Skip to content

Commit 8331e3b

Browse files
committed
chore: update example & upgrade react-native to v0.69.3.
1 parent e223379 commit 8331e3b

Some content is hidden

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

41 files changed

+3989
-3689
lines changed

example/.flowconfig

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ node_modules/react-native/Libraries/polyfills/.*
1111
; Flow doesn't support platforms
1212
.*/Libraries/Utilities/LoadingView.js
1313

14+
.*/node_modules/resolve/test/resolver/malformed_package_json/package\.json$
15+
1416
[untyped]
1517
.*/node_modules/@react-native-community/cli/.*/.*
1618

@@ -23,11 +25,10 @@ node_modules/react-native/flow/
2325
[options]
2426
emoji=true
2527

26-
esproposal.optional_chaining=enable
27-
esproposal.nullish_coalescing=enable
28-
2928
exact_by_default=true
3029

30+
format.bracket_spacing=false
31+
3132
module.file_ext=.js
3233
module.file_ext=.json
3334
module.file_ext=.ios.js
@@ -51,7 +52,6 @@ nonstrict-import=warn
5152
deprecated-type=warn
5253
unsafe-getters-setters=warn
5354
unnecessary-invariant=warn
54-
signature-verification-failure=warn
5555

5656
[strict]
5757
deprecated-type
@@ -63,4 +63,4 @@ untyped-import
6363
untyped-type-import
6464

6565
[version]
66-
^0.137.0
66+
^0.176.3

example/.gitignore

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ DerivedData
2020
*.hmap
2121
*.ipa
2222
*.xcuserstate
23+
ios/.xcode.env.local
2324

2425
# Android/IntelliJ
2526
#
@@ -28,6 +29,7 @@ build/
2829
.gradle
2930
local.properties
3031
*.iml
32+
*.hprof
3133

3234
# node.js
3335
#
@@ -48,12 +50,14 @@ buck-out/
4850
# For more information about the recommended setup visit:
4951
# https://docs.fastlane.tools/best-practices/source-control/
5052

51-
*/fastlane/report.xml
52-
*/fastlane/Preview.html
53-
*/fastlane/screenshots
53+
**/fastlane/report.xml
54+
**/fastlane/Preview.html
55+
**/fastlane/screenshots
56+
**/fastlane/test_output
5457

5558
# Bundle artifact
5659
*.jsbundle
5760

58-
# CocoaPods
61+
# Ruby / CocoaPods
5962
/ios/Pods/
63+
/vendor/bundle/

example/.prettierrc.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module.exports = {
2+
arrowParens: 'avoid',
3+
bracketSameLine: true,
24
bracketSpacing: false,
3-
jsxBracketSameLine: true,
45
singleQuote: true,
56
trailingComma: 'all',
6-
arrowParens: 'avoid',
77
};

example/android/app/build.gradle

Lines changed: 113 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -114,33 +114,107 @@ def jscFlavor = 'org.webkit:android-jsc:+'
114114
/**
115115
* Whether to enable the Hermes VM.
116116
*
117-
* This should be set on project.ext.react and mirrored here. If it is not set
117+
* This should be set on project.ext.react and that value will be read here. If it is not set
118118
* on project.ext.react, JavaScript will not be compiled to Hermes Bytecode
119119
* and the benefits of using Hermes will therefore be sharply reduced.
120120
*/
121121
def enableHermes = project.ext.react.get("enableHermes", false);
122122

123+
/**
124+
* Architectures to build native code for.
125+
*/
126+
def reactNativeArchitectures() {
127+
def value = project.getProperties().get("reactNativeArchitectures")
128+
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
129+
}
130+
123131
android {
124-
compileSdkVersion rootProject.ext.compileSdkVersion
132+
ndkVersion rootProject.ext.ndkVersion
125133

126-
compileOptions {
127-
sourceCompatibility JavaVersion.VERSION_1_8
128-
targetCompatibility JavaVersion.VERSION_1_8
129-
}
134+
compileSdkVersion rootProject.ext.compileSdkVersion
130135

131136
defaultConfig {
132137
applicationId "com.uiwjs.example.alipay"
133138
minSdkVersion rootProject.ext.minSdkVersion
134139
targetSdkVersion rootProject.ext.targetSdkVersion
135140
versionCode 1
136141
versionName "1.0"
142+
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
143+
144+
if (isNewArchitectureEnabled()) {
145+
// We configure the NDK build only if you decide to opt-in for the New Architecture.
146+
externalNativeBuild {
147+
ndkBuild {
148+
arguments "APP_PLATFORM=android-21",
149+
"APP_STL=c++_shared",
150+
"NDK_TOOLCHAIN_VERSION=clang",
151+
"GENERATED_SRC_DIR=$buildDir/generated/source",
152+
"PROJECT_BUILD_DIR=$buildDir",
153+
"REACT_ANDROID_DIR=$rootDir/../node_modules/react-native/ReactAndroid",
154+
"REACT_ANDROID_BUILD_DIR=$rootDir/../node_modules/react-native/ReactAndroid/build",
155+
"NODE_MODULES_DIR=$rootDir/../node_modules"
156+
cFlags "-Wall", "-Werror", "-fexceptions", "-frtti", "-DWITH_INSPECTOR=1"
157+
cppFlags "-std=c++17"
158+
// Make sure this target name is the same you specify inside the
159+
// src/main/jni/Android.mk file for the `LOCAL_MODULE` variable.
160+
targets "example_appmodules"
161+
}
162+
}
163+
if (!enableSeparateBuildPerCPUArchitecture) {
164+
ndk {
165+
abiFilters (*reactNativeArchitectures())
166+
}
167+
}
168+
}
137169
}
170+
171+
if (isNewArchitectureEnabled()) {
172+
// We configure the NDK build only if you decide to opt-in for the New Architecture.
173+
externalNativeBuild {
174+
ndkBuild {
175+
path "$projectDir/src/main/jni/Android.mk"
176+
}
177+
}
178+
def reactAndroidProjectDir = project(':ReactAndroid').projectDir
179+
def packageReactNdkDebugLibs = tasks.register("packageReactNdkDebugLibs", Copy) {
180+
dependsOn(":ReactAndroid:packageReactNdkDebugLibsForBuck")
181+
from("$reactAndroidProjectDir/src/main/jni/prebuilt/lib")
182+
into("$buildDir/react-ndk/exported")
183+
}
184+
def packageReactNdkReleaseLibs = tasks.register("packageReactNdkReleaseLibs", Copy) {
185+
dependsOn(":ReactAndroid:packageReactNdkReleaseLibsForBuck")
186+
from("$reactAndroidProjectDir/src/main/jni/prebuilt/lib")
187+
into("$buildDir/react-ndk/exported")
188+
}
189+
afterEvaluate {
190+
// If you wish to add a custom TurboModule or component locally,
191+
// you should uncomment this line.
192+
// preBuild.dependsOn("generateCodegenArtifactsFromSchema")
193+
preDebugBuild.dependsOn(packageReactNdkDebugLibs)
194+
preReleaseBuild.dependsOn(packageReactNdkReleaseLibs)
195+
196+
// Due to a bug inside AGP, we have to explicitly set a dependency
197+
// between configureNdkBuild* tasks and the preBuild tasks.
198+
// This can be removed once this is solved: https://issuetracker.google.com/issues/207403732
199+
configureNdkBuildRelease.dependsOn(preReleaseBuild)
200+
configureNdkBuildDebug.dependsOn(preDebugBuild)
201+
reactNativeArchitectures().each { architecture ->
202+
tasks.findByName("configureNdkBuildDebug[${architecture}]")?.configure {
203+
dependsOn("preDebugBuild")
204+
}
205+
tasks.findByName("configureNdkBuildRelease[${architecture}]")?.configure {
206+
dependsOn("preReleaseBuild")
207+
}
208+
}
209+
}
210+
}
211+
138212
splits {
139213
abi {
140214
reset()
141215
enable enableSeparateBuildPerCPUArchitecture
142216
universalApk false // If true, also generate a universal APK
143-
include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
217+
include (*reactNativeArchitectures())
144218
}
145219
}
146220
signingConfigs {
@@ -169,6 +243,7 @@ android {
169243
variant.outputs.each { output ->
170244
// For each separate APK per architecture, set a unique version code as described here:
171245
// https://developer.android.com/studio/build/configure-apk-splits.html
246+
// Example: versionCode 1 will generate 1001 for armeabi-v7a, 1002 for x86, etc.
172247
def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
173248
def abi = output.getFilter(OutputFile.ABI)
174249
if (abi != null) { // null for the universal-debug, universal-release variants
@@ -182,13 +257,14 @@ android {
182257

183258
dependencies {
184259
implementation fileTree(dir: "libs", include: ["*.jar"])
260+
185261
//noinspection GradleDynamicVersion
186262
implementation "com.facebook.react:react-native:+" // From node_modules
187263

188264
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
189265

190266
debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
191-
exclude group:'com.facebook.fbjni'
267+
exclude group:'com.facebook.fbjni'
192268
}
193269

194270
debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
@@ -201,19 +277,44 @@ dependencies {
201277
}
202278

203279
if (enableHermes) {
204-
def hermesPath = "../../node_modules/hermes-engine/android/";
205-
debugImplementation files(hermesPath + "hermes-debug.aar")
206-
releaseImplementation files(hermesPath + "hermes-release.aar")
280+
//noinspection GradleDynamicVersion
281+
implementation("com.facebook.react:hermes-engine:+") { // From node_modules
282+
exclude group:'com.facebook.fbjni'
283+
}
207284
} else {
208285
implementation jscFlavor
209286
}
210287
}
211288

289+
if (isNewArchitectureEnabled()) {
290+
// If new architecture is enabled, we let you build RN from source
291+
// Otherwise we fallback to a prebuilt .aar bundled in the NPM package.
292+
// This will be applied to all the imported transtitive dependency.
293+
configurations.all {
294+
resolutionStrategy.dependencySubstitution {
295+
substitute(module("com.facebook.react:react-native"))
296+
.using(project(":ReactAndroid"))
297+
.because("On New Architecture we're building React Native from source")
298+
substitute(module("com.facebook.react:hermes-engine"))
299+
.using(project(":ReactAndroid:hermes-engine"))
300+
.because("On New Architecture we're building Hermes from source")
301+
}
302+
}
303+
}
304+
212305
// Run this once to be able to run the application with BUCK
213306
// puts all compile dependencies into folder libs for BUCK to use
214307
task copyDownloadableDepsToLibs(type: Copy) {
215-
from configurations.compile
308+
from configurations.implementation
216309
into 'libs'
217310
}
218311

219312
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
313+
314+
def isNewArchitectureEnabled() {
315+
// To opt-in for the New Architecture, you can either:
316+
// - Set `newArchEnabled` to true inside the `gradle.properties` file
317+
// - Invoke gradle with `-newArchEnabled=true`
318+
// - Set an environment variable `ORG_GRADLE_PROJECT_newArchEnabled=true`
319+
return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
320+
}

example/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>

example/android/app/src/debug/java/com/example/ReactNativeFlipper.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright (c) Facebook, Inc. and its affiliates.
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
33
*
44
* <p>This source code is licensed under the MIT license found in the LICENSE file in the root
55
* directory of this source tree.
@@ -19,6 +19,7 @@
1919
import com.facebook.flipper.plugins.network.NetworkFlipperPlugin;
2020
import com.facebook.flipper.plugins.react.ReactFlipperPlugin;
2121
import com.facebook.flipper.plugins.sharedpreferences.SharedPreferencesFlipperPlugin;
22+
import com.facebook.react.ReactInstanceEventListener;
2223
import com.facebook.react.ReactInstanceManager;
2324
import com.facebook.react.bridge.ReactContext;
2425
import com.facebook.react.modules.network.NetworkingModule;
@@ -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);

example/android/app/src/main/AndroidManifest.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
<activity
1414
android:name=".MainActivity"
1515
android:label="@string/app_name"
16-
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
16+
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"
1717
android:launchMode="singleTask"
18-
android:windowSoftInputMode="adjustResize">
18+
android:windowSoftInputMode="adjustResize"
19+
android:exported="true">
1920
<intent-filter>
2021
<action android:name="android.intent.action.MAIN" />
2122
<category android:name="android.intent.category.LAUNCHER" />

example/android/app/src/main/java/com/example/MainActivity.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.uiwjs.example.alipay;
22

33
import com.facebook.react.ReactActivity;
4+
import com.facebook.react.ReactActivityDelegate;
5+
import com.facebook.react.ReactRootView;
46

57
public class MainActivity extends ReactActivity {
68

@@ -12,4 +14,35 @@ public class MainActivity extends ReactActivity {
1214
protected String getMainComponentName() {
1315
return "example";
1416
}
17+
18+
/**
19+
* Returns the instance of the {@link ReactActivityDelegate}. There the RootView is created and
20+
* you can specify the renderer you wish to use - the new renderer (Fabric) or the old renderer
21+
* (Paper).
22+
*/
23+
@Override
24+
protected ReactActivityDelegate createReactActivityDelegate() {
25+
return new MainActivityDelegate(this, getMainComponentName());
26+
}
27+
28+
public static class MainActivityDelegate extends ReactActivityDelegate {
29+
public MainActivityDelegate(ReactActivity activity, String mainComponentName) {
30+
super(activity, mainComponentName);
31+
}
32+
33+
@Override
34+
protected ReactRootView createRootView() {
35+
ReactRootView reactRootView = new ReactRootView(getContext());
36+
// If you opted-in for the New Architecture, we enable the Fabric Renderer.
37+
reactRootView.setIsFabric(BuildConfig.IS_NEW_ARCHITECTURE_ENABLED);
38+
return reactRootView;
39+
}
40+
41+
@Override
42+
protected boolean isConcurrentRootEnabled() {
43+
// If you opted-in for the New Architecture, we enable Concurrent Root (i.e. React 18).
44+
// More on this on https://reactjs.org/blog/2022/03/29/react-v18.html
45+
return BuildConfig.IS_NEW_ARCHITECTURE_ENABLED;
46+
}
47+
}
1548
}

example/android/app/src/main/java/com/example/MainApplication.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
import com.facebook.react.ReactInstanceManager;
88
import com.facebook.react.ReactNativeHost;
99
import com.facebook.react.ReactPackage;
10+
import com.facebook.react.config.ReactFeatureFlags;
1011
import com.facebook.soloader.SoLoader;
12+
import com.uiwjs.example.alipay.newarchitecture.MainApplicationReactNativeHost;
1113
import java.lang.reflect.InvocationTargetException;
1214
import java.util.List;
1315

@@ -35,14 +37,23 @@ protected String getJSMainModuleName() {
3537
}
3638
};
3739

40+
private final ReactNativeHost mNewArchitectureNativeHost =
41+
new MainApplicationReactNativeHost(this);
42+
3843
@Override
3944
public ReactNativeHost getReactNativeHost() {
40-
return mReactNativeHost;
45+
if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
46+
return mNewArchitectureNativeHost;
47+
} else {
48+
return mReactNativeHost;
49+
}
4150
}
4251

4352
@Override
4453
public void onCreate() {
4554
super.onCreate();
55+
// If you opted-in for the New Architecture, we enable the TurboModule system
56+
ReactFeatureFlags.useTurboModules = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED;
4657
SoLoader.init(this, /* native exopackage */ false);
4758
initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
4859
}

0 commit comments

Comments
 (0)