Skip to content

Commit b53a2e8

Browse files
authored
chore: update to Android X and refactor example to React Native 0.61.x (callstack#103)
* chore: update to Android X and refactor all our example to use React Native 0.61.x * fix: do not ignore debug.keystore * feat: add commands to package.json
1 parent 97a37e6 commit b53a2e8

37 files changed

+1767
-1564
lines changed

.flowconfig

+38-28
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,42 @@
11
[ignore]
2-
; We fork some components by platform
3-
.*/node_modules/react-native/.*/*[.]android.js
2+
.*/node_modules/.*/*[.]android.js
43

54
; Ignore "BUCK" generated dirs
65
<PROJECT_ROOT>/\.buckd/
76

8-
; Ignore unexpected extra "@providesModule"
9-
.*/node_modules/.*/node_modules/fbjs/.*
10-
11-
; Ignore duplicate module providers
12-
; For RN Apps installed via npm, "Libraries" folder is inside
13-
; "node_modules/react-native" but in the source repo it is in the root
14-
.*/Libraries/react-native/React.js
15-
167
; Ignore polyfills
17-
.*/Libraries/polyfills/.*
8+
node_modules/react-native/Libraries/polyfills/.*
9+
10+
; These should not be required directly
11+
; require from fbjs/lib instead: require('fbjs/lib/warning')
12+
node_modules/warning/.*
13+
; Flow doesn't support platforms
14+
.*/Libraries/Utilities/LoadingView.js
1815

1916
; Ignore metro
2017
.*/node_modules/metro/.*
2118

19+
; Dependency of realm
20+
.*/node_modules/license-checker/.*
21+
2222
[include]
2323

2424
[libs]
2525
node_modules/react-native/Libraries/react-native/react-native-interface.js
2626
node_modules/react-native/flow/
27-
node_modules/react-native/flow-github/
27+
node_modules/react-navigation/flow/react-navigation.js
28+
flow-typed/.*
2829

2930
[options]
3031
emoji=true
3132

3233
esproposal.optional_chaining=enable
3334
esproposal.nullish_coalescing=enable
3435

35-
module.system=haste
36-
module.system.haste.use_name_reducers=true
37-
# get basename
38-
module.system.haste.name_reducers='^.*/\([a-zA-Z0-9$_.-]+\.js\(\.flow\)?\)$' -> '\1'
39-
# strip .js or .js.flow suffix
40-
module.system.haste.name_reducers='^\(.*\)\.js\(\.flow\)?$' -> '\1'
41-
# strip .ios suffix
42-
module.system.haste.name_reducers='^\(.*\)\.ios$' -> '\1'
43-
module.system.haste.name_reducers='^\(.*\)\.android$' -> '\1'
44-
module.system.haste.name_reducers='^\(.*\)\.native$' -> '\1'
45-
module.system.haste.paths.blacklist=.*/__tests__/.*
46-
module.system.haste.paths.blacklist=.*/__mocks__/.*
47-
module.system.haste.paths.blacklist=<PROJECT_ROOT>/node_modules/react-native/Libraries/Animated/src/polyfills/.*
48-
module.system.haste.paths.whitelist=<PROJECT_ROOT>/node_modules/react-native/Libraries/.*
49-
5036
munge_underscores=true
5137

38+
module.name_mapper='^react-native$' -> '<PROJECT_ROOT>/node_modules/react-native/Libraries/react-native/react-native-implementation'
39+
module.name_mapper='^react-native/\(.*\)$' -> '<PROJECT_ROOT>/node_modules/react-native/\1'
5240
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\)$' -> 'RelativeImageStub'
5341
# Support the library import in examples
5442
module.name_mapper='^\@react-native-community/viewpager$' -> '<PROJECT_ROOT>/js/index.js'
@@ -70,5 +58,27 @@ suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(<VERSION>\\)? *\\(site=[a-z,_]*
7058
suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy
7159
suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError
7260

61+
[lints]
62+
sketchy-null-number=warn
63+
sketchy-null-mixed=warn
64+
sketchy-number=warn
65+
# untyped-type-import=warn
66+
nonstrict-import=warn
67+
# deprecated-type=warn
68+
unsafe-getters-setters=warn
69+
# inexact-spread=warn
70+
unnecessary-invariant=warn
71+
signature-verification-failure=warn
72+
deprecated-utility=error
73+
74+
[strict]
75+
deprecated-type
76+
nonstrict-import
77+
sketchy-null
78+
unclear-type
79+
unsafe-getters-setters
80+
untyped-import
81+
untyped-type-import
82+
7383
[version]
74-
^0.86.0
84+
^0.105.0

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,6 @@ buck-out/
5454

5555
# Bundle artifact
5656
*.jsbundle
57+
58+
example/ios/Pods/
59+
!debug.keystore

android/gradle.properties

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
ReactNativeViewPager_compileSdkVersion=28
22
ReactNativeViewPager_buildToolsVersion=28.0.3
33
ReactNativeViewPager_targetSdkVersion=27
4-
ReactNativeViewPager_minSdkVersion=16
4+
ReactNativeViewPager_minSdkVersion=16
5+
6+
android.enableJetifier=true
7+
android.useAndroidX=true

android/src/main/java/com/reactnativecommunity/viewpager/ReactViewPager.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
package com.reactnativecommunity.viewpager;
99

10-
import android.support.v4.view.PagerAdapter;
11-
import android.support.v4.view.ViewPager;
10+
import androidx.viewpager.widget.PagerAdapter;
11+
import androidx.viewpager.widget.ViewPager;
1212
import android.view.MotionEvent;
1313
import android.view.View;
1414
import android.view.ViewGroup;

example/.gitignore

-56
This file was deleted.

example/ViewPagerExample.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ export default class ViewPagerExample extends React.Component<*, State> {
103103
renderPage(page: CreatePage) {
104104
return (
105105
<View key={page.key} style={page.style} collapsable={false}>
106+
{/* $FlowFixMe */}
106107
<Image style={styles.image} source={page.imgSource} />
107108
<LikeCount />
108109
</View>
@@ -127,7 +128,7 @@ export default class ViewPagerExample extends React.Component<*, State> {
127128
transitionStyle="scroll"
128129
showPageIndicator
129130
ref={this.viewPager}>
130-
{pages.map(page => this.renderPage(page))}
131+
{pages.map(p => this.renderPage(p))}
131132
</ViewPager>
132133
<View style={styles.buttons}>
133134
<Button
File renamed without changes.

example/android/app/build.gradle

+62-6
Original file line numberDiff line numberDiff line change
@@ -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,7 +76,8 @@ import com.android.build.OutputFile
7376
*/
7477

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

7983
apply from: "../../../node_modules/react-native/react.gradle"
@@ -93,9 +97,36 @@ 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

125+
compileOptions {
126+
sourceCompatibility JavaVersion.VERSION_1_8
127+
targetCompatibility JavaVersion.VERSION_1_8
128+
}
129+
99130
defaultConfig {
100131
applicationId "com.reactnativecommunity.viewpager.example"
101132
minSdkVersion rootProject.ext.minSdkVersion
@@ -108,11 +139,25 @@ android {
108139
reset()
109140
enable enableSeparateBuildPerCPUArchitecture
110141
universalApk false // If true, also generate a universal APK
111-
include "armeabi-v7a", "x86", "arm64-v8a"
142+
include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
143+
}
144+
}
145+
signingConfigs {
146+
debug {
147+
storeFile file('debug.keystore')
148+
storePassword 'android'
149+
keyAlias 'androiddebugkey'
150+
keyPassword 'android'
112151
}
113152
}
114153
buildTypes {
154+
debug {
155+
signingConfig signingConfigs.debug
156+
}
115157
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
116161
minifyEnabled enableProguardInReleaseBuilds
117162
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
118163
}
@@ -121,23 +166,31 @@ android {
121166
applicationVariants.all { variant ->
122167
variant.outputs.each { output ->
123168
// For each separate APK per architecture, set a unique version code as described here:
124-
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
125-
def versionCodes = ["armeabi-v7a":1, "x86":2, "arm64-v8a": 3]
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]
126171
def abi = output.getFilter(OutputFile.ABI)
127172
if (abi != null) { // null for the universal-debug, universal-release variants
128173
output.versionCodeOverride =
129174
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
130175
}
176+
131177
}
132178
}
133179
}
134180

135181
dependencies {
136182
implementation fileTree(dir: "libs", include: ["*.jar"])
137-
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
138-
//noinspection GradleDynamicVersion
183+
implementation "androidx.appcompat:appcompat:${rootProject.ext.appCompatVersion}"
139184
implementation "com.facebook.react:react-native:+" // From node_modules
140185
implementation project(':react-native-viewpager')
186+
187+
if (enableHermes) {
188+
def hermesPath = "../../../node_modules/hermes-engine/android/";
189+
debugImplementation files(hermesPath + "hermes-debug.aar")
190+
releaseImplementation files(hermesPath + "hermes-release.aar")
191+
} else {
192+
implementation jscFlavor
193+
}
141194
}
142195

143196
// Run this once to be able to run the application with BUCK
@@ -146,3 +199,6 @@ task copyDownloadableDepsToLibs(type: Copy) {
146199
from configurations.compile
147200
into 'libs'
148201
}
202+
203+
204+
apply from: file("../../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)

example/android/app/debug.keystore

2.2 KB
Binary file not shown.

example/android/app/proguard-rules.pro

-7
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-
#}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools">
4+
5+
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
6+
7+
<application android:usesCleartextTraffic="true" tools:targetApi="28" tools:ignore="GoogleAppIndexingWarning" />
8+
</manifest>

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

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
package="com.reactnativecommunity.viewpager.example">
33

44
<uses-permission android:name="android.permission.INTERNET" />
5-
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
65

76
<application
87
android:name="com.reactnativecommunity.viewpager.example.MainApplication"

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

+8-8
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 "ViewPagerExample";
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 "ViewPagerExample";
14+
}
1515
}

0 commit comments

Comments
 (0)