| 19 | ViewNodesVisibilityObserver::~ViewNodesVisibilityObserver() = default; |
| 20 | |
| 21 | void ViewNodesVisibilityObserver::flush(const Ref<Context>& context) { |
| 22 | if (_isFlushing || (_visibilityUpdates.empty() && _viewportUpdates.empty()) || _callback == nullptr) { |
| 23 | return; |
| 24 | } |
| 25 | |
| 26 | auto eventTime = _lastUpdateTime; |
| 27 | _lastUpdateTime = TimePoint(); |
| 28 | |
| 29 | size_t visibleIdsSize = 0; |
| 30 | size_t invisibleIdsSize = 0; |
| 31 | |
| 32 | for (const auto& it : _visibilityUpdates) { |
| 33 | if (it.second) { |
| 34 | visibleIdsSize++; |
| 35 | } else { |
| 36 | invisibleIdsSize++; |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | auto visibleIds = ValueArray::make(visibleIdsSize); |
| 41 | auto invisibleIds = ValueArray::make(invisibleIdsSize); |
| 42 | size_t visibleIdsIndex = 0; |
| 43 | size_t invisibleIdsIndex = 0; |
| 44 | |
| 45 | for (const auto& it : _visibilityUpdates) { |
| 46 | if (it.second) { |
| 47 | (*visibleIds)[visibleIdsIndex++] = Value(it.first); |
| 48 | } else { |
| 49 | (*invisibleIds)[invisibleIdsIndex++] = Value(it.first); |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | auto viewportUpdates = ValueArray::make(_viewportUpdates.size() * 5); |
| 54 | |
| 55 | size_t index = 0; |
| 56 | for (const auto& it : _viewportUpdates) { |
| 57 | auto frame = it.second; |
| 58 | viewportUpdates->emplace(index++, Value(it.first)); |
| 59 | viewportUpdates->emplace(index++, Value(frame.x)); |
| 60 | viewportUpdates->emplace(index++, Value(frame.y)); |
| 61 | viewportUpdates->emplace(index++, Value(frame.width)); |
| 62 | viewportUpdates->emplace(index++, Value(frame.height)); |
| 63 | } |
| 64 | |
| 65 | _visibilityUpdates.clear(); |
| 66 | _viewportUpdates.clear(); |
| 67 | _isFlushing = true; |
| 68 | |
| 69 | auto updateId = context->enqueueUpdate(); |
| 70 | |
| 71 | auto self = strongRef(this); |
| 72 | auto callback = makeShared<ValueFunctionWithCallable>( |
| 73 | [self, context, updateId](const ValueFunctionCallContext& /*callContext*/) -> Value { |
| 74 | DispatchFunction dispatchFn = [self, context, updateId]() { |
| 75 | self->onFlushAcknowledged(context); |
| 76 | context->markUpdateCompleted(updateId); |
| 77 | }; |
| 78 | if (self->_mainThreadManager != nullptr) { |
nothing calls this directly
no test coverage detected