From 4a8613f40f47e9afd5464da04d258a6130a82185 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Wed, 26 Sep 2018 10:01:37 -0700 Subject: [PATCH] Fabric: UIManager's API for installing and uninstalling itself Summary: UIManager now can install and uninstall itself calling a functions that are provided as constructor arguments. Reviewed By: mdvacca Differential Revision: D9931329 fbshipit-source-id: b8d2d9925b0e2db0fed44bdf2e185d198fabd5ee --- ReactCommon/fabric/uimanager/FabricUIManager.cpp | 11 +++++++++++ ReactCommon/fabric/uimanager/FabricUIManager.h | 13 +++++++++++++ ReactCommon/fabric/uimanager/Scheduler.cpp | 5 ++++- 3 files changed, 28 insertions(+), 1 deletion(-) 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(