Skip to content

Commit

Permalink
Provide easy regristration of C++ TurboModules in rn-tester Android (#…
Browse files Browse the repository at this point in the history
…35225)

Summary:
Pull Request resolved: #35225

Changelog:
[Android] [Changed] - Provide easy regristration of C++ TurboModules in rn-tester Android

Differential Revision: D41069277

fbshipit-source-id: 06793c95b8d91d2acca0666d01cef376ffe0338d
  • Loading branch information
christophpurrer authored and facebook-github-bot committed Nov 6, 2022
1 parent f0b7cbe commit 152b53e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
9 changes: 9 additions & 0 deletions ReactAndroid/cmake-utils/default-app-setup/OnLoad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,22 @@ std::shared_ptr<TurboModule> provideModules(
return rncli_ModuleProvider(name, params);
}

std::shared_ptr<TurboModule> provideCxxModules(
const std::string &name,
const std::shared_ptr<CallInvoker> &jsInvoker) {
// Not implemented yet: provide pure-C++ NativeModules here.
return nullptr;
}

} // namespace react
} // namespace facebook

JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *) {
return facebook::jni::initialize(vm, [] {
facebook::react::DefaultTurboModuleManagerDelegate::
moduleProvidersFromEntryPoint = &facebook::react::provideModules;
facebook::react::DefaultTurboModuleManagerDelegate::cxxModuleProviders =
&facebook::react::provideCxxModules;
facebook::react::DefaultComponentsRegistry::
registerComponentDescriptorsFromEntryPoint =
&facebook::react::registerComponents;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
namespace facebook {
namespace react {

std::function<std::shared_ptr<TurboModule>(
const std::string &,
const std::shared_ptr<CallInvoker> &)>
DefaultTurboModuleManagerDelegate::cxxModuleProvidersFromEntryPoint{
nullptr};

std::function<std::shared_ptr<TurboModule>(
const std::string &,
const JavaTurboModule::InitParams &)>
Expand All @@ -32,7 +38,11 @@ void DefaultTurboModuleManagerDelegate::registerNatives() {
std::shared_ptr<TurboModule> DefaultTurboModuleManagerDelegate::getTurboModule(
const std::string &name,
const std::shared_ptr<CallInvoker> &jsInvoker) {
// Not implemented yet: provide pure-C++ NativeModules here.
auto resolvedModule = (DefaultTurboModuleManagerDelegate::
cxxModuleProvidersFromEntryPoint)(name, jsInvoker);
if (resolvedModule != nullptr) {
return resolvedModule;
}
return nullptr;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ class DefaultTurboModuleManagerDelegate : public jni::HybridClass<

static void registerNatives();

static std::function<std::shared_ptr<TurboModule>(
const std::string &,
const std::shared_ptr<CallInvoker> &)>
cxxModuleProvidersFromEntryPoint;

static std::function<std::shared_ptr<TurboModule>(
const std::string &,
const JavaTurboModule::InitParams &)>
Expand Down
8 changes: 8 additions & 0 deletions packages/rn-tester/android/app/src/main/jni/OnLoad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,19 @@ std::shared_ptr<TurboModule> provideModules(
return rncore_ModuleProvider(name, params);
}

std::shared_ptr<TurboModule> provideCxxModules(
const std::string &name,
const std::shared_ptr<CallInvoker> &jsInvoker) {
return nullptr;
}

} // namespace react
} // namespace facebook

JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *) {
return facebook::jni::initialize(vm, [] {
facebook::react::DefaultTurboModuleManagerDelegate::
cxxModuleProvidersFromEntryPoint = &facebook::react::provideCxxModules;
facebook::react::DefaultTurboModuleManagerDelegate::
moduleProvidersFromEntryPoint = &facebook::react::provideModules;
facebook::react::DefaultComponentsRegistry::
Expand Down

0 comments on commit 152b53e

Please sign in to comment.