From 4ecf57ead2a32294cb9ed19088e7cce59702794e Mon Sep 17 00:00:00 2001 From: Nicola Corti Date: Tue, 20 Feb 2024 08:30:38 -0800 Subject: [PATCH] Hook the default-app-setup OnLoad.cpp file with the cxxModuleProvider from RNCLI (#43049) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/43049 This connects the OnLoad.cpp file used by OSS apps with the `rncli_cxxModuleProvider`. This method is created by the CLI and takes care of querying all the TM CXX Modules discovered and returning them. This PR is currently waiting on https://github.com/react-native-community/cli/pull/2296 Changelog: [Internal] [Changed] - Hook the default-app-setup OnLoad.cpp file with the cxxModuleProvider from RNCLI Reviewed By: cipolleschi Differential Revision: D53812109 fbshipit-source-id: 47bc0ea699516993070cfa0127de97853acf8890 --- .../cmake-utils/default-app-setup/OnLoad.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/react-native/ReactAndroid/cmake-utils/default-app-setup/OnLoad.cpp b/packages/react-native/ReactAndroid/cmake-utils/default-app-setup/OnLoad.cpp index d206b123ad44bb..56a38374370ab6 100644 --- a/packages/react-native/ReactAndroid/cmake-utils/default-app-setup/OnLoad.cpp +++ b/packages/react-native/ReactAndroid/cmake-utils/default-app-setup/OnLoad.cpp @@ -62,8 +62,16 @@ void registerComponents( std::shared_ptr cxxModuleProvider( const std::string& name, const std::shared_ptr& jsInvoker) { - // Not implemented yet: provide pure-C++ NativeModules here. - return nullptr; + // Here you can provide your CXX Turbo Modules coming from + // either your application or from external libraries. The approach to follow + // is similar to the following (for a module called `NativeCxxModuleExample`): + // + // if (name == NativeCxxModuleExample::kModuleName) { + // return std::make_shared(jsInvoker); + // } + + // And we fallback to the CXX module providers autolinked by RN CLI + return rncli_cxxModuleProvider(name, jsInvoker); } std::shared_ptr javaModuleProvider(