Give TurboModules access to the native CallInvoker

Summary:
Self explanatory.
1. **Existing:** We create the NativeModules thread in CatalystInstanceImpl.cpp.
2. D17422165: We wrap this thread in a `BridgeNativeCallInvoker`.
3. D17422164: We use `CatalystInstanceImpl::getNativeCallInvokerHolder()` to get a hold of the `BridgeNitiveCallInvoker` in Java.
4. D17422163: From Java, we pass this `CallInvokerHolder` to `TurboModuleManager`'s constructor.
5. **This diff:** `TurboModuleManager` then unwraps the `CallInvoker` from `CallInvokerHolder`, and passes it to all TurboModules in their constructor.

Reviewed By: PeteTheHeat

Differential Revision: D17422160

fbshipit-source-id: c0a76dfe5fdedac2e0e21f7a562bc7588dc190fb
This commit is contained in:
Ramanpreet Nara
2019-09-20 10:52:57 -07:00
committed by Facebook Github Bot
parent 10d89b1eff
commit 43807f04fe
4 changed files with 10 additions and 5 deletions
@@ -84,7 +84,7 @@ void TurboModuleManager::installJSIBindings() {
auto moduleInstance = getJavaModule(javaPart_.get(), name);
if (moduleInstance) {
auto turboModule = delegate_->cthis()->getTurboModule(name, moduleInstance, jsCallInvoker_);
auto turboModule = delegate_->cthis()->getTurboModule(name, moduleInstance, jsCallInvoker_, nativeCallInvoker_);
turboModuleCache_.insert({name, turboModule});
return turboModule;
}
@@ -20,7 +20,7 @@ class TurboModuleManagerDelegate : public jni::HybridClass<TurboModuleManagerDel
public:
static auto constexpr kJavaDescriptor = "Lcom/facebook/react/turbomodule/core/TurboModuleManagerDelegate;";
virtual std::shared_ptr<TurboModule> getTurboModule(std::string name, jni::alias_ref<JTurboModule> turboModule, std::shared_ptr<CallInvoker> jsInvoker) = 0;
virtual std::shared_ptr<TurboModule> getTurboModule(std::string name, jni::alias_ref<JTurboModule> turboModule, std::shared_ptr<CallInvoker> jsInvoker, std::shared_ptr<CallInvoker> nativeInvoker) = 0;
virtual std::shared_ptr<TurboModule> getTurboModule(std::string name, std::shared_ptr<CallInvoker> jsInvoker) = 0;
private:
@@ -26,8 +26,11 @@ namespace react {
JavaTurboModule::JavaTurboModule(
const std::string &name,
jni::alias_ref<JTurboModule> instance,
std::shared_ptr<CallInvoker> jsInvoker)
: TurboModule(name, jsInvoker), instance_(jni::make_global(instance)) {}
std::shared_ptr<CallInvoker> jsInvoker,
std::shared_ptr<CallInvoker> nativeInvoker)
: TurboModule(name, jsInvoker),
instance_(jni::make_global(instance)),
nativeInvoker_(nativeInvoker) {}
jni::local_ref<JCxxCallbackImpl::JavaPart>
JavaTurboModule::createJavaCallbackFromJSIFunction(
@@ -29,7 +29,8 @@ class JSI_EXPORT JavaTurboModule : public TurboModule {
JavaTurboModule(
const std::string &name,
jni::alias_ref<JTurboModule> instance,
std::shared_ptr<CallInvoker> jsInvoker);
std::shared_ptr<CallInvoker> jsInvoker,
std::shared_ptr<CallInvoker> nativeInvoker);
jsi::Value invokeJavaMethod(
jsi::Runtime &runtime,
TurboModuleMethodValueKind valueKind,
@@ -48,6 +49,7 @@ class JSI_EXPORT JavaTurboModule : public TurboModule {
private:
jni::global_ref<JTurboModule> instance_;
std::unordered_set<std::shared_ptr<CallbackWrapper>> callbackWrappers_;
std::shared_ptr<CallInvoker> nativeInvoker_;
/**
* This method must be called from the JS Thread, since it accesses