Skip to content

Commit 4cffb82

Browse files
committed
chore: update example
1 parent 87bda71 commit 4cffb82

23 files changed

+891
-2205
lines changed

example/ProgressBarAndroidExample.android.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010

1111
'use strict';
1212

13-
var ProgressBar = require('../js/RNCProgressBarAndroid.android');
14-
var React = require('react');
15-
var createReactClass = require('create-react-class');
16-
var RNTesterBlock = require('./RNTesterBlock');
17-
var RNTesterPage = require('./RNTesterPage');
13+
import {ProgressBar} from '@react-native-community/progress-bar-android';
14+
import React from 'react';
15+
import createReactClass from 'create-react-class';
16+
import RNTesterBlock from './RNTesterBlock';
17+
import RNTesterPage from './RNTesterPage';
1818

19-
var TimerMixin = require('react-timer-mixin');
19+
import TimerMixin from 'react-timer-mixin';
2020

21-
var MovingBar = createReactClass({
21+
const MovingBar = createReactClass({
2222
displayName: 'MovingBar',
2323
mixins: [TimerMixin],
2424

example/RNTesterBlock.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@
1010

1111
'use strict';
1212

13-
var React = require('react');
14-
var PropTypes = require('prop-types');
15-
var ReactNative = require('react-native');
16-
var {StyleSheet, Text, View} = ReactNative;
13+
import React from 'react';
14+
import PropTypes from 'prop-types';
15+
import {StyleSheet, Text, View} from 'react-native';
1716

1817
class RNTesterBlock extends React.Component<
1918
{
@@ -95,4 +94,4 @@ var styles = StyleSheet.create({
9594
},
9695
});
9796

98-
module.exports = RNTesterBlock;
97+
export default RNTesterBlock;

example/RNTesterPage.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@
1010

1111
'use strict';
1212

13-
var PropTypes = require('prop-types');
14-
var React = require('react');
15-
var ReactNative = require('react-native');
16-
var {ScrollView, StyleSheet, View} = ReactNative;
13+
import React from 'react';
14+
import PropTypes from 'prop-types';
15+
import {ScrollView, StyleSheet, View} from 'react-native';
1716

18-
var RNTesterTitle = require('./RNTesterTitle');
17+
import RNTesterTitle from './RNTesterTitle';
1918

2019
class RNTesterPage extends React.Component<{
2120
noScroll?: boolean,
@@ -74,4 +73,4 @@ var styles = StyleSheet.create({
7473
},
7574
});
7675

77-
module.exports = RNTesterPage;
76+
export default RNTesterPage;

example/RNTesterTitle.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@
1010

1111
'use strict';
1212

13-
var React = require('react');
14-
var ReactNative = require('react-native');
15-
var {StyleSheet, Text, View} = ReactNative;
13+
import React from 'react';
14+
import {StyleSheet, Text, View} from 'react-native';
1615

1716
class RNTesterTitle extends React.Component<$FlowFixMeProps> {
1817
render() {
@@ -41,4 +40,4 @@ var styles = StyleSheet.create({
4140
},
4241
});
4342

44-
module.exports = RNTesterTitle;
43+
export default RNTesterTitle;

example/android/app/.classpath

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<classpath>
3-
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-12/"/>
3+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/>
44
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
55
<classpathentry kind="output" path="bin/default"/>
66
</classpath>
File renamed without changes.

example/android/app/build.gradle

100644100755
Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import com.android.build.OutputFile
99
* cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
1010
* bundle directly from the development server. Below you can see all the possible configurations
1111
* and their defaults. If you decide to add a configuration block, make sure to add it before the
12-
* `apply from: "../../../node_modules/react-native/react.gradle"` line.
12+
* `apply from: "../../node_modules/react-native/react.gradle"` line.
1313
*
1414
* project.ext.react = [
1515
* // the name of the generated asset file containing your JS bundle
@@ -18,6 +18,9 @@ import com.android.build.OutputFile
1818
* // the entry file for bundle generation
1919
* entryFile: "index.android.js",
2020
*
21+
* // https://facebook.github.io/react-native/docs/performance#enable-the-ram-format
22+
* bundleCommand: "ram-bundle",
23+
*
2124
* // whether to bundle JS and assets in debug mode
2225
* bundleInDebug: false,
2326
*
@@ -73,10 +76,11 @@ import com.android.build.OutputFile
7376
*/
7477

7578
project.ext.react = [
76-
entryFile: "index.js"
79+
entryFile: "index.js",
80+
enableHermes: false, // clean and rebuild if changing
7781
]
7882

79-
apply from: "../../../node_modules/react-native/react.gradle"
83+
apply from: "../../node_modules/react-native/react.gradle"
8084

8185
/**
8286
* Set this to true to create two separate APKs instead of one:
@@ -93,6 +97,28 @@ def enableSeparateBuildPerCPUArchitecture = false
9397
*/
9498
def enableProguardInReleaseBuilds = false
9599

100+
/**
101+
* The preferred build flavor of JavaScriptCore.
102+
*
103+
* For example, to use the international variant, you can use:
104+
* `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
105+
*
106+
* The international variant includes ICU i18n library and necessary data
107+
* allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
108+
* give correct results when using with locales other than en-US. Note that
109+
* this variant is about 6MiB larger per architecture than default.
110+
*/
111+
def jscFlavor = 'org.webkit:android-jsc:+'
112+
113+
/**
114+
* Whether to enable the Hermes VM.
115+
*
116+
* This should be set on project.ext.react and mirrored here. If it is not set
117+
* on project.ext.react, JavaScript will not be compiled to Hermes Bytecode
118+
* and the benefits of using Hermes will therefore be sharply reduced.
119+
*/
120+
def enableHermes = project.ext.react.get("enableHermes", false);
121+
96122
android {
97123
compileSdkVersion rootProject.ext.compileSdkVersion
98124

@@ -116,8 +142,22 @@ android {
116142
include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
117143
}
118144
}
145+
signingConfigs {
146+
debug {
147+
storeFile file('debug.keystore')
148+
storePassword 'android'
149+
keyAlias 'androiddebugkey'
150+
keyPassword 'android'
151+
}
152+
}
119153
buildTypes {
154+
debug {
155+
signingConfig signingConfigs.debug
156+
}
120157
release {
158+
// Caution! In production, you need to generate your own keystore file.
159+
// see https://facebook.github.io/react-native/docs/signed-apk-android.
160+
signingConfig signingConfigs.debug
121161
minifyEnabled enableProguardInReleaseBuilds
122162
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
123163
}
@@ -126,21 +166,29 @@ android {
126166
applicationVariants.all { variant ->
127167
variant.outputs.each { output ->
128168
// For each separate APK per architecture, set a unique version code as described here:
129-
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
130-
def versionCodes = ["armeabi-v7a":1, "x86":2, "arm64-v8a": 3, "x86_64": 4]
169+
// https://developer.android.com/studio/build/configure-apk-splits.html
170+
def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
131171
def abi = output.getFilter(OutputFile.ABI)
132172
if (abi != null) { // null for the universal-debug, universal-release variants
133173
output.versionCodeOverride =
134174
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
135175
}
176+
136177
}
137178
}
138179
}
139180

140181
dependencies {
141182
implementation fileTree(dir: "libs", include: ["*.jar"])
142-
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
143183
implementation "com.facebook.react:react-native:+" // From node_modules
184+
185+
if (enableHermes) {
186+
def hermesPath = "../../node_modules/hermes-engine/android/";
187+
debugImplementation files(hermesPath + "hermes-debug.aar")
188+
releaseImplementation files(hermesPath + "hermes-release.aar")
189+
} else {
190+
implementation jscFlavor
191+
}
144192
}
145193

146194
// Run this once to be able to run the application with BUCK
@@ -149,3 +197,5 @@ task copyDownloadableDepsToLibs(type: Copy) {
149197
from configurations.compile
150198
into 'libs'
151199
}
200+
201+
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)

example/android/app/proguard-rules.pro

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,3 @@
88
# http://developer.android.com/guide/developing/tools/proguard.html
99

1010
# Add any project specific keep options here:
11-
12-
# If your project uses WebView with JS, uncomment the following
13-
# and specify the fully qualified class name to the JavaScript interface
14-
# class:
15-
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16-
# public *;
17-
#}

example/android/app/src/main/java/com/androidprogressbar/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 "AndroidProgressBarExample";
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 "AndroidProgressBarExample";
14+
}
1515
}
Lines changed: 49 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,38 @@
11
package com.androidprogressbar;
22

33
import android.app.Application;
4-
4+
import android.content.Context;
5+
import com.facebook.react.PackageList;
56
import com.facebook.react.ReactApplication;
67
import com.facebook.react.ReactNativeHost;
78
import com.facebook.react.ReactPackage;
8-
import com.facebook.react.shell.MainReactPackage;
99
import com.facebook.soloader.SoLoader;
10-
11-
import java.util.Arrays;
10+
import java.lang.reflect.InvocationTargetException;
1211
import java.util.List;
1312

1413
public class MainApplication extends Application implements ReactApplication {
1514

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

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

29-
@Override
30-
protected String getJSMainModuleName() {
31-
return "example/index";
32-
}
33-
};
31+
@Override
32+
protected String getJSMainModuleName() {
33+
return "index";
34+
}
35+
};
3436

3537
@Override
3638
public ReactNativeHost getReactNativeHost() {
@@ -41,5 +43,32 @@ public ReactNativeHost getReactNativeHost() {
4143
public void onCreate() {
4244
super.onCreate();
4345
SoLoader.init(this, /* native exopackage */ false);
46+
initializeFlipper(this); // Remove this line if you don't want Flipper enabled
47+
}
48+
49+
/**
50+
* Loads Flipper in React Native templates.
51+
*
52+
* @param context
53+
*/
54+
private static void initializeFlipper(Context context) {
55+
if (BuildConfig.DEBUG) {
56+
try {
57+
/*
58+
We use reflection here to pick up the class that initializes Flipper,
59+
since Flipper library is not available in release mode
60+
*/
61+
Class<?> aClass = Class.forName("com.facebook.flipper.ReactNativeFlipper");
62+
aClass.getMethod("initializeFlipper", Context.class).invoke(null, context);
63+
} catch (ClassNotFoundException e) {
64+
e.printStackTrace();
65+
} catch (NoSuchMethodException e) {
66+
e.printStackTrace();
67+
} catch (IllegalAccessException e) {
68+
e.printStackTrace();
69+
} catch (InvocationTargetException e) {
70+
e.printStackTrace();
71+
}
72+
}
4473
}
4574
}

0 commit comments

Comments
 (0)