Implement method dispatch using TurboModuleSchema

Summary:
This is the final diff in the JS TurboModule codegen stack for Android. It implements method dispatch using the TurboModuleSchema object.

Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D22837486

fbshipit-source-id: f91b03f064941457d4b8c5e37e011468559dee71
This commit is contained in:
Ramanpreet Nara
2020-11-08 14:02:02 -08:00
committed by Facebook GitHub Bot
parent 165dcccc58
commit 610dcf488b
5 changed files with 104 additions and 6 deletions
@@ -14,6 +14,7 @@
#include <ReactCommon/TurboCxxModule.h>
#include <ReactCommon/TurboModuleBinding.h>
#include <ReactCommon/TurboModulePerfLogger.h>
#include <ReactCommon/TurboModuleSchema.h>
#include <react/jni/JMessageQueueThread.h>
#include "TurboModuleManager.h"
@@ -76,7 +77,8 @@ void TurboModuleManager::installJSIBindings() {
jsCallInvoker_ = std::weak_ptr<CallInvoker>(jsCallInvoker_),
nativeCallInvoker_ = std::weak_ptr<CallInvoker>(nativeCallInvoker_),
delegate_ = jni::make_weak(delegate_),
javaPart_ = jni::make_weak(javaPart_)](
javaPart_ = jni::make_weak(javaPart_),
runtime_ = runtime_](
const std::string &name,
const jsi::Value *schema) -> std::shared_ptr<TurboModule> {
auto turboModuleCache = turboModuleCache_.lock();
@@ -139,6 +141,13 @@ void TurboModuleManager::installJSIBindings() {
.jsInvoker = jsCallInvoker,
.nativeInvoker = nativeCallInvoker};
if (schema->isObject() && !schema->isNull()) {
auto turboModule = std::make_shared<JavaTurboModule>(
params, TurboModuleSchema::parse(*runtime_, name, *schema));
TurboModulePerfLogger::moduleJSRequireEndingEnd(moduleName);
return turboModule;
}
auto turboModule = delegate->cthis()->getTurboModule(name, params);
turboModuleCache->insert({name, turboModule});
TurboModulePerfLogger::moduleJSRequireEndingEnd(moduleName);