Skip to content

Commit 0fcb10e

Browse files
committed
upgrade RN 0.7x for example
1 parent 1b9c160 commit 0fcb10e

File tree

30 files changed

+5579
-1956
lines changed

30 files changed

+5579
-1956
lines changed

example/.bundle/config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
BUNDLE_PATH: "vendor/bundle"
2+
BUNDLE_FORCE_RUBY_PLATFORM: 1

example/.node-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
18

example/Gemfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
source 'https://rubygems.org'
2+
# You may use http://rbenv.org/ or https://rvm.io/ to install and use this version
3+
ruby '>= 2.6.10'
4+
gem 'cocoapods', '>= 1.11.3'

example/android/app/build.gradle

Lines changed: 63 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -3,129 +3,67 @@ apply plugin: "com.android.application"
33
import com.android.build.OutputFile
44

55
/**
6-
* The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
7-
* and bundleReleaseJsAndAssets).
8-
* These basically call `react-native bundle` with the correct arguments during the Android build
9-
* cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
10-
* bundle directly from the development server. Below you can see all the possible configurations
11-
* and their defaults. If you decide to add a configuration block, make sure to add it before the
12-
* `apply from: "../../node_modules/react-native/react.gradle"` line.
13-
*
14-
* project.ext.react = [
15-
* // the name of the generated asset file containing your JS bundle
16-
* bundleAssetName: "index.android.bundle",
17-
*
18-
* // the entry file for bundle generation
19-
* entryFile: "index.android.js",
20-
*
21-
* // https://reactnative.dev/docs/performance#enable-the-ram-format
22-
* bundleCommand: "ram-bundle",
23-
*
24-
* // whether to bundle JS and assets in debug mode
25-
* bundleInDebug: false,
26-
*
27-
* // whether to bundle JS and assets in release mode
28-
* bundleInRelease: true,
29-
*
30-
* // whether to bundle JS and assets in another build variant (if configured).
31-
* // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
32-
* // The configuration property can be in the following formats
33-
* // 'bundleIn${productFlavor}${buildType}'
34-
* // 'bundleIn${buildType}'
35-
* // bundleInFreeDebug: true,
36-
* // bundleInPaidRelease: true,
37-
* // bundleInBeta: true,
38-
*
39-
* // whether to disable dev mode in custom build variants (by default only disabled in release)
40-
* // for MultipleImagePickerExample: to disable dev mode in the staging build type (if configured)
41-
* devDisabledInStaging: true,
42-
* // The configuration property can be in the following formats
43-
* // 'devDisabledIn${productFlavor}${buildType}'
44-
* // 'devDisabledIn${buildType}'
45-
*
46-
* // the root of your project, i.e. where "package.json" lives
47-
* root: "../../",
48-
*
49-
* // where to put the JS bundle asset in debug mode
50-
* jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
51-
*
52-
* // where to put the JS bundle asset in release mode
53-
* jsBundleDirRelease: "$buildDir/intermediates/assets/release",
54-
*
55-
* // where to put drawable resources / React Native assets, e.g. the ones you use via
56-
* // require('./image.png')), in debug mode
57-
* resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
58-
*
59-
* // where to put drawable resources / React Native assets, e.g. the ones you use via
60-
* // require('./image.png')), in release mode
61-
* resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
62-
*
63-
* // by default the gradle tasks are skipped if none of the JS files or assets change; this means
64-
* // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
65-
* // date; if you have any other folders that you want to ignore for performance reasons (gradle
66-
* // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
67-
* // for MultipleImagePickerExample, you might want to remove it from here.
68-
* inputExcludes: ["android/**", "ios/**"],
69-
*
70-
* // override which node gets called and with what additional arguments
71-
* nodeExecutableAndArgs: ["node"],
72-
*
73-
* // supply additional arguments to the packager
74-
* extraPackagerArgs: []
75-
* ]
76-
*/
77-
78-
project.ext.react = [
79-
enableHermes: false, // clean and rebuild if changing
80-
entryFile: "index.tsx",
81-
]
82-
83-
apply from: "../../node_modules/react-native/react.gradle"
84-
85-
/**
86-
* Set this to true to create two separate APKs instead of one:
87-
* - An APK that only works on ARM devices
88-
* - An APK that only works on x86 devices
89-
* The advantage is the size of the APK is reduced by about 4MB.
90-
* Upload all the APKs to the Play Store and people will download
91-
* the correct one based on the CPU architecture of their device.
92-
*/
93-
def enableSeparateBuildPerCPUArchitecture = false
946
95-
/**
96-
* Run Proguard to shrink the Java bytecode in release builds.
7+
* This is the configuration block to customize your React Native Android app.
8+
* By default you don't need to apply any configuration, just uncomment the lines you need.
979
*/
98-
def enableProguardInReleaseBuilds = false
99-
10+
react {
11+
/* Folders */
12+
// The root of your project, i.e. where "package.json" lives. Default is '..'
13+
// root = file("../")
14+
// The folder where the react-native NPM package is. Default is ../node_modules/react-native
15+
// reactNativeDir = file("../node_modules/react-native")
16+
// The folder where the react-native Codegen package is. Default is ../node_modules/react-native-codegen
17+
// codegenDir = file("../node_modules/react-native-codegen")
18+
// The cli.js file which is the React Native CLI entrypoint. Default is ../node_modules/react-native/cli.js
19+
// cliFile = file("../node_modules/react-native/cli.js")
20+
/* Variants */
21+
// The list of variants to that are debuggable. For those we're going to
22+
// skip the bundling of the JS bundle and the assets. By default is just 'debug'.
23+
// If you add flavors like lite, prod, etc. you'll have to list your debuggableVariants.
24+
// debuggableVariants = ["liteDebug", "prodDebug"]
25+
/* Bundling */
26+
// A list containing the node command and its flags. Default is just 'node'.
27+
// nodeExecutableAndArgs = ["node"]
28+
//
29+
// The command to run when bundling. By default is 'bundle'
30+
// bundleCommand = "ram-bundle"
31+
//
32+
// The path to the CLI configuration file. Default is empty.
33+
// bundleConfig = file(../rn-cli.config.js)
34+
//
35+
// The name of the generated asset file containing your JS bundle
36+
// bundleAssetName = "MyApplication.android.bundle"
37+
//
38+
// The entry file for bundle generation. Default is 'index.android.js' or 'index.js'
39+
// entryFile = file("../js/MyApplication.android.js")
40+
//
41+
// A list of extra flags to pass to the 'bundle' commands.
42+
// See https://github.com/react-native-community/cli/blob/main/docs/commands.md#bundle
43+
// extraPackagerArgs = []
44+
/* Hermes Commands */
45+
// The hermes compiler command to run. By default it is 'hermesc'
46+
// hermesCommand = "$rootDir/my-custom-hermesc/bin/hermesc"
47+
//
48+
// The list of flags to pass to the Hermes compiler. By default is "-O", "-output-source-map"
49+
// hermesFlags = ["-O", "-output-source-map"]
50+
}
10051
/**
101-
* The preferred build flavor of JavaScriptCore.
102-
*
103-
* For MultipleImagePickerExample, to use the international variant, you can use:
104-
* `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
105-
*
106-
* The international variant includes ICU i18n library and necessary data
107-
* allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
108-
* give correct results when using with locales other than en-US. Note that
109-
* this variant is about 6MiB larger per architecture than default.
110-
*/
111-
def jscFlavor = 'org.webkit:android-jsc:+'
52+
def enableSeparateBuildPerCPUArchitecture = false
11253
113-
/**
114-
* Whether to enable the Hermes VM.
115-
*
116-
* This should be set on project.ext.react and mirrored here. If it is not set
117-
* on project.ext.react, JavaScript will not be compiled to Hermes Bytecode
118-
* and the benefits of using Hermes will therefore be sharply reduced.
54+
* Private function to get the list of Native Architectures you want to build.
55+
* This reads the value from reactNativeArchitectures in your gradle.properties
56+
* file and works together with the --active-arch-only flag of react-native run-android.
11957
*/
120-
def enableHermes = project.ext.react.get("enableHermes", false);
58+
def reactNativeArchitectures() {
59+
def value = project.getProperties().get("reactNativeArchitectures")
60+
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
61+
}
12162

12263
android {
64+
ndkVersion rootProject.ext.ndkVersion
12365
compileSdkVersion rootProject.ext.compileSdkVersion
124-
125-
compileOptions {
126-
sourceCompatibility JavaVersion.VERSION_1_8
127-
targetCompatibility JavaVersion.VERSION_1_8
128-
}
66+
namespace "com.example.reactnativemultipleimagepicker"
12967

13068
defaultConfig {
13169
applicationId "com.example.reactnativemultipleimagepicker"
@@ -139,7 +77,7 @@ android {
13977
reset()
14078
enable enableSeparateBuildPerCPUArchitecture
14179
universalApk false // If true, also generate a universal APK
142-
include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
80+
include (*reactNativeArchitectures())
14381
}
14482
}
14583
signingConfigs {
@@ -171,37 +109,28 @@ android {
171109
def abi = output.getFilter(OutputFile.ABI)
172110
if (abi != null) { // null for the universal-debug, universal-release variants
173111
output.versionCodeOverride =
174-
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
112+
defaultConfig.versionCode * 1000 + versionCodes.get(abi)
175113
}
176114

177115
}
178116
}
179117
}
180118

181119
dependencies {
182-
implementation fileTree(dir: "libs", include: ["*.jar"])
183-
//noinspection GradleDynamicVersion
184-
implementation "com.facebook.react:react-native:+" // From node_modules
185-
120+
// The version of react-native is set by the React Native Gradle Plugin
121+
implementation("com.facebook.react:react-android")
186122

187-
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
188-
debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
189-
exclude group:'com.facebook.fbjni'
190-
}
123+
implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.0.0")
191124

125+
debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}")
192126
debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
193-
exclude group:'com.facebook.flipper'
194127
exclude group:'com.squareup.okhttp3', module:'okhttp'
195128
}
196129

197-
debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
198-
exclude group:'com.facebook.flipper'
199-
}
200-
201-
if (enableHermes) {
202-
def hermesPath = "../../node_modules/hermes-engine/android/";
203-
debugImplementation files(hermesPath + "hermes-debug.aar")
204-
releaseImplementation files(hermesPath + "hermes-release.aar")
130+
debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}")
131+
132+
if (hermesEnabled.toBoolean()) {
133+
implementation("com.facebook.react:hermes-android")
205134
} else {
206135
implementation jscFlavor
207136
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@
44

55
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
66

7-
<application android:usesCleartextTraffic="true" tools:targetApi="28" tools:ignore="GoogleAppIndexingWarning" />
7+
<application android:usesCleartextTraffic="true" tools:targetApi="28" tools:ignore="GoogleAppIndexingWarning">
8+
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" android:exported="false" />
9+
</application>
810
</manifest>

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,18 @@
1717
import com.facebook.flipper.plugins.inspector.InspectorFlipperPlugin;
1818
import com.facebook.flipper.plugins.network.FlipperOkhttpInterceptor;
1919
import com.facebook.flipper.plugins.network.NetworkFlipperPlugin;
20-
import com.facebook.flipper.plugins.react.ReactFlipperPlugin;
20+
import com.facebook.react.ReactInstanceEventListener;
2121
import com.facebook.flipper.plugins.sharedpreferences.SharedPreferencesFlipperPlugin;
2222
import com.facebook.react.ReactInstanceManager;
2323
import com.facebook.react.bridge.ReactContext;
2424
import com.facebook.react.modules.network.NetworkingModule;
2525
import okhttp3.OkHttpClient;
2626

27+
/**
28+
* Class responsible of loading Flipper inside your React Native application. This is the debug
29+
* flavor of it. Here you can add your own plugins and customize the Flipper setup.
30+
*/
31+
2732
public class ReactNativeFlipper {
2833
public static void initializeFlipper(Context context, ReactInstanceManager reactInstanceManager) {
2934
if (FlipperUtils.shouldEnableFlipper(context)) {
@@ -48,7 +53,7 @@ public void apply(OkHttpClient.Builder builder) {
4853
ReactContext reactContext = reactInstanceManager.getCurrentReactContext();
4954
if (reactContext == null) {
5055
reactInstanceManager.addReactInstanceEventListener(
51-
new ReactInstanceManager.ReactInstanceEventListener() {
56+
new ReactInstanceEventListener() {
5257
@Override
5358
public void onReactContextInitialized(ReactContext reactContext) {
5459
reactInstanceManager.removeReactInstanceEventListener(this);

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

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,12 @@
1-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
xmlns:tools="http://schemas.android.com/tools"
3-
package="com.example.reactnativemultipleimagepicker">
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
42

53
<uses-permission android:name="android.permission.INTERNET" />
64
<uses-permission android:name="android.permission.CAMERA"/>
75
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
86
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
97

10-
<application
11-
android:name=".MainApplication"
12-
android:allowBackup="false"
13-
android:icon="@mipmap/ic_launcher"
14-
android:label="@string/app_name"
15-
android:roundIcon="@mipmap/ic_launcher_round"
16-
android:theme="@style/AppTheme">
17-
<activity
18-
android:name=".MainActivity"
19-
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
20-
android:label="@string/app_name"
21-
android:launchMode="singleTask"
22-
android:windowSoftInputMode="adjustResize">
8+
<application android:name=".MainApplication" android:allowBackup="false" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:theme="@style/AppTheme">
9+
<activity android:name=".MainActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode" android:label="@string/app_name" android:launchMode="singleTask" android:windowSoftInputMode="adjustResize" android:exported="true">
2310
<intent-filter>
2411
<action android:name="android.intent.action.MAIN" />
2512
<category android:name="android.intent.category.LAUNCHER" />

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package com.example.reactnativemultipleimagepicker;
22

33
import com.facebook.react.ReactActivity;
4+
import com.facebook.react.ReactActivityDelegate;
5+
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint;
6+
import com.facebook.react.defaults.DefaultReactActivityDelegate;
47

58
public class MainActivity extends ReactActivity {
69

@@ -12,4 +15,21 @@ public class MainActivity extends ReactActivity {
1215
protected String getMainComponentName() {
1316
return "MultipleImagePickerExample";
1417
}
18+
19+
/**
20+
* Returns the instance of the {@link ReactActivityDelegate}. Here we use a util class {@link
21+
* DefaultReactActivityDelegate} which allows you to easily enable Fabric and Concurrent React
22+
* (aka React 18) with two boolean flags.
23+
*/
24+
@Override
25+
protected ReactActivityDelegate createReactActivityDelegate() {
26+
return new DefaultReactActivityDelegate(
27+
this,
28+
getMainComponentName(),
29+
// If you opted-in for the New Architecture, we enable the Fabric Renderer.
30+
DefaultNewArchitectureEntryPoint.getFabricEnabled(), // fabricEnabled
31+
// If you opted-in for the New Architecture, we enable Concurrent React (i.e. React 18).
32+
DefaultNewArchitectureEntryPoint.getConcurrentReactEnabled() // concurrentRootEnabled
33+
);
34+
}
1535
}

0 commit comments

Comments
 (0)