mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
Simplify construction of UIManagerBinding
Summary: changelog: [internal] Provide `UIManager` to `UIManagerBinding` in constructor to make the API safer. Reviewed By: philIip Differential Revision: D32668892 fbshipit-source-id: a15cd295196a60c3f46997e59c05c4f90503e18d
This commit is contained in:
1 parent
34efaab3a8
commit
b30ff9853c
3 files changed
+20
-33
No files matched your search
@@ -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";
|
||||
|
||||
@@ -58,9 +58,10 @@ static bool checkGetCallableModuleIsActive(jsi::Runtime &runtime) {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::shared_ptr<UIManagerBinding> UIManagerBinding::createAndInstallIfNeeded(
|
||||
void UIManagerBinding::createAndInstallIfNeeded(
|
||||
jsi::Runtime &runtime,
|
||||
RuntimeExecutor const &runtimeExecutor) {
|
||||
RuntimeExecutor const &runtimeExecutor,
|
||||
std::shared_ptr<UIManager> const &uiManager) {
|
||||
auto uiManagerModuleName = "nativeFabricUIManager";
|
||||
|
||||
auto uiManagerValue =
|
||||
@@ -68,17 +69,12 @@ std::shared_ptr<UIManagerBinding> 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<UIManagerBinding>(runtimeExecutor);
|
||||
auto uiManagerBinding =
|
||||
std::make_shared<UIManagerBinding>(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<UIManagerBinding>(runtime);
|
||||
}
|
||||
|
||||
std::shared_ptr<UIManagerBinding> UIManagerBinding::getBinding(
|
||||
@@ -95,18 +91,16 @@ std::shared_ptr<UIManagerBinding> UIManagerBinding::getBinding(
|
||||
return uiManagerObject.getHostObject<UIManagerBinding>(runtime);
|
||||
}
|
||||
|
||||
UIManagerBinding::UIManagerBinding(RuntimeExecutor const &runtimeExecutor)
|
||||
: runtimeExecutor_(runtimeExecutor) {}
|
||||
UIManagerBinding::UIManagerBinding(
|
||||
std::shared_ptr<UIManager> 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<UIManager> const &uiManager) {
|
||||
uiManager_ = uiManager;
|
||||
}
|
||||
|
||||
static jsi::Value callMethodOfModule(
|
||||
jsi::Runtime &runtime,
|
||||
std::string const &moduleName,
|
||||
|
||||
@@ -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<UIManagerBinding> createAndInstallIfNeeded(
|
||||
static void createAndInstallIfNeeded(
|
||||
jsi::Runtime &runtime,
|
||||
RuntimeExecutor const &runtimeExecutor);
|
||||
RuntimeExecutor const &runtimeExecutor,
|
||||
std::shared_ptr<UIManager> 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<UIManagerBinding> getBinding(jsi::Runtime &runtime);
|
||||
|
||||
UIManagerBinding(RuntimeExecutor const &runtimeExecutor);
|
||||
UIManagerBinding(
|
||||
std::shared_ptr<UIManager> 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<UIManager> const &uiManager);
|
||||
|
||||
/*
|
||||
* Starts React Native Surface with given id, moduleName, and props.
|
||||
* Thread synchronization must be enforced externally.
|
||||
|
||||
Reference in new issue
Block a user