Skip to content

Commit

Permalink
fix(android): handle rncli.h -> autolinking.h (#2121)
Browse files Browse the repository at this point in the history
  • Loading branch information
tido64 authored Jul 16, 2024
1 parent 88e8495 commit d7a56c0
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 12 deletions.
22 changes: 22 additions & 0 deletions android/app/src/main/jni/AutolinkingCompat.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef REACTAPP_JNI_AUTOLINKINGCOMPAT_H_
#define REACTAPP_JNI_AUTOLINKINGCOMPAT_H_

#if __has_include(<autolinking.h>) // >= 0.75

#include <autolinking.h>

#define autolinking_ModuleProvider facebook::react::autolinking_ModuleProvider
#define autolinking_cxxModuleProvider facebook::react::autolinking_cxxModuleProvider
#define autolinking_registerProviders facebook::react::autolinking_registerProviders

#else // < 0.75

#include <rncli.h>

#define autolinking_ModuleProvider facebook::react::rncli_ModuleProvider
#define autolinking_cxxModuleProvider facebook::react::rncli_cxxModuleProvider
#define autolinking_registerProviders facebook::react::rncli_registerProviders

#endif // __has_include(<autolinking.h>)

#endif // REACTAPP_JNI_AUTOLINKINGCOMPAT_H_
6 changes: 3 additions & 3 deletions android/app/src/main/jni/ComponentsRegistry.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#include "ComponentsRegistry.h"

#include <rncli.h>
#include "AutolinkingCompat.h"

#if __has_include(<react/fabric/CoreComponentsRegistry.h>) // >= 0.71
#include <react/fabric/CoreComponentsRegistry.h>
#else // < 0.71
#include <CoreComponentsRegistry.h>
#endif
#endif // __has_include(<react/fabric/CoreComponentsRegistry.h>)

#include <DefaultComponentsRegistry.h>

Expand All @@ -31,7 +31,7 @@ void ComponentsRegistry::registerNatives()
facebook::react::DefaultComponentsRegistry::registerComponentDescriptorsFromEntryPoint =
[](std::shared_ptr<ComponentDescriptorProviderRegistry const> registry) {
// Register providers generated by `@react-native-community/cli`
rncli_registerProviders(registry);
autolinking_registerProviders(registry);
};
}

Expand Down
10 changes: 5 additions & 5 deletions android/app/src/main/jni/OnLoad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

#include <DefaultComponentsRegistry.h>
#include <DefaultTurboModuleManagerDelegate.h>
#include <rncli.h>

#include <fbjni/fbjni.h>

#include <ReactCommon/CallInvoker.h>

#include "AutolinkingCompat.h"

using facebook::react::CallInvoker;
using facebook::react::DefaultComponentsRegistry;
using facebook::react::DefaultTurboModuleManagerDelegate;
Expand All @@ -19,7 +20,7 @@ namespace
const std::shared_ptr<CallInvoker> &jsInvoker)
{
#if __has_include(<ReactCommon/CxxReactPackage.h>)
return facebook::react::rncli_cxxModuleProvider(name, jsInvoker);
return autolinking_cxxModuleProvider(name, jsInvoker);
#else
return nullptr;
#endif // __has_include(<ReactCommon/CxxReactPackage.h>)
Expand All @@ -30,10 +31,9 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *)
{
return facebook::jni::initialize(vm, [] {
DefaultTurboModuleManagerDelegate::cxxModuleProvider = &cxxModuleProvider;
DefaultTurboModuleManagerDelegate::javaModuleProvider =
&facebook::react::rncli_ModuleProvider;
DefaultTurboModuleManagerDelegate::javaModuleProvider = &autolinking_ModuleProvider;
DefaultComponentsRegistry::registerComponentDescriptorsFromEntryPoint =
&facebook::react::rncli_registerProviders;
&autolinking_registerProviders;
});
}

Expand Down
9 changes: 5 additions & 4 deletions android/app/src/main/jni/TurboModuleManagerDelegate.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#include "TurboModuleManagerDelegate.h"

#include <rncli.h>
#include <rncore.h>

#include "AutolinkingCompat.h"

using facebook::react::CallInvoker;
using facebook::react::JavaTurboModule;
using facebook::react::TurboModule;
Expand All @@ -26,9 +27,9 @@ std::shared_ptr<TurboModule> TurboModuleManagerDelegate::getTurboModule(
StringRef name, const JavaTurboModule::InitParams &params)
{
// Try autolinked module providers first
auto rncli_module = rncli_ModuleProvider(name, params);
if (rncli_module != nullptr) {
return rncli_module;
auto module = autolinking_ModuleProvider(name, params);
if (module != nullptr) {
return module;
}

return rncore_ModuleProvider(name, params);
Expand Down
1 change: 1 addition & 0 deletions test/pack.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ describe("npm pack", () => {
"android/app/src/main/java/com/microsoft/reacttestapp/react/TestAppReactNativeHost.kt",
"android/app/src/main/jni/AppRegistry.cpp",
"android/app/src/main/jni/AppRegistry.h",
"android/app/src/main/jni/AutolinkingCompat.h",
"android/app/src/main/jni/CMakeLists.txt",
"android/app/src/main/jni/ComponentsRegistry.cpp",
"android/app/src/main/jni/ComponentsRegistry.h",
Expand Down

0 comments on commit d7a56c0

Please sign in to comment.