/* * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ #pragma once #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace facebook::react { /* * Scheduler coordinates Shadow Tree updates and event flows. */ class Scheduler final : public UIManagerDelegate { public: Scheduler( const SchedulerToolbox &schedulerToolbox, UIManagerAnimationDelegate *animationDelegate, SchedulerDelegate *delegate); ~Scheduler() override; #pragma mark - Surface Management /* * Registers and unregisters a `SurfaceHandler` object in the `Scheduler`. * All registered `SurfaceHandler` objects must be unregistered * (with the same `Scheduler`) before their deallocation. */ void registerSurface(const SurfaceHandler &surfaceHandler) const noexcept; void unregisterSurface(const SurfaceHandler &surfaceHandler) const noexcept; /* * This is broken. Please do not use. * `ComponentDescriptor`s are not designed to be used outside of `UIManager`, * there is no any guarantees about their lifetime. */ const ComponentDescriptor *findComponentDescriptorByHandle_DO_NOT_USE_THIS_IS_BROKEN(ComponentHandle handle) const; #pragma mark - Delegate /* * Sets and gets the Scheduler's delegate. * If you requesting a ComponentDescriptor and unsure that it's there, you are * doing something wrong. */ void setDelegate(SchedulerDelegate *delegate); SchedulerDelegate *getDelegate() const; #pragma mark - UIManagerAnimationDelegate // This is not needed on iOS or any platform that has a "pull" instead of // "push" MountingCoordinator model. This just tells the delegate an update // is available and that it should `pullTransaction`; we may want to rename // this to be more generic and not animation-specific. void animationTick() const; #pragma mark - UIManagerDelegate void uiManagerDidFinishTransaction( std::shared_ptr mountingCoordinator, bool mountSynchronously) override; void uiManagerDidCreateShadowNode(const ShadowNode &shadowNode) override; void uiManagerDidDispatchCommand( const std::shared_ptr &shadowNode, const std::string &commandName, const folly::dynamic &args) override; void uiManagerDidSendAccessibilityEvent( const std::shared_ptr &shadowNode, const std::string &eventType) override; void uiManagerDidSetIsJSResponder( const std::shared_ptr &shadowNode, bool isJSResponder, bool blockNativeResponder) override; void uiManagerShouldSynchronouslyUpdateViewOnUIThread(Tag tag, const folly::dynamic &props) override; void uiManagerDidUpdateShadowTree(const std::unordered_map &tagToProps) override; void uiManagerShouldAddEventListener(std::shared_ptr listener) final; void uiManagerShouldRemoveEventListener(const std::shared_ptr &listener) final; void uiManagerDidStartSurface(const ShadowTree &shadowTree) override; #pragma mark - ContextContainer std::shared_ptr getContextContainer() const; #pragma mark - UIManager std::shared_ptr getUIManager() const; void reportMount(SurfaceId surfaceId) const; #pragma mark - Event listeners void addEventListener(std::shared_ptr listener); void removeEventListener(const std::shared_ptr &listener); #pragma mark - Surface start callback void uiManagerShouldSetOnSurfaceStartCallback(OnSurfaceStartCallback &&callback) override; private: friend class SurfaceHandler; SchedulerDelegate *delegate_; SharedComponentDescriptorRegistry componentDescriptorRegistry_; RuntimeExecutor runtimeExecutor_; std::shared_ptr uiManager_; std::vector> commitHooks_; /* * At some point, we have to have an owning shared pointer to something that * will become an `EventDispatcher` a moment later. That's why we have it as a * pointer to an optional: we construct the pointer first, share that with * parts that need to have ownership (and only ownership) of that, and then * fill the optional. */ std::shared_ptr> eventDispatcher_; std::shared_ptr performanceEntryReporter_; std::optional cdpMetricsReporter_; std::optional cdpPerfIssuesReporter_; std::shared_ptr eventPerformanceLogger_; /** * Hold onto ContextContainer. See SchedulerToolbox. * Must not be nullptr. */ std::shared_ptr contextContainer_; RuntimeScheduler *runtimeScheduler_{nullptr}; mutable std::shared_mutex onSurfaceStartCallbackMutex_; OnSurfaceStartCallback onSurfaceStartCallback_; }; } // namespace facebook::react