diff --git a/ReactCommon/react/renderer/scheduler/Scheduler.cpp b/ReactCommon/react/renderer/scheduler/Scheduler.cpp index dd01cbe995c..5d642d834a0 100644 --- a/ReactCommon/react/renderer/scheduler/Scheduler.cpp +++ b/ReactCommon/react/renderer/scheduler/Scheduler.cpp @@ -86,12 +86,11 @@ Scheduler::Scheduler( uiManager->setDelegate(this); uiManager->setComponentDescriptorRegistry(componentDescriptorRegistry_); - runtimeExecutor_([uiManager, - runtimeExecutor = runtimeExecutor_](jsi::Runtime &runtime) { - auto uiManagerBinding = - UIManagerBinding::createAndInstallIfNeeded(runtime, runtimeExecutor); - uiManagerBinding->attach(uiManager); - }); + runtimeExecutor_( + [uiManager, runtimeExecutor = runtimeExecutor_](jsi::Runtime &runtime) { + UIManagerBinding::createAndInstallIfNeeded( + runtime, runtimeExecutor, uiManager); + }); auto componentDescriptorRegistryKey = "ComponentDescriptorRegistry_DO_NOT_USE_PRETTY_PLEASE"; diff --git a/ReactCommon/react/renderer/uimanager/UIManagerBinding.cpp b/ReactCommon/react/renderer/uimanager/UIManagerBinding.cpp index b604a3fe3ab..75e4c49a111 100644 --- a/ReactCommon/react/renderer/uimanager/UIManagerBinding.cpp +++ b/ReactCommon/react/renderer/uimanager/UIManagerBinding.cpp @@ -58,9 +58,10 @@ static bool checkGetCallableModuleIsActive(jsi::Runtime &runtime) { return true; } -std::shared_ptr UIManagerBinding::createAndInstallIfNeeded( +void UIManagerBinding::createAndInstallIfNeeded( jsi::Runtime &runtime, - RuntimeExecutor const &runtimeExecutor) { + RuntimeExecutor const &runtimeExecutor, + std::shared_ptr const &uiManager) { auto uiManagerModuleName = "nativeFabricUIManager"; auto uiManagerValue = @@ -68,17 +69,12 @@ std::shared_ptr UIManagerBinding::createAndInstallIfNeeded( if (uiManagerValue.isUndefined()) { // The global namespace does not have an instance of the binding; // we need to create, install and return it. - auto uiManagerBinding = std::make_shared(runtimeExecutor); + auto uiManagerBinding = + std::make_shared(uiManager, runtimeExecutor); auto object = jsi::Object::createFromHostObject(runtime, uiManagerBinding); runtime.global().setProperty( runtime, uiManagerModuleName, std::move(object)); - return uiManagerBinding; } - - // The global namespace already has an instance of the binding; - // we need to return that. - auto uiManagerObject = uiManagerValue.asObject(runtime); - return uiManagerObject.getHostObject(runtime); } std::shared_ptr UIManagerBinding::getBinding( @@ -95,18 +91,16 @@ std::shared_ptr UIManagerBinding::getBinding( return uiManagerObject.getHostObject(runtime); } -UIManagerBinding::UIManagerBinding(RuntimeExecutor const &runtimeExecutor) - : runtimeExecutor_(runtimeExecutor) {} +UIManagerBinding::UIManagerBinding( + std::shared_ptr const &uiManager, + RuntimeExecutor const &runtimeExecutor) + : uiManager_(uiManager), runtimeExecutor_(runtimeExecutor) {} UIManagerBinding::~UIManagerBinding() { LOG(WARNING) << "UIManagerBinding::~UIManagerBinding() was called (address: " << this << ")."; } -void UIManagerBinding::attach(std::shared_ptr const &uiManager) { - uiManager_ = uiManager; -} - static jsi::Value callMethodOfModule( jsi::Runtime &runtime, std::string const &moduleName, diff --git a/ReactCommon/react/renderer/uimanager/UIManagerBinding.h b/ReactCommon/react/renderer/uimanager/UIManagerBinding.h index 947e3ecf43e..e14b7e24cf3 100644 --- a/ReactCommon/react/renderer/uimanager/UIManagerBinding.h +++ b/ReactCommon/react/renderer/uimanager/UIManagerBinding.h @@ -24,13 +24,12 @@ class UIManagerBinding : public jsi::HostObject { /* * Installs UIManagerBinding into JavaScript runtime if needed. * Creates and sets `UIManagerBinding` into the global namespace. - * In case if the global namespace already has a `UIManagerBinding` installed, - * returns that. * Thread synchronization must be enforced externally. */ - static std::shared_ptr createAndInstallIfNeeded( + static void createAndInstallIfNeeded( jsi::Runtime &runtime, - RuntimeExecutor const &runtimeExecutor); + RuntimeExecutor const &runtimeExecutor, + std::shared_ptr const &uiManager); /* * Returns a pointer to UIManagerBinding previously installed into a runtime. @@ -38,17 +37,12 @@ class UIManagerBinding : public jsi::HostObject { */ static std::shared_ptr getBinding(jsi::Runtime &runtime); - UIManagerBinding(RuntimeExecutor const &runtimeExecutor); + UIManagerBinding( + std::shared_ptr const &uiManager, + RuntimeExecutor const &runtimeExecutor); ~UIManagerBinding(); - /* - * Establish a relationship between `UIManager` and `UIManagerBinding` by - * setting internal pointers to each other. - * Must be called on JavaScript thread or during VM destruction. - */ - void attach(std::shared_ptr const &uiManager); - /* * Starts React Native Surface with given id, moduleName, and props. * Thread synchronization must be enforced externally.