From 111aab590e83957be34c762cd5df9f742b386dd4 Mon Sep 17 00:00:00 2001 From: Ramanpreet Nara Date: Fri, 31 Jul 2020 15:27:46 -0700 Subject: [PATCH] Forward the NativeModule schema jsi::Value to TMM Summary: If `__turboModuleProxy` is called with a second argument, we'll now forward that `jsi::Value` to TurboModuleManager on iOS and Android, so that the TurboModuleManager can eventually use this `jsi::Value` to read data required to perform method invocation on the TurboModule object. **Note:** This diff is basically a no-op right now. Changelog: [Internal] Reviewed By: PeteTheHeat Differential Revision: D22828838 fbshipit-source-id: 19db2adcae6a58b4885fcd11bef23f9d5882bfce --- .../core/jni/ReactCommon/TurboModuleManager.cpp | 3 ++- ReactCommon/turbomodule/core/TurboModule.h | 4 ++-- ReactCommon/turbomodule/core/TurboModuleBinding.cpp | 11 ++++++++--- ReactCommon/turbomodule/core/TurboModuleBinding.h | 4 +++- .../core/platform/ios/RCTTurboModuleManager.mm | 3 ++- 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/jni/ReactCommon/TurboModuleManager.cpp b/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/jni/ReactCommon/TurboModuleManager.cpp index d074ba5b121..131b41b075e 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/jni/ReactCommon/TurboModuleManager.cpp +++ b/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/jni/ReactCommon/TurboModuleManager.cpp @@ -73,7 +73,8 @@ void TurboModuleManager::installJSIBindings() { nativeCallInvoker_ = std::weak_ptr(nativeCallInvoker_), delegate_ = jni::make_weak(delegate_), javaPart_ = jni::make_weak(javaPart_)]( - const std::string &name) -> std::shared_ptr { + const std::string &name, + const jsi::Value *schema) -> std::shared_ptr { auto turboModuleCache = turboModuleCache_.lock(); auto jsCallInvoker = jsCallInvoker_.lock(); auto nativeCallInvoker = nativeCallInvoker_.lock(); diff --git a/ReactCommon/turbomodule/core/TurboModule.h b/ReactCommon/turbomodule/core/TurboModule.h index 0772986a76a..8bc8362730c 100644 --- a/ReactCommon/turbomodule/core/TurboModule.h +++ b/ReactCommon/turbomodule/core/TurboModule.h @@ -64,8 +64,8 @@ class JSI_EXPORT TurboModule : public facebook::jsi::HostObject { * An app/platform-specific provider function to get an instance of a module * given a name. */ -using TurboModuleProviderFunctionType = - std::function(const std::string &name)>; +using TurboModuleProviderFunctionType = std::function(const std::string &name, const jsi::Value *schema)>; } // namespace react } // namespace facebook diff --git a/ReactCommon/turbomodule/core/TurboModuleBinding.cpp b/ReactCommon/turbomodule/core/TurboModuleBinding.cpp index dae9274ebcf..0b04ac69b10 100644 --- a/ReactCommon/turbomodule/core/TurboModuleBinding.cpp +++ b/ReactCommon/turbomodule/core/TurboModuleBinding.cpp @@ -50,11 +50,12 @@ TurboModuleBinding::~TurboModuleBinding() { } std::shared_ptr TurboModuleBinding::getModule( - const std::string &name) { + const std::string &name, + const jsi::Value *schema) { std::shared_ptr module = nullptr; { SystraceSection s("TurboModuleBinding::getModule", "module", name); - module = moduleProvider_(name); + module = moduleProvider_(name, schema); } return module; } @@ -69,7 +70,11 @@ jsi::Value TurboModuleBinding::jsProxy( "__turboModuleProxy must be called with at least 1 argument"); } std::string moduleName = args[0].getString(runtime).utf8(runtime); - std::shared_ptr module = getModule(moduleName); + jsi::Value nullSchema = jsi::Value::undefined(); + + std::shared_ptr module = + (count >= 2 ? getModule(moduleName, &args[1]) + : getModule(moduleName, &nullSchema)); if (module == nullptr) { return jsi::Value::null(); diff --git a/ReactCommon/turbomodule/core/TurboModuleBinding.h b/ReactCommon/turbomodule/core/TurboModuleBinding.h index 96de89bed47..2546730959f 100644 --- a/ReactCommon/turbomodule/core/TurboModuleBinding.h +++ b/ReactCommon/turbomodule/core/TurboModuleBinding.h @@ -36,7 +36,9 @@ class TurboModuleBinding { /** * Get an TurboModule instance for the given module name. */ - std::shared_ptr getModule(const std::string &name); + std::shared_ptr getModule( + const std::string &name, + const jsi::Value *schema); private: /** diff --git a/ReactCommon/turbomodule/core/platform/ios/RCTTurboModuleManager.mm b/ReactCommon/turbomodule/core/platform/ios/RCTTurboModuleManager.mm index f93dfa4f1ae..0d89875a25b 100644 --- a/ReactCommon/turbomodule/core/platform/ios/RCTTurboModuleManager.mm +++ b/ReactCommon/turbomodule/core/platform/ios/RCTTurboModuleManager.mm @@ -656,7 +656,8 @@ static Class getFallbackClassFromName(const char *name) } __weak __typeof(self) weakSelf = self; - auto turboModuleProvider = [weakSelf](const std::string &name) -> std::shared_ptr { + auto turboModuleProvider = + [weakSelf](const std::string &name, const jsi::Value *schema) -> std::shared_ptr { if (!weakSelf) { return nullptr; }