Skip to content

Commit 259f505

Browse files
committed
added a new example to show case react-native 20
1 parent f116c8d commit 259f505

File tree

35 files changed

+2069
-0
lines changed

35 files changed

+2069
-0
lines changed

examples/SampleRN20/.flowconfig

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
[ignore]
2+
3+
# We fork some components by platform.
4+
.*/*.web.js
5+
.*/*.android.js
6+
7+
# Some modules have their own node_modules with overlap
8+
.*/node_modules/node-haste/.*
9+
10+
# Ugh
11+
.*/node_modules/babel.*
12+
.*/node_modules/babylon.*
13+
.*/node_modules/invariant.*
14+
15+
# Ignore react and fbjs where there are overlaps, but don't ignore
16+
# anything that react-native relies on
17+
.*/node_modules/fbjs/lib/Map.js
18+
.*/node_modules/fbjs/lib/Promise.js
19+
.*/node_modules/fbjs/lib/fetch.js
20+
.*/node_modules/fbjs/lib/ExecutionEnvironment.js
21+
.*/node_modules/fbjs/lib/isEmpty.js
22+
.*/node_modules/fbjs/lib/crc32.js
23+
.*/node_modules/fbjs/lib/ErrorUtils.js
24+
25+
# Flow has a built-in definition for the 'react' module which we prefer to use
26+
# over the currently-untyped source
27+
.*/node_modules/react/react.js
28+
.*/node_modules/react/lib/React.js
29+
.*/node_modules/react/lib/ReactDOM.js
30+
31+
# Ignore commoner tests
32+
.*/node_modules/commoner/test/.*
33+
34+
# See https://github.com/facebook/flow/issues/442
35+
.*/react-tools/node_modules/commoner/lib/reader.js
36+
37+
# Ignore jest
38+
.*/node_modules/jest-cli/.*
39+
40+
# Ignore Website
41+
.*/website/.*
42+
43+
[include]
44+
45+
[libs]
46+
node_modules/react-native/Libraries/react-native/react-native-interface.js
47+
48+
[options]
49+
module.system=haste
50+
51+
munge_underscores=true
52+
53+
module.name_mapper='^image![a-zA-Z0-9$_-]+$' -> 'GlobalImageStub'
54+
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\)$' -> 'RelativeImageStub'
55+
56+
suppress_type=$FlowIssue
57+
suppress_type=$FlowFixMe
58+
suppress_type=$FixMe
59+
60+
suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(2[0-1]\\|1[0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)
61+
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(2[0-1]\\|1[0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+
62+
suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy
63+
64+
[version]
65+
0.21.0

examples/SampleRN20/.gitignore

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# OSX
2+
#
3+
.DS_Store
4+
5+
# Xcode
6+
#
7+
build/
8+
*.pbxuser
9+
!default.pbxuser
10+
*.mode1v3
11+
!default.mode1v3
12+
*.mode2v3
13+
!default.mode2v3
14+
*.perspectivev3
15+
!default.perspectivev3
16+
xcuserdata
17+
*.xccheckout
18+
*.moved-aside
19+
DerivedData
20+
*.hmap
21+
*.ipa
22+
*.xcuserstate
23+
project.xcworkspace
24+
25+
# Android/IJ
26+
#
27+
.idea
28+
.gradle
29+
local.properties
30+
31+
# node.js
32+
#
33+
node_modules/
34+
npm-debug.log

examples/SampleRN20/.watchmanconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
apply plugin: "com.android.application"
2+
3+
import com.android.build.OutputFile
4+
5+
/**
6+
* The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
7+
* and bundleReleaseJsAndAssets).
8+
* These basically call `react-native bundle` with the correct arguments during the Android build
9+
* cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
10+
* bundle directly from the development server. Below you can see all the possible configurations
11+
* and their defaults. If you decide to add a configuration block, make sure to add it before the
12+
* `apply from: "react.gradle"` line.
13+
*
14+
* project.ext.react = [
15+
* // the name of the generated asset file containing your JS bundle
16+
* bundleAssetName: "index.android.bundle",
17+
*
18+
* // the entry file for bundle generation
19+
* entryFile: "index.android.js",
20+
*
21+
* // whether to bundle JS and assets in debug mode
22+
* bundleInDebug: false,
23+
*
24+
* // whether to bundle JS and assets in release mode
25+
* bundleInRelease: true,
26+
*
27+
* // whether to bundle JS and assets in another build variant (if configured).
28+
* // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
29+
* // The configuration property is in the format 'bundleIn${productFlavor}${buildType}'
30+
* // bundleInFreeDebug: true,
31+
* // bundleInPaidRelease: true,
32+
* // bundleInBeta: true,
33+
*
34+
* // the root of your project, i.e. where "package.json" lives
35+
* root: "../../",
36+
*
37+
* // where to put the JS bundle asset in debug mode
38+
* jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
39+
*
40+
* // where to put the JS bundle asset in release mode
41+
* jsBundleDirRelease: "$buildDir/intermediates/assets/release",
42+
*
43+
* // where to put drawable resources / React Native assets, e.g. the ones you use via
44+
* // require('./image.png')), in debug mode
45+
* resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
46+
*
47+
* // where to put drawable resources / React Native assets, e.g. the ones you use via
48+
* // require('./image.png')), in release mode
49+
* resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
50+
*
51+
* // by default the gradle tasks are skipped if none of the JS files or assets change; this means
52+
* // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
53+
* // date; if you have any other folders that you want to ignore for performance reasons (gradle
54+
* // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
55+
* // for example, you might want to remove it from here.
56+
* inputExcludes: ["android/**", "ios/**"]
57+
* ]
58+
*/
59+
60+
apply from: "react.gradle"
61+
62+
/**
63+
* Set this to true to create three separate APKs instead of one:
64+
* - A universal APK that works on all devices
65+
* - An APK that only works on ARM devices
66+
* - An APK that only works on x86 devices
67+
* The advantage is the size of the APK is reduced by about 4MB.
68+
* Upload all the APKs to the Play Store and people will download
69+
* the correct one based on the CPU architecture of their device.
70+
*/
71+
def enableSeparateBuildPerCPUArchitecture = false
72+
73+
/**
74+
* Run Proguard to shrink the Java bytecode in release builds.
75+
*/
76+
def enableProguardInReleaseBuilds = false
77+
78+
android {
79+
compileSdkVersion 23
80+
buildToolsVersion "23.0.1"
81+
82+
defaultConfig {
83+
applicationId "com.samplern20"
84+
minSdkVersion 16
85+
targetSdkVersion 22
86+
versionCode 1
87+
versionName "1.0"
88+
ndk {
89+
abiFilters "armeabi-v7a", "x86"
90+
}
91+
}
92+
splits {
93+
abi {
94+
enable enableSeparateBuildPerCPUArchitecture
95+
universalApk false
96+
reset()
97+
include "armeabi-v7a", "x86"
98+
}
99+
}
100+
buildTypes {
101+
release {
102+
minifyEnabled enableProguardInReleaseBuilds
103+
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
104+
}
105+
}
106+
// applicationVariants are e.g. debug, release
107+
applicationVariants.all { variant ->
108+
variant.outputs.each { output ->
109+
// For each separate APK per architecture, set a unique version code as described here:
110+
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
111+
def versionCodes = ["armeabi-v7a":1, "x86":2]
112+
def abi = output.getFilter(OutputFile.ABI)
113+
if (abi != null) { // null for the universal-debug, universal-release variants
114+
output.versionCodeOverride =
115+
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
116+
}
117+
}
118+
}
119+
}
120+
121+
dependencies {
122+
compile fileTree(dir: "libs", include: ["*.jar"])
123+
compile "com.android.support:appcompat-v7:23.0.1"
124+
compile "com.facebook.react:react-native:0.20.+"
125+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# 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+
#}
18+
19+
# Disabling obfuscation is useful if you collect stack traces from production crashes
20+
# (unless you are using a system that supports de-obfuscate the stack traces).
21+
-dontobfuscate
22+
23+
# React Native
24+
25+
# Keep our interfaces so they can be used by other ProGuard rules.
26+
# See http://sourceforge.net/p/proguard/bugs/466/
27+
-keep,allowobfuscation @interface com.facebook.proguard.annotations.DoNotStrip
28+
-keep,allowobfuscation @interface com.facebook.proguard.annotations.KeepGettersAndSetters
29+
30+
# Do not strip any method/class that is annotated with @DoNotStrip
31+
-keep @com.facebook.proguard.annotations.DoNotStrip class *
32+
-keepclassmembers class * {
33+
@com.facebook.proguard.annotations.DoNotStrip *;
34+
}
35+
36+
-keepclassmembers @com.facebook.proguard.annotations.KeepGettersAndSetters class * {
37+
void set*(***);
38+
*** get*();
39+
}
40+
41+
-keep class * extends com.facebook.react.bridge.JavaScriptModule { *; }
42+
-keep class * extends com.facebook.react.bridge.NativeModule { *; }
43+
-keepclassmembers,includedescriptorclasses class * { native <methods>; }
44+
-keepclassmembers class * { @com.facebook.react.uimanager.UIProp <fields>; }
45+
-keepclassmembers class * { @com.facebook.react.uimanager.annotations.ReactProp <methods>; }
46+
-keepclassmembers class * { @com.facebook.react.uimanager.annotations.ReactPropGroup <methods>; }
47+
48+
-dontwarn com.facebook.react.**
49+
50+
# okhttp
51+
52+
-keepattributes Signature
53+
-keepattributes *Annotation*
54+
-keep class com.squareup.okhttp.** { *; }
55+
-keep interface com.squareup.okhttp.** { *; }
56+
-dontwarn com.squareup.okhttp.**
57+
58+
# okio
59+
60+
-keep class sun.misc.Unsafe { *; }
61+
-dontwarn java.nio.file.*
62+
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
63+
-dontwarn okio.**
64+
65+
# stetho
66+
67+
-dontwarn com.facebook.stetho.**
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import org.apache.tools.ant.taskdefs.condition.Os
2+
3+
def config = project.hasProperty("react") ? project.react : [];
4+
5+
def bundleAssetName = config.bundleAssetName ?: "index.android.bundle"
6+
def entryFile = config.entryFile ?: "index.android.js"
7+
8+
// because elvis operator
9+
def elvisFile(thing) {
10+
return thing ? file(thing) : null;
11+
}
12+
13+
def reactRoot = elvisFile(config.root) ?: file("../../")
14+
def inputExcludes = config.inputExcludes ?: ["android/**", "ios/**"]
15+
16+
void runBefore(String dependentTaskName, Task task) {
17+
Task dependentTask = tasks.findByPath(dependentTaskName);
18+
if (dependentTask != null) {
19+
dependentTask.dependsOn task
20+
}
21+
}
22+
23+
gradle.projectsEvaluated {
24+
// Grab all build types and product flavors
25+
def buildTypes = android.buildTypes.collect { type -> type.name }
26+
def productFlavors = android.productFlavors.collect { flavor -> flavor.name }
27+
28+
// When no product flavors defined, use empty
29+
if (!productFlavors) productFlavors.add('')
30+
31+
productFlavors.each { productFlavorName ->
32+
buildTypes.each { buildTypeName ->
33+
// Create variant and source names
34+
def sourceName = "${buildTypeName}"
35+
def targetName = "${sourceName.capitalize()}"
36+
if (productFlavorName) {
37+
sourceName = "${productFlavorName}${targetName}"
38+
}
39+
40+
// React js bundle directories
41+
def jsBundleDirConfigName = "jsBundleDir${targetName}"
42+
def jsBundleDir = elvisFile(config."$jsBundleDirConfigName") ?:
43+
file("$buildDir/intermediates/assets/${sourceName}")
44+
45+
def resourcesDirConfigName = "jsBundleDir${targetName}"
46+
def resourcesDir = elvisFile(config."${resourcesDirConfigName}") ?:
47+
file("$buildDir/intermediates/res/merged/${sourceName}")
48+
def jsBundleFile = file("$jsBundleDir/$bundleAssetName")
49+
50+
// Bundle task name for variant
51+
def bundleJsAndAssetsTaskName = "bundle${targetName}JsAndAssets"
52+
53+
def currentBundleTask = tasks.create(
54+
name: bundleJsAndAssetsTaskName,
55+
type: Exec) {
56+
group = "react"
57+
description = "bundle JS and assets for ${targetName}."
58+
59+
// Create dirs if they are not there (e.g. the "clean" task just ran)
60+
doFirst {
61+
jsBundleDir.mkdirs()
62+
resourcesDir.mkdirs()
63+
}
64+
65+
// Set up inputs and outputs so gradle can cache the result
66+
inputs.files fileTree(dir: reactRoot, excludes: inputExcludes)
67+
outputs.dir jsBundleDir
68+
outputs.dir resourcesDir
69+
70+
// Set up the call to the react-native cli
71+
workingDir reactRoot
72+
73+
// Set up dev mode
74+
def devEnabled = !targetName.toLowerCase().contains("release")
75+
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
76+
commandLine "cmd", "/c", "react-native", "bundle", "--platform", "android", "--dev", "${devEnabled}",
77+
"--entry-file", entryFile, "--bundle-output", jsBundleFile, "--assets-dest", resourcesDir
78+
} else {
79+
commandLine "react-native", "bundle", "--platform", "android", "--dev", "${devEnabled}",
80+
"--entry-file", entryFile, "--bundle-output", jsBundleFile, "--assets-dest", resourcesDir
81+
}
82+
83+
enabled config."bundleIn${targetName}" ?: targetName.toLowerCase().contains("release")
84+
}
85+
86+
// Hook bundle${productFlavor}${buildType}JsAndAssets into the android build process
87+
currentBundleTask.dependsOn("merge${targetName}Resources")
88+
currentBundleTask.dependsOn("merge${targetName}Assets")
89+
90+
runBefore("processArmeabi-v7a${targetName}Resources", currentBundleTask)
91+
runBefore("processX86${targetName}Resources", currentBundleTask)
92+
runBefore("processUniversal${targetName}Resources", currentBundleTask)
93+
runBefore("process${targetName}Resources", currentBundleTask)
94+
}
95+
}
96+
}

0 commit comments

Comments
 (0)