Skip to content

Commit 37cee1e

Browse files
author
Xinyi
committed
init commit
0 parents  commit 37cee1e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+2219
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
bundle.js

README.md

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
## About this project
2+
This is a cross platform startup react native + redux project, support ios, android and web
3+
4+
The example project is from https://github.com/alinz/example-react-native-redux
5+
And the adaption of react-native to web is powered by https://github.com/necolas/react-native-weba
6+
7+
## Usage
8+
Do npm install first.
9+
10+
### Run react-native
11+
react-native start
12+
13+
### Run react-native in web
14+
webpack-dev-server
15+
16+
17+
# Have fun!

android/app/build.gradle

+126
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
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 can be in the following formats
30+
* // 'bundleIn${productFlavor}${buildType}'
31+
* // 'bundleIn${buildType}'
32+
* // bundleInFreeDebug: true,
33+
* // bundleInPaidRelease: true,
34+
* // bundleInBeta: true,
35+
*
36+
* // the root of your project, i.e. where "package.json" lives
37+
* root: "../../",
38+
*
39+
* // where to put the JS bundle asset in debug mode
40+
* jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
41+
*
42+
* // where to put the JS bundle asset in release mode
43+
* jsBundleDirRelease: "$buildDir/intermediates/assets/release",
44+
*
45+
* // where to put drawable resources / React Native assets, e.g. the ones you use via
46+
* // require('./image.png')), in debug mode
47+
* resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
48+
*
49+
* // where to put drawable resources / React Native assets, e.g. the ones you use via
50+
* // require('./image.png')), in release mode
51+
* resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
52+
*
53+
* // by default the gradle tasks are skipped if none of the JS files or assets change; this means
54+
* // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
55+
* // date; if you have any other folders that you want to ignore for performance reasons (gradle
56+
* // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
57+
* // for example, you might want to remove it from here.
58+
* inputExcludes: ["android/**", "ios/**"]
59+
* ]
60+
*/
61+
62+
apply from: "react.gradle"
63+
64+
/**
65+
* Set this to true to create two separate APKs instead of one:
66+
* - An APK that only works on ARM devices
67+
* - An APK that only works on x86 devices
68+
* The advantage is the size of the APK is reduced by about 4MB.
69+
* Upload all the APKs to the Play Store and people will download
70+
* the correct one based on the CPU architecture of their device.
71+
*/
72+
def enableSeparateBuildPerCPUArchitecture = false
73+
74+
/**
75+
* Run Proguard to shrink the Java bytecode in release builds.
76+
*/
77+
def enableProguardInReleaseBuilds = false
78+
79+
android {
80+
compileSdkVersion 23
81+
buildToolsVersion "23.0.1"
82+
83+
defaultConfig {
84+
applicationId "com.counter"
85+
minSdkVersion 16
86+
targetSdkVersion 22
87+
versionCode 1
88+
versionName "1.0"
89+
ndk {
90+
abiFilters "armeabi-v7a", "x86"
91+
}
92+
}
93+
splits {
94+
abi {
95+
reset()
96+
enable enableSeparateBuildPerCPUArchitecture
97+
universalApk false // If true, also generate a universal APK
98+
include "armeabi-v7a", "x86"
99+
}
100+
}
101+
buildTypes {
102+
release {
103+
minifyEnabled enableProguardInReleaseBuilds
104+
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
105+
}
106+
}
107+
// applicationVariants are e.g. debug, release
108+
applicationVariants.all { variant ->
109+
variant.outputs.each { output ->
110+
// For each separate APK per architecture, set a unique version code as described here:
111+
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
112+
def versionCodes = ["armeabi-v7a":1, "x86":2]
113+
def abi = output.getFilter(OutputFile.ABI)
114+
if (abi != null) { // null for the universal-debug, universal-release variants
115+
output.versionCodeOverride =
116+
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
117+
}
118+
}
119+
}
120+
}
121+
122+
dependencies {
123+
compile fileTree(dir: "libs", include: ["*.jar"])
124+
compile "com.android.support:appcompat-v7:23.0.1"
125+
compile "com.facebook.react:react-native:+" // From node_modules
126+
}

android/app/proguard-rules.pro

+67
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.**

android/app/react.gradle

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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 target names
34+
def targetName = "${productFlavorName.capitalize()}${buildTypeName.capitalize()}"
35+
def targetPath = productFlavorName ?
36+
"${productFlavorName}/${buildTypeName}" :
37+
"${buildTypeName}"
38+
39+
// React js bundle directories
40+
def jsBundleDirConfigName = "jsBundleDir${targetName}"
41+
def jsBundleDir = elvisFile(config."$jsBundleDirConfigName") ?:
42+
file("$buildDir/intermediates/assets/${targetPath}")
43+
44+
def resourcesDirConfigName = "jsBundleDir${targetName}"
45+
def resourcesDir = elvisFile(config."${resourcesDirConfigName}") ?:
46+
file("$buildDir/intermediates/res/merged/${targetPath}")
47+
def jsBundleFile = file("$jsBundleDir/$bundleAssetName")
48+
49+
// Bundle task name for variant
50+
def bundleJsAndAssetsTaskName = "bundle${targetName}JsAndAssets"
51+
52+
def currentBundleTask = tasks.create(
53+
name: bundleJsAndAssetsTaskName,
54+
type: Exec) {
55+
group = "react"
56+
description = "bundle JS and assets for ${targetName}."
57+
58+
// Create dirs if they are not there (e.g. the "clean" task just ran)
59+
doFirst {
60+
jsBundleDir.mkdirs()
61+
resourcesDir.mkdirs()
62+
}
63+
64+
// Set up inputs and outputs so gradle can cache the result
65+
inputs.files fileTree(dir: reactRoot, excludes: inputExcludes)
66+
outputs.dir jsBundleDir
67+
outputs.dir resourcesDir
68+
69+
// Set up the call to the react-native cli
70+
workingDir reactRoot
71+
72+
// Set up dev mode
73+
def devEnabled = !targetName.toLowerCase().contains("release")
74+
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
75+
commandLine "cmd", "/c", "react-native", "bundle", "--platform", "android", "--dev", "${devEnabled}",
76+
"--entry-file", entryFile, "--bundle-output", jsBundleFile, "--assets-dest", resourcesDir
77+
} else {
78+
commandLine "react-native", "bundle", "--platform", "android", "--dev", "${devEnabled}",
79+
"--entry-file", entryFile, "--bundle-output", jsBundleFile, "--assets-dest", resourcesDir
80+
}
81+
82+
enabled config."bundleIn${targetName}" ||
83+
config."bundleIn${buildTypeName.capitalize()}" ?:
84+
targetName.toLowerCase().contains("release")
85+
}
86+
87+
// Hook bundle${productFlavor}${buildType}JsAndAssets into the android build process
88+
currentBundleTask.dependsOn("merge${targetName}Resources")
89+
currentBundleTask.dependsOn("merge${targetName}Assets")
90+
91+
runBefore("processArmeabi-v7a${targetName}Resources", currentBundleTask)
92+
runBefore("processX86${targetName}Resources", currentBundleTask)
93+
runBefore("processUniversal${targetName}Resources", currentBundleTask)
94+
runBefore("process${targetName}Resources", currentBundleTask)
95+
}
96+
}
97+
}
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="com.counter">
3+
4+
<uses-permission android:name="android.permission.INTERNET" />
5+
6+
<application
7+
android:allowBackup="true"
8+
android:label="@string/app_name"
9+
android:icon="@mipmap/ic_launcher"
10+
android:theme="@style/AppTheme">
11+
<activity
12+
android:name=".MainActivity"
13+
android:label="@string/app_name"
14+
android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
15+
<intent-filter>
16+
<action android:name="android.intent.action.MAIN" />
17+
<category android:name="android.intent.category.LAUNCHER" />
18+
</intent-filter>
19+
</activity>
20+
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
21+
</application>
22+
23+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.counter;
2+
3+
import com.facebook.react.ReactActivity;
4+
import com.facebook.react.ReactPackage;
5+
import com.facebook.react.shell.MainReactPackage;
6+
7+
import java.util.Arrays;
8+
import java.util.List;
9+
10+
public class MainActivity extends ReactActivity {
11+
12+
/**
13+
* Returns the name of the main component registered from JavaScript.
14+
* This is used to schedule rendering of the component.
15+
*/
16+
@Override
17+
protected String getMainComponentName() {
18+
return "Counter";
19+
}
20+
21+
/**
22+
* Returns whether dev mode should be enabled.
23+
* This enables e.g. the dev menu.
24+
*/
25+
@Override
26+
protected boolean getUseDeveloperSupport() {
27+
return BuildConfig.DEBUG;
28+
}
29+
30+
/**
31+
* A list of packages used by the app. If the app uses additional views
32+
* or modules besides the default ones, add more packages here.
33+
*/
34+
@Override
35+
protected List<ReactPackage> getPackages() {
36+
return Arrays.<ReactPackage>asList(
37+
new MainReactPackage()
38+
);
39+
}
40+
}
Loading
Loading
Loading
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<resources>
2+
<string name="app_name">Counter</string>
3+
</resources>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<resources>
2+
3+
<!-- Base application theme. -->
4+
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
5+
<!-- Customize your theme here. -->
6+
</style>
7+
8+
</resources>

0 commit comments

Comments
 (0)