diff --git a/ReactAndroid/cmake-utils/default-app-setup/OnLoad.cpp b/ReactAndroid/cmake-utils/default-app-setup/OnLoad.cpp index 1eaa20836f7641..5e7df8b86bc062 100644 --- a/ReactAndroid/cmake-utils/default-app-setup/OnLoad.cpp +++ b/ReactAndroid/cmake-utils/default-app-setup/OnLoad.cpp @@ -48,7 +48,14 @@ void registerComponents( rncli_registerProviders(registry); } -std::shared_ptr provideModules( +std::shared_ptr cxxModuleProvider( + const std::string &name, + const std::shared_ptr &jsInvoker) { + // Not implemented yet: provide pure-C++ NativeModules here. + return nullptr; +} + +std::shared_ptr javaModuleProvider( const std::string &name, const JavaTurboModule::InitParams ¶ms) { // Here you can provide your own module provider for TurboModules coming from @@ -70,8 +77,10 @@ std::shared_ptr provideModules( JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *) { return facebook::jni::initialize(vm, [] { - facebook::react::DefaultTurboModuleManagerDelegate:: - moduleProvidersFromEntryPoint = &facebook::react::provideModules; + facebook::react::DefaultTurboModuleManagerDelegate::cxxModuleProvider = + &facebook::react::cxxModuleProvider; + facebook::react::DefaultTurboModuleManagerDelegate::javaModuleProvider = + &facebook::react::javaModuleProvider; facebook::react::DefaultComponentsRegistry:: registerComponentDescriptorsFromEntryPoint = &facebook::react::registerComponents; diff --git a/ReactAndroid/src/main/jni/react/newarchdefaults/DefaultTurboModuleManagerDelegate.cpp b/ReactAndroid/src/main/jni/react/newarchdefaults/DefaultTurboModuleManagerDelegate.cpp index 09534d8ce08aca..78af98677af624 100644 --- a/ReactAndroid/src/main/jni/react/newarchdefaults/DefaultTurboModuleManagerDelegate.cpp +++ b/ReactAndroid/src/main/jni/react/newarchdefaults/DefaultTurboModuleManagerDelegate.cpp @@ -12,10 +12,15 @@ namespace facebook { namespace react { +std::function( + const std::string &, + const std::shared_ptr &)> + DefaultTurboModuleManagerDelegate::cxxModuleProvider{nullptr}; + std::function( const std::string &, const JavaTurboModule::InitParams &)> - DefaultTurboModuleManagerDelegate::moduleProvidersFromEntryPoint{nullptr}; + DefaultTurboModuleManagerDelegate::javaModuleProvider{nullptr}; jni::local_ref DefaultTurboModuleManagerDelegate::initHybrid(jni::alias_ref) { @@ -32,17 +37,21 @@ void DefaultTurboModuleManagerDelegate::registerNatives() { std::shared_ptr DefaultTurboModuleManagerDelegate::getTurboModule( const std::string &name, const std::shared_ptr &jsInvoker) { - // Not implemented yet: provide pure-C++ NativeModules here. + auto moduleProvider = DefaultTurboModuleManagerDelegate::cxxModuleProvider; + if (moduleProvider) { + return moduleProvider(name, jsInvoker); + } return nullptr; } std::shared_ptr DefaultTurboModuleManagerDelegate::getTurboModule( const std::string &name, const JavaTurboModule::InitParams ¶ms) { - auto resolvedModule = (DefaultTurboModuleManagerDelegate:: - moduleProvidersFromEntryPoint)(name, params); - if (resolvedModule != nullptr) { - return resolvedModule; + auto moduleProvider = DefaultTurboModuleManagerDelegate::javaModuleProvider; + if (moduleProvider) { + if (auto resolvedModule = moduleProvider(name, params)) { + return resolvedModule; + } } return rncore_ModuleProvider(name, params); } diff --git a/ReactAndroid/src/main/jni/react/newarchdefaults/DefaultTurboModuleManagerDelegate.h b/ReactAndroid/src/main/jni/react/newarchdefaults/DefaultTurboModuleManagerDelegate.h index 1a9c75b1d9c1cc..c6d37782d9b25f 100644 --- a/ReactAndroid/src/main/jni/react/newarchdefaults/DefaultTurboModuleManagerDelegate.h +++ b/ReactAndroid/src/main/jni/react/newarchdefaults/DefaultTurboModuleManagerDelegate.h @@ -27,10 +27,15 @@ class DefaultTurboModuleManagerDelegate : public jni::HybridClass< static void registerNatives(); + static std::function( + const std::string &, + const std::shared_ptr &)> + cxxModuleProvider; + static std::function( const std::string &, const JavaTurboModule::InitParams &)> - moduleProvidersFromEntryPoint; + javaModuleProvider; std::shared_ptr getTurboModule( const std::string &name, diff --git a/packages/rn-tester/android/app/src/main/jni/OnLoad.cpp b/packages/rn-tester/android/app/src/main/jni/OnLoad.cpp index ae21e72a4dccff..81b8450dfee885 100644 --- a/packages/rn-tester/android/app/src/main/jni/OnLoad.cpp +++ b/packages/rn-tester/android/app/src/main/jni/OnLoad.cpp @@ -23,7 +23,13 @@ void registerComponents( RNTMyNativeViewComponentDescriptor>()); } -std::shared_ptr provideModules( +std::shared_ptr cxxModuleProvider( + const std::string &name, + const std::shared_ptr &jsInvoker) { + return nullptr; +} + +std::shared_ptr javaModuleProvider( const std::string &name, const JavaTurboModule::InitParams ¶ms) { auto module = AppSpecs_ModuleProvider(name, params); @@ -42,8 +48,10 @@ std::shared_ptr provideModules( JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *) { return facebook::jni::initialize(vm, [] { - facebook::react::DefaultTurboModuleManagerDelegate:: - moduleProvidersFromEntryPoint = &facebook::react::provideModules; + facebook::react::DefaultTurboModuleManagerDelegate::cxxModuleProvider = + &facebook::react::cxxModuleProvider; + facebook::react::DefaultTurboModuleManagerDelegate::javaModuleProvider = + &facebook::react::javaModuleProvider; facebook::react::DefaultComponentsRegistry:: registerComponentDescriptorsFromEntryPoint = &facebook::react::registerComponents;