Skip to content

Commit b50eb3e

Browse files
Naturalclaridkjs
andauthored
Upgrade template to use RN 0.62 (#5)
Co-authored-by: Alain Armand <idkjs@users.noreply.github.com>
1 parent 2a2c124 commit b50eb3e

File tree

19 files changed

+320
-255
lines changed

19 files changed

+320
-255
lines changed

template/.flowconfig

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ node_modules/warning/.*
2121
[include]
2222

2323
[libs]
24-
node_modules/react-native/Libraries/react-native/react-native-interface.js
24+
node_modules/react-native/interface.js
2525
node_modules/react-native/flow/
2626

2727
[options]
@@ -36,9 +36,8 @@ module.file_ext=.ios.js
3636

3737
munge_underscores=true
3838

39-
module.name_mapper='^react-native$' -> '<PROJECT_ROOT>/node_modules/react-native/Libraries/react-native/react-native-implementation'
4039
module.name_mapper='^react-native/\(.*\)$' -> '<PROJECT_ROOT>/node_modules/react-native/\1'
41-
module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> '<PROJECT_ROOT>/node_modules/react-native/Libraries/Image/RelativeImageStub'
40+
module.name_mapper='^@?[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> '<PROJECT_ROOT>/node_modules/react-native/Libraries/Image/RelativeImageStub'
4241

4342
suppress_type=$FlowIssue
4443
suppress_type=$FlowFixMe
@@ -72,4 +71,4 @@ untyped-import
7271
untyped-type-import
7372

7473
[version]
75-
^0.105.0
74+
^0.113.0

template/.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@
44
# .re and .rei files are Reason, sometimes recognized as C/C++ (on GitHub)
55
*.re linguist-language=Reason
66
*.rei linguist-language=Reason
7+
8+
# specific for windows script files
9+
*.bat text eol=crlf

template/android/app/build.gradle

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ import com.android.build.OutputFile
1515
* // the name of the generated asset file containing your JS bundle
1616
* bundleAssetName: "index.android.bundle",
1717
*
18-
* // the entry file for bundle generation
18+
* // the entry file for bundle generation. If none specified and
19+
* // "index.android.js" exists, it will be used. Otherwise "index.js" is
20+
* // default. Can be overridden with ENTRY_FILE environment variable.
1921
* entryFile: "index.android.js",
2022
*
2123
* // https://facebook.github.io/react-native/docs/performance#enable-the-ram-format
@@ -76,7 +78,6 @@ import com.android.build.OutputFile
7678
*/
7779

7880
project.ext.react = [
79-
entryFile: "index.js",
8081
enableHermes: false, // clean and rebuild if changing
8182
]
8283

@@ -162,6 +163,14 @@ android {
162163
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
163164
}
164165
}
166+
167+
packagingOptions {
168+
pickFirst "lib/armeabi-v7a/libc++_shared.so"
169+
pickFirst "lib/arm64-v8a/libc++_shared.so"
170+
pickFirst "lib/x86/libc++_shared.so"
171+
pickFirst "lib/x86_64/libc++_shared.so"
172+
}
173+
165174
// applicationVariants are e.g. debug, release
166175
applicationVariants.all { variant ->
167176
variant.outputs.each { output ->
@@ -176,27 +185,33 @@ android {
176185

177186
}
178187
}
179-
180-
packagingOptions {
181-
pickFirst '**/armeabi-v7a/libc++_shared.so'
182-
pickFirst '**/x86/libc++_shared.so'
183-
pickFirst '**/arm64-v8a/libc++_shared.so'
184-
pickFirst '**/x86_64/libc++_shared.so'
185-
pickFirst '**/x86/libjsc.so'
186-
pickFirst '**/armeabi-v7a/libjsc.so'
187-
}
188188
}
189189

190190
dependencies {
191191
implementation fileTree(dir: "libs", include: ["*.jar"])
192+
//noinspection GradleDynamicVersion
192193
implementation "com.facebook.react:react-native:+" // From node_modules
193194

195+
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
196+
197+
debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
198+
exclude group:'com.facebook.fbjni'
199+
}
200+
201+
debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
202+
exclude group:'com.facebook.flipper'
203+
}
204+
205+
debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
206+
exclude group:'com.facebook.flipper'
207+
}
208+
194209
if (enableHermes) {
195-
def hermesPath = "../../node_modules/hermesvm/android/";
196-
debugImplementation files(hermesPath + "hermes-debug.aar")
197-
releaseImplementation files(hermesPath + "hermes-release.aar")
210+
def hermesPath = "../../node_modules/hermes-engine/android/";
211+
debugImplementation files(hermesPath + "hermes-debug.aar")
212+
releaseImplementation files(hermesPath + "hermes-release.aar")
198213
} else {
199-
implementation jscFlavor
214+
implementation jscFlavor
200215
}
201216
}
202217

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
<activity
1414
android:name=".MainActivity"
1515
android:label="@string/app_name"
16-
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
16+
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
17+
android:launchMode="singleTask"
1718
android:windowSoftInputMode="adjustResize">
1819
<intent-filter>
1920
<action android:name="android.intent.action.MAIN" />

template/android/app/src/main/java/com/projectname/MainApplication.java

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
package com.projectname;
22

33
import android.app.Application;
4-
import android.util.Log;
54
import android.content.Context;
65
import com.facebook.react.PackageList;
7-
import com.facebook.hermes.reactexecutor.HermesExecutorFactory;
8-
import com.facebook.react.bridge.JavaScriptExecutorFactory;
96
import com.facebook.react.ReactApplication;
7+
import com.facebook.react.ReactInstanceManager;
108
import com.facebook.react.ReactNativeHost;
119
import com.facebook.react.ReactPackage;
1210
import com.facebook.soloader.SoLoader;
@@ -15,26 +13,27 @@
1513

1614
public class MainApplication extends Application implements ReactApplication {
1715

18-
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
19-
@Override
20-
public boolean getUseDeveloperSupport() {
21-
return BuildConfig.DEBUG;
22-
}
16+
private final ReactNativeHost mReactNativeHost =
17+
new ReactNativeHost(this) {
18+
@Override
19+
public boolean getUseDeveloperSupport() {
20+
return BuildConfig.DEBUG;
21+
}
2322

24-
@Override
25-
protected List<ReactPackage> getPackages() {
26-
@SuppressWarnings("UnnecessaryLocalVariable")
27-
List<ReactPackage> packages = new PackageList(this).getPackages();
28-
// Packages that cannot be autolinked yet can be added manually here, for example:
29-
// packages.add(new MyReactNativePackage());
30-
return packages;
31-
}
23+
@Override
24+
protected List<ReactPackage> getPackages() {
25+
@SuppressWarnings("UnnecessaryLocalVariable")
26+
List<ReactPackage> packages = new PackageList(this).getPackages();
27+
// Packages that cannot be autolinked yet can be added manually here, for example:
28+
// packages.add(new MyReactNativePackage());
29+
return packages;
30+
}
3231

33-
@Override
34-
protected String getJSMainModuleName() {
35-
return "index";
36-
}
37-
};
32+
@Override
33+
protected String getJSMainModuleName() {
34+
return "index";
35+
}
36+
};
3837

3938
@Override
4039
public ReactNativeHost getReactNativeHost() {
@@ -45,23 +44,28 @@ public ReactNativeHost getReactNativeHost() {
4544
public void onCreate() {
4645
super.onCreate();
4746
SoLoader.init(this, /* native exopackage */ false);
48-
initializeFlipper(this); // Remove this line if you don't want Flipper enabled
47+
initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
4948
}
5049

5150
/**
52-
* Loads Flipper in React Native templates.
51+
* Loads Flipper in React Native templates. Call this in the onCreate method with something like
52+
* initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
5353
*
5454
* @param context
55+
* @param reactInstanceManager
5556
*/
56-
private static void initializeFlipper(Context context) {
57+
private static void initializeFlipper(
58+
Context context, ReactInstanceManager reactInstanceManager) {
5759
if (BuildConfig.DEBUG) {
5860
try {
5961
/*
60-
We use reflection here to pick up the class that initializes Flipper,
62+
We use reflection here to pick up the class that initializes Flipper,
6163
since Flipper library is not available in release mode
6264
*/
63-
Class<?> aClass = Class.forName("com.facebook.flipper.ReactNativeFlipper");
64-
aClass.getMethod("initializeFlipper", Context.class).invoke(null, context);
65+
Class<?> aClass = Class.forName("com.projectname.ReactNativeFlipper");
66+
aClass
67+
.getMethod("initializeFlipper", Context.class, ReactInstanceManager.class)
68+
.invoke(null, context, reactInstanceManager);
6569
} catch (ClassNotFoundException e) {
6670
e.printStackTrace();
6771
} catch (NoSuchMethodException e) {
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* <p>This source code is licensed under the MIT license found in the LICENSE file in the root
5+
* directory of this source tree.
6+
*/
7+
package com.projectname;
8+
9+
import android.content.Context;
10+
import com.facebook.flipper.android.AndroidFlipperClient;
11+
import com.facebook.flipper.android.utils.FlipperUtils;
12+
import com.facebook.flipper.core.FlipperClient;
13+
import com.facebook.flipper.plugins.crashreporter.CrashReporterPlugin;
14+
import com.facebook.flipper.plugins.databases.DatabasesFlipperPlugin;
15+
import com.facebook.flipper.plugins.fresco.FrescoFlipperPlugin;
16+
import com.facebook.flipper.plugins.inspector.DescriptorMapping;
17+
import com.facebook.flipper.plugins.inspector.InspectorFlipperPlugin;
18+
import com.facebook.flipper.plugins.network.FlipperOkhttpInterceptor;
19+
import com.facebook.flipper.plugins.network.NetworkFlipperPlugin;
20+
import com.facebook.flipper.plugins.react.ReactFlipperPlugin;
21+
import com.facebook.flipper.plugins.sharedpreferences.SharedPreferencesFlipperPlugin;
22+
import com.facebook.react.ReactInstanceManager;
23+
import com.facebook.react.bridge.ReactContext;
24+
import com.facebook.react.modules.network.NetworkingModule;
25+
import okhttp3.OkHttpClient;
26+
27+
public class ReactNativeFlipper {
28+
public static void initializeFlipper(Context context, ReactInstanceManager reactInstanceManager) {
29+
if (FlipperUtils.shouldEnableFlipper(context)) {
30+
final FlipperClient client = AndroidFlipperClient.getInstance(context);
31+
32+
client.addPlugin(new InspectorFlipperPlugin(context, DescriptorMapping.withDefaults()));
33+
client.addPlugin(new ReactFlipperPlugin());
34+
client.addPlugin(new DatabasesFlipperPlugin(context));
35+
client.addPlugin(new SharedPreferencesFlipperPlugin(context));
36+
client.addPlugin(CrashReporterPlugin.getInstance());
37+
38+
NetworkFlipperPlugin networkFlipperPlugin = new NetworkFlipperPlugin();
39+
NetworkingModule.setCustomClientBuilder(
40+
new NetworkingModule.CustomClientBuilder() {
41+
@Override
42+
public void apply(OkHttpClient.Builder builder) {
43+
builder.addNetworkInterceptor(new FlipperOkhttpInterceptor(networkFlipperPlugin));
44+
}
45+
});
46+
client.addPlugin(networkFlipperPlugin);
47+
client.start();
48+
49+
// Fresco Plugin needs to ensure that ImagePipelineFactory is initialized
50+
// Hence we run if after all native modules have been initialized
51+
ReactContext reactContext = reactInstanceManager.getCurrentReactContext();
52+
if (reactContext == null) {
53+
reactInstanceManager.addReactInstanceEventListener(
54+
new ReactInstanceManager.ReactInstanceEventListener() {
55+
@Override
56+
public void onReactContextInitialized(ReactContext reactContext) {
57+
reactInstanceManager.removeReactInstanceEventListener(this);
58+
reactContext.runOnNativeModulesQueueThread(
59+
new Runnable() {
60+
@Override
61+
public void run() {
62+
client.addPlugin(new FrescoFlipperPlugin());
63+
}
64+
});
65+
}
66+
});
67+
} else {
68+
client.addPlugin(new FrescoFlipperPlugin());
69+
}
70+
}
71+
}
72+
}

template/android/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ buildscript {
1313
jcenter()
1414
}
1515
dependencies {
16-
classpath("com.android.tools.build:gradle:3.4.2")
16+
classpath("com.android.tools.build:gradle:3.5.2")
1717

1818
// NOTE: Do not place your application dependencies here; they belong
1919
// in the individual module build.gradle files
@@ -34,6 +34,6 @@ allprojects {
3434

3535
google()
3636
jcenter()
37-
maven { url 'https://jitpack.io' }
37+
maven { url 'https://www.jitpack.io' }
3838
}
3939
}

template/android/gradle.properties

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,11 @@
1717
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
1818
# org.gradle.parallel=true
1919

20+
# AndroidX package structure to make it clearer which packages are bundled with the
21+
# Android operating system, and which are packaged with your app's APK
22+
# https://developer.android.com/topic/libraries/support-library/androidx-rn
2023
android.useAndroidX=true
24+
# Automatically convert third-party libraries to use AndroidX
2125
android.enableJetifier=true
26+
# Version of flipper SDK to use with React Native
27+
FLIPPER_VERSION=0.33.1
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.5-all.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-all.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

template/android/gradlew

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# you may not use this file except in compliance with the License.
88
# You may obtain a copy of the License at
99
#
10-
# http://www.apache.org/licenses/LICENSE-2.0
10+
# https://www.apache.org/licenses/LICENSE-2.0
1111
#
1212
# Unless required by applicable law or agreed to in writing, software
1313
# distributed under the License is distributed on an "AS IS" BASIS,
@@ -125,9 +125,8 @@ if $darwin; then
125125
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
126126
fi
127127

128-
# For Cygwin, switch paths to Windows format before running java
129-
if $cygwin ; then
130-
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
128+
# For Cygwin or MSYS, switch paths to Windows format before running java
129+
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then APP_HOME=`cygpath --path --mixed "$APP_HOME"`
131130
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
132131
JAVACMD=`cygpath --unix "$JAVACMD"`
133132

0 commit comments

Comments
 (0)