Skip to content

Commit e5b1a38

Browse files
committed
Add example project
1 parent 44f468c commit e5b1a38

37 files changed

+2144
-3
lines changed

Example/.flowconfig

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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-haste/.*/__tests__/.*
18+
.*/node_modules/fbjs-haste/__forks__/Map.js
19+
.*/node_modules/fbjs-haste/__forks__/Promise.js
20+
.*/node_modules/fbjs-haste/__forks__/fetch.js
21+
.*/node_modules/fbjs-haste/core/ExecutionEnvironment.js
22+
.*/node_modules/fbjs-haste/core/isEmpty.js
23+
.*/node_modules/fbjs-haste/crypto/crc32.js
24+
.*/node_modules/fbjs-haste/stubs/ErrorUtils.js
25+
.*/node_modules/react-haste/React.js
26+
.*/node_modules/react-haste/renderers/dom/ReactDOM.js
27+
.*/node_modules/react-haste/renderers/shared/event/eventPlugins/ResponderEventPlugin.js
28+
29+
# Ignore commoner tests
30+
.*/node_modules/commoner/test/.*
31+
32+
# See https://github.com/facebook/flow/issues/442
33+
.*/react-tools/node_modules/commoner/lib/reader.js
34+
35+
# Ignore jest
36+
.*/node_modules/jest-cli/.*
37+
38+
# Ignore Website
39+
.*/website/.*
40+
41+
[include]
42+
43+
[libs]
44+
node_modules/react-native/Libraries/react-native/react-native-interface.js
45+
46+
[options]
47+
module.system=haste
48+
49+
munge_underscores=true
50+
51+
module.name_mapper='^image![a-zA-Z0-9$_-]+$' -> 'GlobalImageStub'
52+
module.name_mapper='^[./a-zA-Z0-9$_-]+\.png$' -> 'RelativeImageStub'
53+
54+
suppress_type=$FlowIssue
55+
suppress_type=$FlowFixMe
56+
suppress_type=$FixMe
57+
58+
suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(1[0-8]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)
59+
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(1[0-8]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)? #[0-9]+
60+
suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy
61+
62+
[version]
63+
0.18.1

Example/.gitignore

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
ios/GoogleMobileAds.framework/
25+
26+
# Android/IJ
27+
#
28+
.idea
29+
.gradle
30+
local.properties
31+
32+
# node.js
33+
#
34+
node_modules/
35+
npm-debug.log

Example/.watchmanconfig

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

Example/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## react-native-admob example project
2+
3+
1. `npm install`
4+
2. place **GoogleMobileAds.framework** from https://developers.google.com/admob/ios/download in ios folder

Example/android/app/build.gradle

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
apply plugin: "com.android.application"
2+
3+
/**
4+
* The react.gradle file registers two tasks: bundleDebugJsAndAssets and bundleReleaseJsAndAssets.
5+
* These basically call `react-native bundle` with the correct arguments during the Android build
6+
* cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
7+
* bundle directly from the development server. Below you can see all the possible configurations
8+
* and their defaults. If you decide to add a configuration block, make sure to add it before the
9+
* `apply from: "react.gradle"` line.
10+
*
11+
* project.ext.react = [
12+
* // the name of the generated asset file containing your JS bundle
13+
* bundleAssetName: "index.android.bundle",
14+
*
15+
* // the entry file for bundle generation
16+
* entryFile: "index.android.js",
17+
*
18+
* // whether to bundle JS and assets in debug mode
19+
* bundleInDebug: false,
20+
*
21+
* // whether to bundle JS and assets in release mode
22+
* bundleInRelease: true,
23+
*
24+
* // the root of your project, i.e. where "package.json" lives
25+
* root: "../../",
26+
*
27+
* // where to put the JS bundle asset in debug mode
28+
* jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
29+
*
30+
* // where to put the JS bundle asset in release mode
31+
* jsBundleDirRelease: "$buildDir/intermediates/assets/release",
32+
*
33+
* // where to put drawable resources / React Native assets, e.g. the ones you use via
34+
* // require('./image.png')), in debug mode
35+
* resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
36+
*
37+
* // where to put drawable resources / React Native assets, e.g. the ones you use via
38+
* // require('./image.png')), in release mode
39+
* resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
40+
*
41+
* // by default the gradle tasks are skipped if none of the JS files or assets change; this means
42+
* // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
43+
* // date; if you have any other folders that you want to ignore for performance reasons (gradle
44+
* // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
45+
* // for example, you might want to remove it from here.
46+
* inputExcludes: ["android/**", "ios/**"]
47+
* ]
48+
*/
49+
50+
apply from: "react.gradle"
51+
52+
android {
53+
compileSdkVersion 23
54+
buildToolsVersion "23.0.1"
55+
56+
defaultConfig {
57+
applicationId "com.example"
58+
minSdkVersion 16
59+
targetSdkVersion 22
60+
versionCode 1
61+
versionName "1.0"
62+
ndk {
63+
abiFilters "armeabi-v7a", "x86"
64+
}
65+
}
66+
buildTypes {
67+
release {
68+
minifyEnabled false // Set this to true to enable Proguard
69+
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
70+
}
71+
}
72+
}
73+
74+
dependencies {
75+
compile fileTree(dir: "libs", include: ["*.jar"])
76+
compile "com.android.support:appcompat-v7:23.0.1"
77+
compile "com.facebook.react:react-native:0.16.+"
78+
compile project(':RNAdMob')
79+
}
+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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 class * { @com.facebook.react.uimanager.UIProp <fields>; }
44+
-keepclassmembers class * { @com.facebook.react.uimanager.ReactProp <methods>; }
45+
-keepclassmembers class * { @com.facebook.react.uimanager.ReactPropGroup <methods>; }
46+
47+
# okhttp
48+
49+
-keepattributes Signature
50+
-keepattributes *Annotation*
51+
-keep class com.squareup.okhttp.** { *; }
52+
-keep interface com.squareup.okhttp.** { *; }
53+
-dontwarn com.squareup.okhttp.**
54+
55+
# okio
56+
57+
-keep class sun.misc.Unsafe { *; }
58+
-dontwarn java.nio.file.*
59+
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
60+
-dontwarn okio.**

Example/android/app/react.gradle

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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 jsBundleDirDebug = elvisFile(config.jsBundleDirDebug) ?:
15+
file("$buildDir/intermediates/assets/debug")
16+
def jsBundleDirRelease = elvisFile(config.jsBundleDirRelease) ?:
17+
file("$buildDir/intermediates/assets/release")
18+
def resourcesDirDebug = elvisFile(config.resourcesDirDebug) ?:
19+
file("$buildDir/intermediates/res/merged/debug")
20+
def resourcesDirRelease = elvisFile(config.resourcesDirRelease) ?:
21+
file("$buildDir/intermediates/res/merged/release")
22+
def inputExcludes = config.inputExcludes ?: ["android/**", "ios/**"]
23+
24+
def jsBundleFileDebug = file("$jsBundleDirDebug/$bundleAssetName")
25+
def jsBundleFileRelease = file("$jsBundleDirRelease/$bundleAssetName")
26+
27+
task bundleDebugJsAndAssets(type: Exec) {
28+
// create dirs if they are not there (e.g. the "clean" task just ran)
29+
doFirst {
30+
jsBundleDirDebug.mkdirs()
31+
resourcesDirDebug.mkdirs()
32+
}
33+
34+
// set up inputs and outputs so gradle can cache the result
35+
inputs.files fileTree(dir: reactRoot, excludes: inputExcludes)
36+
outputs.dir jsBundleDirDebug
37+
outputs.dir resourcesDirDebug
38+
39+
// set up the call to the react-native cli
40+
workingDir reactRoot
41+
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
42+
commandLine "cmd", "/c", "react-native", "bundle", "--platform", "android", "--dev", "true", "--entry-file",
43+
entryFile, "--bundle-output", jsBundleFileDebug, "--assets-dest", resourcesDirDebug
44+
} else {
45+
commandLine "react-native", "bundle", "--platform", "android", "--dev", "true", "--entry-file",
46+
entryFile, "--bundle-output", jsBundleFileDebug, "--assets-dest", resourcesDirDebug
47+
}
48+
49+
enabled config.bundleInDebug ?: false
50+
}
51+
52+
task bundleReleaseJsAndAssets(type: Exec) {
53+
// create dirs if they are not there (e.g. the "clean" task just ran)
54+
doFirst {
55+
jsBundleDirRelease.mkdirs()
56+
resourcesDirRelease.mkdirs()
57+
}
58+
59+
// set up inputs and outputs so gradle can cache the result
60+
inputs.files fileTree(dir: reactRoot, excludes: inputExcludes)
61+
outputs.dir jsBundleDirRelease
62+
outputs.dir resourcesDirRelease
63+
64+
// set up the call to the react-native cli
65+
workingDir reactRoot
66+
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
67+
commandLine "cmd","/c", "react-native", "bundle", "--platform", "android", "--dev", "false", "--entry-file",
68+
entryFile, "--bundle-output", jsBundleFileRelease, "--assets-dest", resourcesDirRelease
69+
} else {
70+
commandLine "react-native", "bundle", "--platform", "android", "--dev", "false", "--entry-file",
71+
entryFile, "--bundle-output", jsBundleFileRelease, "--assets-dest", resourcesDirRelease
72+
}
73+
74+
enabled config.bundleInRelease ?: true
75+
}
76+
77+
gradle.projectsEvaluated {
78+
// hook bundleDebugJsAndAssets into the android build process
79+
bundleDebugJsAndAssets.dependsOn mergeDebugResources
80+
bundleDebugJsAndAssets.dependsOn mergeDebugAssets
81+
processDebugResources.dependsOn bundleDebugJsAndAssets
82+
83+
// hook bundleReleaseJsAndAssets into the android build process
84+
bundleReleaseJsAndAssets.dependsOn mergeReleaseResources
85+
bundleReleaseJsAndAssets.dependsOn mergeReleaseAssets
86+
processReleaseResources.dependsOn bundleReleaseJsAndAssets
87+
}
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.example">
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>

0 commit comments

Comments
 (0)