Skip to content

Commit 70ff4fb

Browse files
committed
fix: update react native
1 parent afb74e1 commit 70ff4fb

30 files changed

+962
-585
lines changed

.eslintrc.js

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,8 @@
11
module.exports = {
2-
parser: "@typescript-eslint/parser", // specifies the ESLint parser
3-
parserOptions: {
4-
ecmaVersion: 2018, // allows for the parsing of modern ECMAScript features
5-
sourceType: "module", // allows for the use of imports
6-
project: "./tsconfig.json",
7-
ecmaFeatures: {
8-
jsx: true
9-
}
2+
root: true,
3+
extends: ['@react-native-community'],
4+
env: {
5+
jest: true,
106
},
11-
extends: [
12-
"plugin:@typescript-eslint/recommended", // typescript
13-
"prettier/@typescript-eslint", // prettier
14-
"plugin:react/recommended" // react
15-
],
16-
plugins: ["react-hooks"],
17-
settings: {
18-
react: {
19-
version: "detect"
20-
}
21-
},
22-
rules: {
23-
"react/display-name": 0,
24-
"@typescript-eslint/explicit-function-return-type": 0,
25-
"react-hooks/rules-of-hooks": 1,
26-
"react-hooks/exhaustive-deps": 1
27-
}
7+
ignorePatterns: ['node_modules/', 'coverage/', 'android/', 'ios/'],
288
};

.gitignore

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ DerivedData
2020
*.hmap
2121
*.ipa
2222
*.xcuserstate
23-
project.xcworkspace
2423

2524
# Android/IntelliJ
2625
#
@@ -30,21 +29,17 @@ build/
3029
local.properties
3130
*.iml
3231

33-
# Visual Studio Code
34-
#
35-
.vscode/
36-
3732
# node.js
3833
#
3934
node_modules/
4035
npm-debug.log
4136
yarn-error.log
4237

4338
# BUCK
44-
#
4539
buck-out/
4640
\.buckd/
4741
*.keystore
42+
!debug.keystore
4843

4944
# fastlane
5045
#
@@ -58,15 +53,10 @@ buck-out/
5853
*/fastlane/screenshots
5954

6055
# Bundle artifact
61-
#
6256
*.jsbundle
6357

6458
# CocoaPods
65-
#
6659
/ios/Pods/
6760

68-
69-
# Custom
70-
#
71-
coverage/
72-
build/
61+
.eslintcache
62+
coverage/

.prettierrc.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
bracketSpacing: false,
3+
jsxBracketSameLine: true,
4+
singleQuote: true,
5+
trailingComma: 'all',
6+
};

.vscode/settings.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"editor.formatOnSave": true,
3+
"editor.formatOnPaste": true,
4+
"editor.codeActionsOnSave": {"source.fixAll.eslint": true},
5+
"editor.gotoLocation.multipleImplementations": "goto"
6+
}

android/app/build.gradle

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ 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
*
21-
* // https://facebook.github.io/react-native/docs/performance#enable-the-ram-format
23+
* // https://reactnative.dev/docs/performance#enable-the-ram-format
2224
* bundleCommand: "ram-bundle",
2325
*
2426
* // whether to bundle JS and assets in debug mode
@@ -76,8 +78,7 @@ import com.android.build.OutputFile
7678
*/
7779

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

8384
apply from: "../../node_modules/react-native/react.gradle"
@@ -156,12 +157,13 @@ android {
156157
}
157158
release {
158159
// Caution! In production, you need to generate your own keystore file.
159-
// see https://facebook.github.io/react-native/docs/signed-apk-android.
160+
// see https://reactnative.dev/docs/signed-apk-android.
160161
signingConfig signingConfigs.debug
161162
minifyEnabled enableProguardInReleaseBuilds
162163
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
163164
}
164165
}
166+
165167
// applicationVariants are e.g. debug, release
166168
applicationVariants.all { variant ->
167169
variant.outputs.each { output ->
@@ -176,27 +178,33 @@ android {
176178

177179
}
178180
}
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-
}
188181
}
189182

190183
dependencies {
191184
implementation fileTree(dir: "libs", include: ["*.jar"])
185+
//noinspection GradleDynamicVersion
192186
implementation "com.facebook.react:react-native:+" // From node_modules
193187

188+
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
189+
190+
debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
191+
exclude group:'com.facebook.fbjni'
192+
}
193+
194+
debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
195+
exclude group:'com.facebook.flipper'
196+
}
197+
198+
debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
199+
exclude group:'com.facebook.flipper'
200+
}
201+
194202
if (enableHermes) {
195-
def hermesPath = "../../node_modules/hermesvm/android/";
196-
debugImplementation files(hermesPath + "hermes-debug.aar")
197-
releaseImplementation files(hermesPath + "hermes-release.aar")
203+
def hermesPath = "../../node_modules/hermes-engine/android/";
204+
debugImplementation files(hermesPath + "hermes-debug.aar")
205+
releaseImplementation files(hermesPath + "hermes-release.aar")
198206
} else {
199-
implementation jscFlavor
207+
implementation jscFlavor
200208
}
201209
}
202210

android/app/debug.keystore

2.2 KB
Binary file not shown.
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.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+
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+
}

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

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
public class MainActivity extends ReactActivity {
66

7-
/**
8-
* Returns the name of the main component registered from JavaScript.
9-
* This is used to schedule rendering of the component.
10-
*/
11-
@Override
12-
protected String getMainComponentName() {
13-
return "example";
14-
}
7+
/**
8+
* Returns the name of the main component registered from JavaScript. This is used to schedule
9+
* rendering of the component.
10+
*/
11+
@Override
12+
protected String getMainComponentName() {
13+
return "example";
14+
}
1515
}
Lines changed: 54 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,39 @@
11
package com.example;
22

33
import android.app.Application;
4-
import android.util.Log;
5-
4+
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;
13-
11+
import java.lang.reflect.InvocationTargetException;
1412
import java.util.List;
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,5 +44,37 @@ public ReactNativeHost getReactNativeHost() {
4544
public void onCreate() {
4645
super.onCreate();
4746
SoLoader.init(this, /* native exopackage */ false);
47+
initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
48+
}
49+
50+
/**
51+
* Loads Flipper in React Native templates. Call this in the onCreate method with something like
52+
* initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
53+
*
54+
* @param context
55+
* @param reactInstanceManager
56+
*/
57+
private static void initializeFlipper(
58+
Context context, ReactInstanceManager reactInstanceManager) {
59+
if (BuildConfig.DEBUG) {
60+
try {
61+
/*
62+
We use reflection here to pick up the class that initializes Flipper,
63+
since Flipper library is not available in release mode
64+
*/
65+
Class<?> aClass = Class.forName("com.example.ReactNativeFlipper");
66+
aClass
67+
.getMethod("initializeFlipper", Context.class, ReactInstanceManager.class)
68+
.invoke(null, context, reactInstanceManager);
69+
} catch (ClassNotFoundException e) {
70+
e.printStackTrace();
71+
} catch (NoSuchMethodException e) {
72+
e.printStackTrace();
73+
} catch (IllegalAccessException e) {
74+
e.printStackTrace();
75+
} catch (InvocationTargetException e) {
76+
e.printStackTrace();
77+
}
78+
}
4879
}
4980
}

0 commit comments

Comments
 (0)