Skip to content

Commit 9c662b1

Browse files
authored
feat(chore): registration compat for 0.68/0.69 (#753)
1 parent 45d4530 commit 9c662b1

File tree

4 files changed

+128
-1
lines changed

4 files changed

+128
-1
lines changed

android/Android.mk

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
THIS_DIR := $(call my-dir)
2+
3+
include $(REACT_ANDROID_DIR)/Android-prebuilt.mk
4+
5+
include ${GENERATED_SRC_DIR}/codegen/jni/Android.mk
6+
7+
include $(CLEAR_VARS)
8+
9+
LOCAL_PATH := $(THIS_DIR)
10+
11+
# Define the library name here.
12+
LOCAL_MODULE := ${CODEGEN_MODULE_NAME}_registration
13+
14+
LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp)
15+
16+
LOCAL_SHARED_LIBRARIES := \
17+
libfabricjni \
18+
libfbjni \
19+
libglog \
20+
libjsi \
21+
libreact_codegen_rncore \
22+
libreact_codegen_${CODEGEN_MODULE_NAME} \
23+
libreact_debug \
24+
libreact_nativemodule_core \
25+
libreact_render_componentregistry \
26+
libreact_render_core \
27+
libreact_render_debug \
28+
libreact_render_graphics \
29+
librrc_view \
30+
libruntimeexecutor \
31+
libturbomodulejsijni \
32+
libyoga
33+
34+
ifneq ($(filter $(call modules-get-list),folly_runtime),)
35+
LOCAL_SHARED_LIBRARIES += libfolly_runtime # since [email protected]
36+
else
37+
LOCAL_SHARED_LIBRARIES += libfolly_futures libfolly_json # [email protected]
38+
endif
39+
40+
LOCAL_CFLAGS := \
41+
-DLOG_TAG=\"ReactNative\" \
42+
-DCODEGEN_COMPONENT_DESCRIPTOR_H="<react/renderer/components/${CODEGEN_MODULE_NAME}/ComponentDescriptors.h>"
43+
LOCAL_CFLAGS += -fexceptions -frtti -std=c++17 -Wall
44+
45+
include $(BUILD_SHARED_LIBRARY)

android/build.gradle

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,30 @@ if(shouldUseNameSpace){
5454
manifestContent.replaceAll(" ", " ")
5555
manifestOutFile.write(manifestContent)
5656

57+
import groovy.json.JsonSlurper
58+
59+
// https://github.com/callstack/react-native-builder-bob/discussions/359
60+
def registrationCompat = {
61+
def reactAndroidProject = rootProject.allprojects.find { it.name == 'ReactAndroid' }
62+
if (reactAndroidProject == null) return false
63+
64+
def reactNativeManifest = file("${reactAndroidProject.projectDir}/../package.json")
65+
def reactNativeVersion = new JsonSlurper().parseText(reactNativeManifest.text).version as String
66+
// Fabric was introduced at [email protected], full CMake support were introduced at [email protected]
67+
// Use Android.mk for compatibility with [email protected]/0.69
68+
reactNativeVersion.matches('(0.68.*|0.69.*)')
69+
}()
70+
71+
def codegenViewLibraryName = "RNCViewPager"
72+
def codegenViewModuleName = {
73+
// Autolink for Fabric uses codegenConfig.name in package.json since [email protected]
74+
// Use codegenViewLibraryName for compatibility with [email protected]/0.69
75+
def libraryManifestJson = new JsonSlurper().parseText(file("$projectDir/../package.json").text)
76+
registrationCompat ? codegenViewLibraryName : libraryManifestJson.codegenConfig.name
77+
}()
78+
79+
def appProject = rootProject.allprojects.find { it.plugins.hasPlugin('com.android.application') }
80+
5781
android {
5882
compileSdkVersion getExtOrIntegerDefault('compileSdkVersion')
5983
if (shouldUseNameSpace){
@@ -63,7 +87,38 @@ android {
6387
minSdkVersion getExtOrIntegerDefault('minSdkVersion')
6488
targetSdkVersion getExtOrIntegerDefault('targetSdkVersion')
6589
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
90+
91+
buildConfigField "String", "CODEGEN_MODULE_REGISTRATION", (isNewArchitectureEnabled() && registrationCompat ? "\"${codegenViewModuleName}_registration\"" : "null")
92+
93+
if (isNewArchitectureEnabled() && registrationCompat) {
94+
def reactAndroidProject = project(':ReactAndroid')
95+
externalNativeBuild {
96+
ndkBuild {
97+
arguments "APP_PLATFORM=android-21",
98+
"APP_STL=c++_shared",
99+
"NDK_TOOLCHAIN_VERSION=clang",
100+
"GENERATED_SRC_DIR=$buildDir/generated/source", // for react_codegen_* in this library's codegen/jni
101+
"PROJECT_BUILD_DIR=${appProject.buildDir}", // for REACT_NDK_EXPORT_DIR in ReactAndroid's Android-prebuilt.mk
102+
"REACT_ANDROID_DIR=${reactAndroidProject.projectDir}",
103+
"REACT_ANDROID_BUILD_DIR=${reactAndroidProject.buildDir}",
104+
"CODEGEN_MODULE_NAME=$codegenViewModuleName"
105+
cFlags "-Wall", "-Werror", "-fexceptions", "-frtti", "-DWITH_INSPECTOR=1"
106+
cppFlags "-std=c++17"
107+
targets "${codegenViewModuleName}_registration"
108+
}
109+
}
110+
}
66111
}
112+
113+
if (isNewArchitectureEnabled() && registrationCompat) {
114+
// We configure the NDK build only if you decide to opt-in for the New Architecture.
115+
externalNativeBuild {
116+
ndkBuild {
117+
path "Android.mk"
118+
}
119+
}
120+
}
121+
67122
buildTypes {
68123
release {
69124
minifyEnabled false
@@ -174,7 +229,7 @@ dependencies {
174229
if (isNewArchitectureEnabled()) {
175230
react {
176231
jsRootDir = file("../src")
177-
libraryName = "RNCViewPager"
232+
libraryName = codegenViewLibraryName
178233
codegenJavaPackageName = "com.reactnativepagerview"
179234
}
180235
}

android/registration.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include <CoreComponentsRegistry.h>
2+
#include CODEGEN_COMPONENT_DESCRIPTOR_H
3+
4+
namespace facebook {
5+
namespace react {
6+
7+
void registerProviders() {
8+
auto providerRegistry = CoreComponentsRegistry::sharedProviderRegistry();
9+
providerRegistry->add(concreteComponentDescriptorProvider<RNCViewPagerComponentDescriptor>());
10+
}
11+
12+
}
13+
}
14+
15+
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *) {
16+
facebook::react::registerProviders();
17+
return JNI_VERSION_1_6;
18+
}

android/src/fabric/java/com/reactnativepagerview/PagerViewViewManager.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,22 @@ import com.facebook.react.uimanager.*
1313
import com.facebook.react.uimanager.annotations.ReactProp
1414
import com.facebook.react.viewmanagers.RNCViewPagerManagerDelegate
1515
import com.facebook.react.viewmanagers.RNCViewPagerManagerInterface
16+
import com.facebook.soloader.SoLoader
1617
import com.reactnativepagerview.event.PageScrollEvent
1718
import com.reactnativepagerview.event.PageScrollStateChangedEvent
1819
import com.reactnativepagerview.event.PageSelectedEvent
1920

2021

2122
@ReactModule(name = PagerViewViewManagerImpl.NAME)
2223
class PagerViewViewManager : ViewGroupManager<NestedScrollableHost>(), RNCViewPagerManagerInterface<NestedScrollableHost> {
24+
companion object {
25+
init {
26+
if (BuildConfig.CODEGEN_MODULE_REGISTRATION != null) {
27+
SoLoader.loadLibrary(BuildConfig.CODEGEN_MODULE_REGISTRATION)
28+
}
29+
}
30+
}
31+
2332
private val mDelegate: ViewManagerDelegate<NestedScrollableHost> = RNCViewPagerManagerDelegate(this)
2433

2534
override fun getDelegate() = mDelegate

0 commit comments

Comments
 (0)