Skip to content

Commit af56551

Browse files
committed
example project on rn 62.2
1 parent 0918935 commit af56551

37 files changed

+9200
-511
lines changed

Example/.eslintrc.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
root: true,
3+
extends: '@react-native-community',
4+
};

Example/.flowconfig

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
[ignore]
2+
; We fork some components by platform
3+
.*/*[.]android.js
4+
5+
; Ignore "BUCK" generated dirs
6+
<PROJECT_ROOT>/\.buckd/
7+
8+
; Ignore polyfills
9+
node_modules/react-native/Libraries/polyfills/.*
10+
11+
; These should not be required directly
12+
; require from fbjs/lib instead: require('fbjs/lib/warning')
13+
node_modules/warning/.*
14+
15+
; Flow doesn't support platforms
16+
.*/Libraries/Utilities/LoadingView.js
17+
18+
[untyped]
19+
.*/node_modules/@react-native-community/cli/.*/.*
20+
21+
[include]
22+
23+
[libs]
24+
node_modules/react-native/interface.js
25+
node_modules/react-native/flow/
26+
27+
[options]
28+
emoji=true
29+
30+
esproposal.optional_chaining=enable
31+
esproposal.nullish_coalescing=enable
32+
33+
module.file_ext=.js
34+
module.file_ext=.json
35+
module.file_ext=.ios.js
36+
37+
munge_underscores=true
38+
39+
module.name_mapper='^react-native/\(.*\)$' -> '<PROJECT_ROOT>/node_modules/react-native/\1'
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'
41+
42+
suppress_type=$FlowIssue
43+
suppress_type=$FlowFixMe
44+
suppress_type=$FlowFixMeProps
45+
suppress_type=$FlowFixMeState
46+
47+
suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native\\(_ios\\)?_\\(oss\\|fb\\)[a-z,_]*\\)?)\\)
48+
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native\\(_ios\\)?_\\(oss\\|fb\\)[a-z,_]*\\)?)\\)?:? #[0-9]+
49+
suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError
50+
51+
[lints]
52+
sketchy-null-number=warn
53+
sketchy-null-mixed=warn
54+
sketchy-number=warn
55+
untyped-type-import=warn
56+
nonstrict-import=warn
57+
deprecated-type=warn
58+
unsafe-getters-setters=warn
59+
inexact-spread=warn
60+
unnecessary-invariant=warn
61+
signature-verification-failure=warn
62+
deprecated-utility=error
63+
64+
[strict]
65+
deprecated-type
66+
nonstrict-import
67+
sketchy-null
68+
unclear-type
69+
unsafe-getters-setters
70+
untyped-import
71+
untyped-type-import
72+
73+
[version]
74+
^0.113.0

Example/.prettierrc.js

+6
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+
};

Example/__tests__/App-test.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* @format
3+
*/
4+
5+
import 'react-native';
6+
import React from 'react';
7+
import App from '../App';
8+
9+
// Note: test renderer must be required after react-native.
10+
import renderer from 'react-test-renderer';
11+
12+
it('renders correctly', () => {
13+
renderer.create(<App />);
14+
});

Example/android/app/BUCK Example/android/app/_BUCK

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ android_library(
3535

3636
android_build_config(
3737
name = "build_config",
38-
package = "com.rnappauthexample",
38+
package = "com.example",
3939
)
4040

4141
android_resource(
4242
name = "res",
43-
package = "com.rnappauthexample",
43+
package = "com.example",
4444
res = "src/main/res",
4545
)
4646

Example/android/app/build.gradle

+27-3
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

@@ -128,7 +129,7 @@ android {
128129
}
129130

130131
defaultConfig {
131-
applicationId "com.rnappauthexample"
132+
applicationId "com.example"
132133
minSdkVersion rootProject.ext.minSdkVersion
133134
targetSdkVersion rootProject.ext.targetSdkVersion
134135
versionCode 1
@@ -165,6 +166,14 @@ android {
165166
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
166167
}
167168
}
169+
170+
packagingOptions {
171+
pickFirst "lib/armeabi-v7a/libc++_shared.so"
172+
pickFirst "lib/arm64-v8a/libc++_shared.so"
173+
pickFirst "lib/x86/libc++_shared.so"
174+
pickFirst "lib/x86_64/libc++_shared.so"
175+
}
176+
168177
// applicationVariants are e.g. debug, release
169178
applicationVariants.all { variant ->
170179
variant.outputs.each { output ->
@@ -183,8 +192,23 @@ android {
183192

184193
dependencies {
185194
implementation fileTree(dir: "libs", include: ["*.jar"])
195+
//noinspection GradleDynamicVersion
186196
implementation "com.facebook.react:react-native:+" // From node_modules
187197

198+
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
199+
200+
debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
201+
exclude group:'com.facebook.fbjni'
202+
}
203+
204+
debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
205+
exclude group:'com.facebook.flipper'
206+
}
207+
208+
debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
209+
exclude group:'com.facebook.flipper'
210+
}
211+
188212
if (enableHermes) {
189213
def hermesPath = "../../node_modules/hermes-engine/android/";
190214
debugImplementation files(hermesPath + "hermes-debug.aar")
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+
}

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
package="com.rnappauthexample">
2+
package="com.example">
33

44
<uses-permission android:name="android.permission.INTERNET" />
55

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

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.rnappauthexample;
1+
package com.example;
22

33
import com.facebook.react.ReactActivity;
44

@@ -10,6 +10,6 @@ public class MainActivity extends ReactActivity {
1010
*/
1111
@Override
1212
protected String getMainComponentName() {
13-
return "RNAppAuthExample";
13+
return "Example";
1414
}
1515
}

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

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
package com.rnappauthexample;
1+
package com.example;
22

33
import android.app.Application;
44
import android.content.Context;
55
import com.facebook.react.PackageList;
66
import com.facebook.react.ReactApplication;
7+
import com.facebook.react.ReactInstanceManager;
78
import com.facebook.react.ReactNativeHost;
89
import com.facebook.react.ReactPackage;
910
import com.facebook.soloader.SoLoader;
@@ -43,23 +44,28 @@ public ReactNativeHost getReactNativeHost() {
4344
public void onCreate() {
4445
super.onCreate();
4546
SoLoader.init(this, /* native exopackage */ false);
46-
initializeFlipper(this); // Remove this line if you don't want Flipper enabled
47+
initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
4748
}
4849

4950
/**
50-
* 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());
5153
*
5254
* @param context
55+
* @param reactInstanceManager
5356
*/
54-
private static void initializeFlipper(Context context) {
57+
private static void initializeFlipper(
58+
Context context, ReactInstanceManager reactInstanceManager) {
5559
if (BuildConfig.DEBUG) {
5660
try {
5761
/*
5862
We use reflection here to pick up the class that initializes Flipper,
5963
since Flipper library is not available in release mode
6064
*/
61-
Class<?> aClass = Class.forName("com.facebook.flipper.ReactNativeFlipper");
62-
aClass.getMethod("initializeFlipper", Context.class).invoke(null, context);
65+
Class<?> aClass = Class.forName("com.example.ReactNativeFlipper");
66+
aClass
67+
.getMethod("initializeFlipper", Context.class, ReactInstanceManager.class)
68+
.invoke(null, context, reactInstanceManager);
6369
} catch (ClassNotFoundException e) {
6470
e.printStackTrace();
6571
} catch (NoSuchMethodException e) {
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<resources>
2-
<string name="app_name">RNAppAuthExample</string>
2+
<string name="app_name">Example</string>
33
</resources>

Example/android/build.gradle

+2-2
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
}

Example/android/gradle.properties

+7
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,12 @@
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+
27+
# Version of flipper SDK to use with React Native
28+
FLIPPER_VERSION=0.33.1
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

Example/android/gradlew

+3-3
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,8 +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
128+
# For Cygwin or MSYS, switch paths to Windows format before running java
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)