diff --git a/ReactCommon/fabric/uimanager/FabricUIManager.cpp b/ReactCommon/fabric/uimanager/FabricUIManager.cpp index 86ec31ed2d1..1b1dd67d42e 100644 --- a/ReactCommon/fabric/uimanager/FabricUIManager.cpp +++ b/ReactCommon/fabric/uimanager/FabricUIManager.cpp @@ -89,6 +89,17 @@ static const std::string componentNameByReactViewName(std::string viewName) { return viewName; } +FabricUIManager::FabricUIManager(std::function installer, std::function uninstaller): + installer_(std::move(installer)), + uninstaller_(std::move(uninstaller)) { + + installer_(*this); +} + +FabricUIManager::~FabricUIManager() { + uninstaller_(); +} + void FabricUIManager::setComponentDescriptorRegistry(const SharedComponentDescriptorRegistry &componentDescriptorRegistry) { componentDescriptorRegistry_ = componentDescriptorRegistry; } diff --git a/ReactCommon/fabric/uimanager/FabricUIManager.h b/ReactCommon/fabric/uimanager/FabricUIManager.h index 428d6de5bd7..5c561511c5a 100644 --- a/ReactCommon/fabric/uimanager/FabricUIManager.h +++ b/ReactCommon/fabric/uimanager/FabricUIManager.h @@ -21,12 +21,22 @@ namespace react { class FabricUIManager; using UIManager = FabricUIManager; +/* + * Particular implementations of those functions should capture references to + * the runtime and ensure proper threading. + */ +using UIManagerInstaller = void (UIManager &uiManager); +using UIManagerUninstaller = void (); + using DispatchEventToEmptyTargetFunction = void (const EventHandler &eventHandler, const std::string &type, const folly::dynamic &payload); using DispatchEventToTargetFunction = void (const EventHandler &eventHandler, const EventTarget &eventTarget, const std::string &type, const folly::dynamic &payload); class FabricUIManager { public: + FabricUIManager(std::function installer, std::function uninstaller); + ~FabricUIManager(); + #pragma mark - Native-facing Interface void setComponentDescriptorRegistry(const SharedComponentDescriptorRegistry &componentDescriptorRegistry); @@ -77,6 +87,9 @@ private: mutable UniqueEventHandler eventHandler_; std::function dispatchEventToEmptyTargetFunction_; std::function dispatchEventToTargetFunction_; + + std::function installer_; + std::function uninstaller_; }; } // namespace react diff --git a/ReactCommon/fabric/uimanager/Scheduler.cpp b/ReactCommon/fabric/uimanager/Scheduler.cpp index 056222fdfed..020605cee99 100644 --- a/ReactCommon/fabric/uimanager/Scheduler.cpp +++ b/ReactCommon/fabric/uimanager/Scheduler.cpp @@ -18,7 +18,10 @@ namespace react { Scheduler::Scheduler(const SharedContextContainer &contextContainer): contextContainer_(contextContainer) { - uiManager_ = std::make_shared(); + uiManager_ = std::make_shared( + contextContainer->getInstance>("uimanager-installer"), + contextContainer->getInstance>("uimanager-uninstaller") + ); auto eventDispatcher = std::make_shared(