Skip to content

Commit 61021c0

Browse files
committed
chore: SA and TSM app upgrade RN 69.4
1 parent 920a776 commit 61021c0

70 files changed

Lines changed: 4760 additions & 74222 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

examples/SampleApp/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# OSX
1+
\# OSX
22
#
33
.DS_Store
44

@@ -59,3 +59,4 @@ buck-out/
5959
# Ruby / CocoaPods
6060
/ios/Pods/
6161
/vendor
62+
ios/.xcode.env.local

examples/SampleApp/android/app/build.gradle

Lines changed: 97 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,76 @@ android {
145145
versionName "0.0.22"
146146
testBuildType System.getProperty('testBuildType', 'debug') // This will later be used to control the test apk build type
147147
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
148+
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
149+
150+
if (isNewArchitectureEnabled()) {
151+
// We configure the NDK build only if you decide to opt-in for the New Architecture.
152+
externalNativeBuild {
153+
ndkBuild {
154+
arguments "APP_PLATFORM=android-21",
155+
"APP_STL=c++_shared",
156+
"NDK_TOOLCHAIN_VERSION=clang",
157+
"GENERATED_SRC_DIR=$buildDir/generated/source",
158+
"PROJECT_BUILD_DIR=$buildDir",
159+
"REACT_ANDROID_DIR=$rootDir/../node_modules/react-native/ReactAndroid",
160+
"REACT_ANDROID_BUILD_DIR=$rootDir/../node_modules/react-native/ReactAndroid/build",
161+
"NODE_MODULES_DIR=$rootDir/../node_modules"
162+
cFlags "-Wall", "-Werror", "-fexceptions", "-frtti", "-DWITH_INSPECTOR=1"
163+
cppFlags "-std=c++17"
164+
// Make sure this target name is the same you specify inside the
165+
// src/main/jni/Android.mk file for the `LOCAL_MODULE` variable.
166+
targets "rndiffapp_appmodules"
167+
}
168+
}
169+
if (!enableSeparateBuildPerCPUArchitecture) {
170+
ndk {
171+
abiFilters (*reactNativeArchitectures())
172+
}
173+
}
174+
}
148175
}
176+
177+
if (isNewArchitectureEnabled()) {
178+
// We configure the NDK build only if you decide to opt-in for the New Architecture.
179+
externalNativeBuild {
180+
ndkBuild {
181+
path "$projectDir/src/main/jni/Android.mk"
182+
}
183+
}
184+
def reactAndroidProjectDir = project(':ReactAndroid').projectDir
185+
def packageReactNdkDebugLibs = tasks.register("packageReactNdkDebugLibs", Copy) {
186+
dependsOn(":ReactAndroid:packageReactNdkDebugLibsForBuck")
187+
from("$reactAndroidProjectDir/src/main/jni/prebuilt/lib")
188+
into("$buildDir/react-ndk/exported")
189+
}
190+
def packageReactNdkReleaseLibs = tasks.register("packageReactNdkReleaseLibs", Copy) {
191+
dependsOn(":ReactAndroid:packageReactNdkReleaseLibsForBuck")
192+
from("$reactAndroidProjectDir/src/main/jni/prebuilt/lib")
193+
into("$buildDir/react-ndk/exported")
194+
}
195+
afterEvaluate {
196+
// If you wish to add a custom TurboModule or component locally,
197+
// you should uncomment this line.
198+
// preBuild.dependsOn("generateCodegenArtifactsFromSchema")
199+
preDebugBuild.dependsOn(packageReactNdkDebugLibs)
200+
preReleaseBuild.dependsOn(packageReactNdkReleaseLibs)
201+
202+
// Due to a bug inside AGP, we have to explicitly set a dependency
203+
// between configureNdkBuild* tasks and the preBuild tasks.
204+
// This can be removed once this is solved: https://issuetracker.google.com/issues/207403732
205+
configureNdkBuildRelease.dependsOn(preReleaseBuild)
206+
configureNdkBuildDebug.dependsOn(preDebugBuild)
207+
reactNativeArchitectures().each { architecture ->
208+
tasks.findByName("configureNdkBuildDebug[${architecture}]")?.configure {
209+
dependsOn("preDebugBuild")
210+
}
211+
tasks.findByName("configureNdkBuildRelease[${architecture}]")?.configure {
212+
dependsOn("preReleaseBuild")
213+
}
214+
}
215+
}
216+
}
217+
149218
splits {
150219
abi {
151220
reset()
@@ -235,14 +304,31 @@ dependencies {
235304
androidTestImplementation('com.wix:detox:+')
236305

237306
if (enableHermes) {
238-
def hermesPath = "../../node_modules/hermes-engine/android/";
239-
debugImplementation files(hermesPath + "hermes-debug.aar")
240-
releaseImplementation files(hermesPath + "hermes-release.aar")
307+
//noinspection GradleDynamicVersion
308+
implementation("com.facebook.react:hermes-engine:+") { // From node_modules
309+
exclude group:'com.facebook.fbjni'
310+
}
241311
} else {
242312
implementation jscFlavor
243313
}
244314
}
245315

316+
if (isNewArchitectureEnabled()) {
317+
// If new architecture is enabled, we let you build RN from source
318+
// Otherwise we fallback to a prebuilt .aar bundled in the NPM package.
319+
// This will be applied to all the imported transtitive dependency.
320+
configurations.all {
321+
resolutionStrategy.dependencySubstitution {
322+
substitute(module("com.facebook.react:react-native"))
323+
.using(project(":ReactAndroid"))
324+
.because("On New Architecture we're building React Native from source")
325+
substitute(module("com.facebook.react:hermes-engine"))
326+
.using(project(":ReactAndroid:hermes-engine"))
327+
.because("On New Architecture we're building Hermes from source")
328+
}
329+
}
330+
}
331+
246332
// Run this once to be able to run the application with BUCK
247333
// puts all compile dependencies into folder libs for BUCK to use
248334
task copyDownloadableDepsToLibs(type: Copy) {
@@ -251,3 +337,11 @@ task copyDownloadableDepsToLibs(type: Copy) {
251337
}
252338

253339
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
340+
341+
def isNewArchitectureEnabled() {
342+
// To opt-in for the New Architecture, you can either:
343+
// - Set `newArchEnabled` to true inside the `gradle.properties` file
344+
// - Invoke gradle with `-newArchEnabled=true`
345+
// - Set an environment variable `ORG_GRADLE_PROJECT_newArchEnabled=true`
346+
return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
347+
}

examples/SampleApp/android/app/src/debug/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
android:usesCleartextTraffic="true"
99
tools:targetApi="28"
1010
tools:ignore="GoogleAppIndexingWarning">
11-
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
11+
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" android:exported="false" />
1212
</application>
1313
</manifest>

examples/SampleApp/android/app/src/debug/java/com/sampleapp/ReactNativeFlipper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.facebook.react.bridge.ReactContext;
2424
import com.facebook.react.modules.network.NetworkingModule;
2525
import okhttp3.OkHttpClient;
26+
import com.facebook.react.ReactInstanceEventListener;
2627

2728
public class ReactNativeFlipper {
2829
public static void initializeFlipper(Context context, ReactInstanceManager reactInstanceManager) {
@@ -51,7 +52,7 @@ public void apply(OkHttpClient.Builder builder) {
5152
ReactContext reactContext = reactInstanceManager.getCurrentReactContext();
5253
if (reactContext == null) {
5354
reactInstanceManager.addReactInstanceEventListener(
54-
new ReactInstanceManager.ReactInstanceEventListener() {
55+
new ReactInstanceEventListener() {
5556
@Override
5657
public void onReactContextInitialized(ReactContext reactContext) {
5758
reactInstanceManager.removeReactInstanceEventListener(this);

examples/SampleApp/android/app/src/main/AndroidManifest.xml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@
3030
<activity
3131
android:name=".MainActivity"
3232
android:label="@string/app_name"
33-
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
34-
android:launchMode="singleTask"
33+
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"
3534
android:screenOrientation="portrait"
36-
android:windowSoftInputMode="adjustResize">
35+
android:launchMode="singleTask"
36+
android:windowSoftInputMode="adjustResize"
37+
android:exported="true">
3738
<intent-filter>
3839
<action android:name="android.intent.action.MAIN" />
3940
<category android:name="android.intent.category.LAUNCHER" />

examples/SampleApp/android/app/src/main/java/com/sampleapp/MainActivity.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ protected String getMainComponentName() {
1616
return "SampleApp";
1717
}
1818

19+
/**
20+
* Returns the instance of the {@link ReactActivityDelegate}. There the RootView is created and
21+
* you can specify the renderer you wish to use - the new renderer (Fabric) or the old renderer
22+
* (Paper).
23+
*/
1924
@Override
2025
protected ReactActivityDelegate createReactActivityDelegate() {
2126
return new ReactActivityDelegate(this, getMainComponentName()) {
@@ -25,5 +30,26 @@ protected ReactRootView createRootView() {
2530
}
2631
};
2732
}
33+
34+
public static class MainActivityDelegate extends ReactActivityDelegate {
35+
public MainActivityDelegate(ReactActivity activity, String mainComponentName) {
36+
super(activity, mainComponentName);
37+
}
38+
39+
@Override
40+
protected ReactRootView createRootView() {
41+
ReactRootView reactRootView = new ReactRootView(getContext());
42+
// If you opted-in for the New Architecture, we enable the Fabric Renderer.
43+
reactRootView.setIsFabric(false);
44+
return reactRootView;
45+
}
46+
47+
@Override
48+
protected boolean isConcurrentRootEnabled() {
49+
// If you opted-in for the New Architecture, we enable Concurrent Root (i.e. React 18).
50+
// More on this on https://reactjs.org/blog/2022/03/29/react-v18.html
51+
return BuildConfig.IS_NEW_ARCHITECTURE_ENABLED;
52+
}
53+
}
2854
}
2955

examples/SampleApp/android/app/src/main/java/com/sampleapp/MainApplication.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import com.swmansion.reanimated.ReanimatedJSIModulePackage;
1313
import java.lang.reflect.InvocationTargetException;
1414
import java.util.List;
15+
import com.facebook.react.config.ReactFeatureFlags;
16+
import com.sampleapp.newarchitecture.MainApplicationReactNativeHost;
1517

1618
public class MainApplication extends Application implements ReactApplication {
1719

@@ -44,12 +46,21 @@ protected JSIModulePackage getJSIModulePackage() {
4446

4547
@Override
4648
public ReactNativeHost getReactNativeHost() {
47-
return mReactNativeHost;
49+
if (false) {
50+
return mNewArchitectureNativeHost;
51+
} else {
52+
return mReactNativeHost;
53+
}
4854
}
4955

56+
private final ReactNativeHost mNewArchitectureNativeHost =
57+
new MainApplicationReactNativeHost(this);
58+
5059
@Override
5160
public void onCreate() {
5261
super.onCreate();
62+
// If you opted-in for the New Architecture, we enable the TurboModule system
63+
ReactFeatureFlags.useTurboModules = false;
5364
SoLoader.init(this, /* native exopackage */ false);
5465
initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
5566
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
package com.sampleapp.newarchitecture;
2+
3+
import android.app.Application;
4+
import androidx.annotation.NonNull;
5+
import com.facebook.react.PackageList;
6+
import com.facebook.react.ReactInstanceManager;
7+
import com.facebook.react.ReactNativeHost;
8+
import com.facebook.react.ReactPackage;
9+
import com.facebook.react.ReactPackageTurboModuleManagerDelegate;
10+
import com.facebook.react.bridge.JSIModulePackage;
11+
import com.facebook.react.bridge.JSIModuleProvider;
12+
import com.facebook.react.bridge.JSIModuleSpec;
13+
import com.facebook.react.bridge.JSIModuleType;
14+
import com.facebook.react.bridge.JavaScriptContextHolder;
15+
import com.facebook.react.bridge.ReactApplicationContext;
16+
import com.facebook.react.bridge.UIManager;
17+
import com.facebook.react.fabric.ComponentFactory;
18+
import com.facebook.react.fabric.CoreComponentsRegistry;
19+
import com.facebook.react.fabric.ReactNativeConfig;
20+
import com.facebook.react.fabric.FabricJSIModuleProvider;
21+
import com.facebook.react.uimanager.ViewManagerRegistry;
22+
import com.sampleapp.BuildConfig;
23+
import com.sampleapp.newarchitecture.components.MainComponentsRegistry;
24+
import com.sampleapp.newarchitecture.modules.MainApplicationTurboModuleManagerDelegate;
25+
26+
import java.util.ArrayList;
27+
import java.util.List;
28+
/**
29+
* A {@link ReactNativeHost} that helps you load everything needed for the New Architecture, both
30+
* TurboModule delegates and the Fabric Renderer.
31+
*
32+
* <p>Please note that this class is used ONLY if you opt-in for the New Architecture (see the
33+
* `newArchEnabled` property). Is ignored otherwise.
34+
*/
35+
public class MainApplicationReactNativeHost extends ReactNativeHost {
36+
public MainApplicationReactNativeHost(Application application) {
37+
super(application);
38+
}
39+
@Override
40+
public boolean getUseDeveloperSupport() {
41+
return BuildConfig.DEBUG;
42+
}
43+
@Override
44+
protected List<ReactPackage> getPackages() {
45+
List<ReactPackage> packages = new PackageList(this).getPackages();
46+
// Packages that cannot be autolinked yet can be added manually here, for example:
47+
// packages.add(new MyReactNativePackage());
48+
// TurboModules must also be loaded here providing a valid TurboReactPackage implementation:
49+
// packages.add(new TurboReactPackage() { ... });
50+
// If you have custom Fabric Components, their ViewManagers should also be loaded here
51+
// inside a ReactPackage.
52+
return packages;
53+
}
54+
@Override
55+
protected String getJSMainModuleName() {
56+
return "index";
57+
}
58+
@NonNull
59+
@Override
60+
protected ReactPackageTurboModuleManagerDelegate.Builder
61+
getReactPackageTurboModuleManagerDelegateBuilder() {
62+
// Here we provide the ReactPackageTurboModuleManagerDelegate Builder. This is necessary
63+
// for the new architecture and to use TurboModules correctly.
64+
return new MainApplicationTurboModuleManagerDelegate.Builder();
65+
}
66+
@Override
67+
protected JSIModulePackage getJSIModulePackage() {
68+
return new JSIModulePackage() {
69+
@Override
70+
public List<JSIModuleSpec> getJSIModules(
71+
final ReactApplicationContext reactApplicationContext,
72+
final JavaScriptContextHolder jsContext) {
73+
final List<JSIModuleSpec> specs = new ArrayList<>();
74+
// Here we provide a new JSIModuleSpec that will be responsible of providing the
75+
// custom Fabric Components.
76+
specs.add(
77+
new JSIModuleSpec() {
78+
@Override
79+
public JSIModuleType getJSIModuleType() {
80+
return JSIModuleType.UIManager;
81+
}
82+
@Override
83+
public JSIModuleProvider<UIManager> getJSIModuleProvider() {
84+
final ComponentFactory componentFactory = new ComponentFactory();
85+
CoreComponentsRegistry.register(componentFactory);
86+
// Here we register a Components Registry.
87+
// The one that is generated with the template contains no components
88+
// and just provides you the one from React Native core.
89+
MainComponentsRegistry.register(componentFactory);
90+
final ReactInstanceManager reactInstanceManager = getReactInstanceManager();
91+
ViewManagerRegistry viewManagerRegistry =
92+
new ViewManagerRegistry(
93+
reactInstanceManager.getOrCreateViewManagers(reactApplicationContext));
94+
return new FabricJSIModuleProvider(
95+
reactApplicationContext,
96+
componentFactory,
97+
ReactNativeConfig.DEFAULT_CONFIG,
98+
viewManagerRegistry);
99+
}
100+
});
101+
return specs;
102+
}
103+
};
104+
}
105+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.sampleapp.newarchitecture.components;
2+
import com.facebook.jni.HybridData;
3+
import com.facebook.proguard.annotations.DoNotStrip;
4+
import com.facebook.react.fabric.ComponentFactory;
5+
import com.facebook.soloader.SoLoader;
6+
/**
7+
* Class responsible to load the custom Fabric Components. This class has native methods and needs a
8+
* corresponding C++ implementation/header file to work correctly (already placed inside the jni/
9+
* folder for you).
10+
*
11+
* <p>Please note that this class is used ONLY if you opt-in for the New Architecture (see the
12+
* `newArchEnabled` property). Is ignored otherwise.
13+
*/
14+
@DoNotStrip
15+
public class MainComponentsRegistry {
16+
static {
17+
SoLoader.loadLibrary("fabricjni");
18+
}
19+
@DoNotStrip private final HybridData mHybridData;
20+
@DoNotStrip
21+
private native HybridData initHybrid(ComponentFactory componentFactory);
22+
@DoNotStrip
23+
private MainComponentsRegistry(ComponentFactory componentFactory) {
24+
mHybridData = initHybrid(componentFactory);
25+
}
26+
@DoNotStrip
27+
public static MainComponentsRegistry register(ComponentFactory componentFactory) {
28+
return new MainComponentsRegistry(componentFactory);
29+
}
30+
}

0 commit comments

Comments
 (0)