Skip to content

Commit 3dd6cab

Browse files
committed
chore: update rn version of example
1 parent 415ef7c commit 3dd6cab

File tree

19 files changed

+1410
-0
lines changed

19 files changed

+1410
-0
lines changed

example/.flowconfig

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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+
; Flow doesn't support platforms
12+
.*/Libraries/Utilities/LoadingView.js
13+
14+
[untyped]
15+
.*/node_modules/@react-native-community/cli/.*/.*
16+
17+
[include]
18+
19+
[libs]
20+
node_modules/react-native/interface.js
21+
node_modules/react-native/flow/
22+
23+
[options]
24+
emoji=true
25+
26+
esproposal.optional_chaining=enable
27+
esproposal.nullish_coalescing=enable
28+
29+
exact_by_default=true
30+
31+
module.file_ext=.js
32+
module.file_ext=.json
33+
module.file_ext=.ios.js
34+
35+
munge_underscores=true
36+
37+
module.name_mapper='^react-native/\(.*\)$' -> '<PROJECT_ROOT>/node_modules/react-native/\1'
38+
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'
39+
40+
suppress_type=$FlowIssue
41+
suppress_type=$FlowFixMe
42+
suppress_type=$FlowFixMeProps
43+
suppress_type=$FlowFixMeState
44+
45+
[lints]
46+
sketchy-null-number=warn
47+
sketchy-null-mixed=warn
48+
sketchy-number=warn
49+
untyped-type-import=warn
50+
nonstrict-import=warn
51+
deprecated-type=warn
52+
unsafe-getters-setters=warn
53+
unnecessary-invariant=warn
54+
signature-verification-failure=warn
55+
56+
[strict]
57+
deprecated-type
58+
nonstrict-import
59+
sketchy-null
60+
unclear-type
61+
unsafe-getters-setters
62+
untyped-import
63+
untyped-type-import
64+
65+
[version]
66+
^0.137.0

example/_editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Windows files
2+
[*.bat]
3+
end_of_line = crlf

example/android/app/_BUCK

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# To learn about Buck see [Docs](https://buckbuild.com/).
2+
# To run your application with Buck:
3+
# - install Buck
4+
# - `npm start` - to start the packager
5+
# - `cd android`
6+
# - `keytool -genkey -v -keystore keystores/debug.keystore -storepass android -alias androiddebugkey -keypass android -dname "CN=Android Debug,O=Android,C=US"`
7+
# - `./gradlew :app:copyDownloadableDepsToLibs` - make all Gradle compile dependencies available to Buck
8+
# - `buck install -r android/app` - compile, install and run application
9+
#
10+
11+
load(":build_defs.bzl", "create_aar_targets", "create_jar_targets")
12+
13+
lib_deps = []
14+
15+
create_aar_targets(glob(["libs/*.aar"]))
16+
17+
create_jar_targets(glob(["libs/*.jar"]))
18+
19+
android_library(
20+
name = "all-libs",
21+
exported_deps = lib_deps,
22+
)
23+
24+
android_library(
25+
name = "app-code",
26+
srcs = glob([
27+
"src/main/java/**/*.java",
28+
]),
29+
deps = [
30+
":all-libs",
31+
":build_config",
32+
":res",
33+
],
34+
)
35+
36+
android_build_config(
37+
name = "build_config",
38+
package = "com.example",
39+
)
40+
41+
android_resource(
42+
name = "res",
43+
package = "com.example",
44+
res = "src/main/res",
45+
)
46+
47+
android_binary(
48+
name = "app",
49+
keystore = "//android/keystores:debug",
50+
manifest = "src/main/AndroidManifest.xml",
51+
package_type = "debug",
52+
deps = [
53+
":app-code",
54+
],
55+
)
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+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.example;
2+
3+
import com.facebook.react.ReactActivity;
4+
5+
public class MainActivity extends ReactActivity {
6+
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+
}
15+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package com.example;
2+
3+
import android.app.Application;
4+
import android.content.Context;
5+
import com.facebook.react.PackageList;
6+
import com.facebook.react.ReactApplication;
7+
import com.facebook.react.ReactInstanceManager;
8+
import com.facebook.react.ReactNativeHost;
9+
import com.facebook.react.ReactPackage;
10+
import com.facebook.soloader.SoLoader;
11+
import com.reactnativecommunity.progressview.RNCProgressViewPackage;
12+
import java.lang.reflect.InvocationTargetException;
13+
import java.util.List;
14+
15+
16+
public class MainApplication extends Application implements ReactApplication {
17+
18+
private final ReactNativeHost mReactNativeHost =
19+
new ReactNativeHost(this) {
20+
@Override
21+
public boolean getUseDeveloperSupport() {
22+
return BuildConfig.DEBUG;
23+
}
24+
25+
@Override
26+
protected List<ReactPackage> getPackages() {
27+
@SuppressWarnings("UnnecessaryLocalVariable")
28+
List<ReactPackage> packages = new PackageList(this).getPackages();
29+
// Packages that cannot be autolinked yet can be added manually here, for example:
30+
// packages.add(new MyReactNativePackage());
31+
packages.add(new RNCProgressViewPackage());
32+
return packages;
33+
}
34+
35+
@Override
36+
protected String getJSMainModuleName() {
37+
return "index";
38+
}
39+
};
40+
41+
@Override
42+
public ReactNativeHost getReactNativeHost() {
43+
return mReactNativeHost;
44+
}
45+
46+
@Override
47+
public void onCreate() {
48+
super.onCreate();
49+
SoLoader.init(this, /* native exopackage */ false);
50+
initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
51+
}
52+
53+
/**
54+
* Loads Flipper in React Native templates. Call this in the onCreate method with something like
55+
* initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
56+
*
57+
* @param context
58+
* @param reactInstanceManager
59+
*/
60+
private static void initializeFlipper(
61+
Context context, ReactInstanceManager reactInstanceManager) {
62+
if (BuildConfig.DEBUG) {
63+
try {
64+
/*
65+
We use reflection here to pick up the class that initializes Flipper,
66+
since Flipper library is not available in release mode
67+
*/
68+
Class<?> aClass = Class.forName("com.example.ReactNativeFlipper");
69+
aClass
70+
.getMethod("initializeFlipper", Context.class, ReactInstanceManager.class)
71+
.invoke(null, context, reactInstanceManager);
72+
} catch (ClassNotFoundException e) {
73+
e.printStackTrace();
74+
} catch (NoSuchMethodException e) {
75+
e.printStackTrace();
76+
} catch (IllegalAccessException e) {
77+
e.printStackTrace();
78+
} catch (InvocationTargetException e) {
79+
e.printStackTrace();
80+
}
81+
}
82+
}
83+
}

0 commit comments

Comments
 (0)