Skip to content

Commit 88323dc

Browse files
feat: upgrade RN version from example to 0.62 (#41)
1 parent 6588c5c commit 88323dc

File tree

12 files changed

+159
-15
lines changed

12 files changed

+159
-15
lines changed

templates/library/$.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
*.pbxproj -text
2+
# specific for windows script files
3+
*.bat text eol=crlf

templates/library/example/$package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
"start": "react-native start"
1010
},
1111
"dependencies": {
12-
"react": "16.9.0",
13-
"react-native": "0.61.5"
12+
"react": "16.11.0",
13+
"react-native": "0.62.0"
1414
},
1515
"devDependencies": {
1616
"@babel/core": "^7.8.4",

templates/library/example/android/app/build.gradle

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ import com.android.build.OutputFile
7676
*/
7777

7878
project.ext.react = [
79-
entryFile: "index.js",
8079
enableHermes: false, // clean and rebuild if changing
8180
]
8281

@@ -176,12 +175,32 @@ android {
176175

177176
}
178177
}
178+
179+
packagingOptions {
180+
pickFirst "lib/armeabi-v7a/libc++_shared.so"
181+
pickFirst "lib/arm64-v8a/libc++_shared.so"
182+
pickFirst "lib/x86/libc++_shared.so"
183+
pickFirst "lib/x86_64/libc++_shared.so"
184+
}
179185
}
180186

181187
dependencies {
182188
implementation fileTree(dir: "libs", include: ["*.jar"])
189+
//noinspection GradleDynamicVersion
183190
implementation "com.facebook.react:react-native:+" // From node_modules
184191

192+
193+
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
194+
debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
195+
exclude group:'com.facebook.fbjni'
196+
}
197+
debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
198+
exclude group:'com.facebook.flipper'
199+
}
200+
debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
201+
exclude group:'com.facebook.flipper'
202+
}
203+
185204
if (enableHermes) {
186205
def hermesPath = "../../node_modules/hermes-engine/android/";
187206
debugImplementation files(hermesPath + "hermes-debug.aar")
@@ -190,7 +209,7 @@ dependencies {
190209
implementation jscFlavor
191210
}
192211

193-
compile project(':<%= project.package %>')
212+
implementation project(':<%= project.package %>')
194213
}
195214

196215
// Run this once to be able to run the application with BUCK
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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.<%= project.name %>Example;
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+
client.addPlugin(new InspectorFlipperPlugin(context, DescriptorMapping.withDefaults()));
32+
client.addPlugin(new ReactFlipperPlugin());
33+
client.addPlugin(new DatabasesFlipperPlugin(context));
34+
client.addPlugin(new SharedPreferencesFlipperPlugin(context));
35+
client.addPlugin(CrashReporterPlugin.getInstance());
36+
NetworkFlipperPlugin networkFlipperPlugin = new NetworkFlipperPlugin();
37+
NetworkingModule.setCustomClientBuilder(
38+
new NetworkingModule.CustomClientBuilder() {
39+
@Override
40+
public void apply(OkHttpClient.Builder builder) {
41+
builder.addNetworkInterceptor(new FlipperOkhttpInterceptor(networkFlipperPlugin));
42+
}
43+
});
44+
client.addPlugin(networkFlipperPlugin);
45+
client.start();
46+
// Fresco Plugin needs to ensure that ImagePipelineFactory is initialized
47+
// Hence we run if after all native modules have been initialized
48+
ReactContext reactContext = reactInstanceManager.getCurrentReactContext();
49+
if (reactContext == null) {
50+
reactInstanceManager.addReactInstanceEventListener(
51+
new ReactInstanceManager.ReactInstanceEventListener() {
52+
@Override
53+
public void onReactContextInitialized(ReactContext reactContext) {
54+
reactInstanceManager.removeReactInstanceEventListener(this);
55+
reactContext.runOnNativeModulesQueueThread(
56+
new Runnable() {
57+
@Override
58+
public void run() {
59+
client.addPlugin(new FrescoFlipperPlugin());
60+
}
61+
});
62+
}
63+
});
64+
} else {
65+
client.addPlugin(new FrescoFlipperPlugin());
66+
}
67+
}
68+
}
69+
}

templates/library/example/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" />

templates/library/example/android/app/src/main/java/com/<%= project.name %>Example/MainApplication.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.facebook.react.ReactApplication;
77
import com.facebook.react.ReactNativeHost;
88
import com.facebook.react.ReactPackage;
9+
import com.facebook.react.ReactInstanceManager;
910
import com.facebook.soloader.SoLoader;
1011
import java.lang.reflect.InvocationTargetException;
1112
import java.util.List;
@@ -47,23 +48,25 @@ public ReactNativeHost getReactNativeHost() {
4748
public void onCreate() {
4849
super.onCreate();
4950
SoLoader.init(this, /* native exopackage */ false);
50-
initializeFlipper(this); // Remove this line if you don't want Flipper enabled
51+
initializeFlipper(this, getReactNativeHost().getReactInstanceManager()); // Remove this line if you don't want Flipper enabled
5152
}
5253

5354
/**
5455
* Loads Flipper in React Native templates.
5556
*
5657
* @param context
5758
*/
58-
private static void initializeFlipper(Context context) {
59+
private static void initializeFlipper(Context context, ReactInstanceManager reactInstanceManager) {
5960
if (BuildConfig.DEBUG) {
6061
try {
6162
/*
6263
We use reflection here to pick up the class that initializes Flipper,
6364
since Flipper library is not available in release mode
6465
*/
65-
Class<?> aClass = Class.forName("com.facebook.flipper.ReactNativeFlipper");
66-
aClass.getMethod("initializeFlipper", Context.class).invoke(null, context);
66+
Class<?> aClass = Class.forName("com.<%= project.package %>Example.ReactNativeFlipper");
67+
aClass
68+
.getMethod("initializeFlipper", Context.class, ReactInstanceManager.class)
69+
.invoke(null, context, reactInstanceManager);
6770
} catch (ClassNotFoundException e) {
6871
e.printStackTrace();
6972
} catch (NoSuchMethodException e) {

templates/library/example/android/build.gradle

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

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

3434
google()
3535
jcenter()
36-
maven { url 'https://jitpack.io' }
36+
maven { url 'https://www.jitpack.io' }
3737
}
3838
}

templates/library/example/android/gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@
1919

2020
android.useAndroidX=true
2121
android.enableJetifier=true
22+
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

templates/library/example/android/gradlew

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ if $darwin; then
126126
fi
127127

128128
# For Cygwin, switch paths to Windows format before running java
129-
if $cygwin ; then
129+
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
130130
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
131131
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
132132
JAVACMD=`cygpath --unix "$JAVACMD"`

0 commit comments

Comments
 (0)