Skip to content

Commit 82aea03

Browse files
committed
Add android example
1 parent bde0a13 commit 82aea03

File tree

14 files changed

+304
-217
lines changed

14 files changed

+304
-217
lines changed

examples

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'use strict';
2+
import React, {
3+
AppRegistry,
4+
Component
5+
} from 'react-native';
6+
7+
import AccordionList from './AccordionList';
8+
9+
class AccordionExample extends Component {
10+
render() {
11+
return <AccordionList />;
12+
}
13+
}
14+
15+
AppRegistry.registerComponent('AccordionExample', () => AccordionExample);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Top-level build file where you can add configuration options common to all sub-projects/modules.
2+
3+
buildscript {
4+
repositories {
5+
jcenter()
6+
}
7+
dependencies {
8+
classpath 'com.android.tools.build:gradle:1.3.1'
9+
10+
// NOTE: Do not place your application dependencies here; they belong
11+
// in the individual module build.gradle files
12+
}
13+
}
14+
15+
allprojects {
16+
repositories {
17+
mavenLocal()
18+
jcenter()
19+
maven {
20+
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
21+
url "$projectDir/../../node_modules/react-native/android"
22+
}
23+
}
24+
}

examples/AccordionExample/.flowconfig

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,8 @@
1515
# Ignore react and fbjs where there are overlaps, but don't ignore
1616
# anything that react-native relies on
1717
.*/node_modules/fbjs/lib/Map.js
18-
.*/node_modules/fbjs/lib/Promise.js
1918
.*/node_modules/fbjs/lib/fetch.js
2019
.*/node_modules/fbjs/lib/ExecutionEnvironment.js
21-
.*/node_modules/fbjs/lib/isEmpty.js
22-
.*/node_modules/fbjs/lib/crc32.js
2320
.*/node_modules/fbjs/lib/ErrorUtils.js
2421

2522
# Flow has a built-in definition for the 'react' module which we prefer to use
@@ -28,6 +25,11 @@
2825
.*/node_modules/react/lib/React.js
2926
.*/node_modules/react/lib/ReactDOM.js
3027

28+
.*/__mocks__/.*
29+
.*/__tests__/.*
30+
31+
.*/commoner/test/source/widget/share.js
32+
3133
# Ignore commoner tests
3234
.*/node_modules/commoner/test/.*
3335

@@ -40,26 +42,48 @@
4042
# Ignore Website
4143
.*/website/.*
4244

45+
.*/node_modules/is-my-json-valid/test/.*\.json
46+
.*/node_modules/iconv-lite/encodings/tables/.*\.json
47+
.*/node_modules/y18n/test/.*\.json
48+
.*/node_modules/spdx-license-ids/spdx-license-ids.json
49+
.*/node_modules/spdx-exceptions/index.json
50+
.*/node_modules/resolve/test/subdirs/node_modules/a/b/c/x.json
51+
.*/node_modules/resolve/lib/core.json
52+
.*/node_modules/jsonparse/samplejson/.*\.json
53+
.*/node_modules/json5/test/.*\.json
54+
.*/node_modules/ua-parser-js/test/.*\.json
55+
.*/node_modules/builtin-modules/builtin-modules.json
56+
.*/node_modules/binary-extensions/binary-extensions.json
57+
.*/node_modules/url-regex/tlds.json
58+
.*/node_modules/joi/.*\.json
59+
.*/node_modules/isemail/.*\.json
60+
.*/node_modules/tr46/.*\.json
61+
4362
[include]
4463

4564
[libs]
4665
node_modules/react-native/Libraries/react-native/react-native-interface.js
66+
node_modules/react-native/flow
67+
flow/
4768

4869
[options]
4970
module.system=haste
5071

72+
esproposal.class_static_fields=enable
73+
esproposal.class_instance_fields=enable
74+
5175
munge_underscores=true
5276

5377
module.name_mapper='^image![a-zA-Z0-9$_-]+$' -> 'GlobalImageStub'
54-
module.name_mapper='^[./a-zA-Z0-9$_-]+\.png$' -> 'RelativeImageStub'
78+
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'
5579

5680
suppress_type=$FlowIssue
5781
suppress_type=$FlowFixMe
5882
suppress_type=$FixMe
5983

60-
suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(2[0-0]\\|1[0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)
61-
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(2[0-0]\\|1[0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+
84+
suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(2[0-2]\\|1[0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)
85+
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(2[0-2]\\|1[0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+
6286
suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy
6387

6488
[version]
65-
0.20.1
89+
0.22.0
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
'use strict';
2+
3+
import React, {
4+
ListView,
5+
Text,
6+
TouchableHighlight,
7+
View
8+
} from 'react-native';
9+
10+
import Accordion from 'react-native-accordion';
11+
import { range } from 'lodash';
12+
13+
const AccordionList = React.createClass({
14+
getInitialState() {
15+
const ds = new ListView.DataSource({ rowHasChanged: (r1, r2) => r1 !== r2 });
16+
return {
17+
dataSource: ds.cloneWithRows(range(20)),
18+
};
19+
},
20+
21+
render() {
22+
return (
23+
<View style={{ flex: 1 }}>
24+
<ListView
25+
dataSource={this.state.dataSource}
26+
renderRow={this._renderRow}
27+
/>
28+
</View>
29+
);
30+
},
31+
32+
_renderHeader() {
33+
return (
34+
<View style={{
35+
paddingTop: 15,
36+
paddingRight: 15,
37+
paddingLeft: 15,
38+
paddingBottom: 15,
39+
borderBottomWidth: 1,
40+
borderBottomColor: '#a9a9a9',
41+
backgroundColor: '#f9f9f9',
42+
}}>
43+
<Text>Click to Expand</Text>
44+
</View>
45+
);
46+
},
47+
48+
_renderContent() {
49+
return (
50+
<View style={{
51+
backgroundColor: '#31363D'
52+
}}>
53+
<Text style={{
54+
paddingTop: 15,
55+
paddingRight: 15,
56+
paddingBottom: 15,
57+
paddingLeft: 15,
58+
color: '#fff',
59+
}}>
60+
This content is hidden in the accordion
61+
</Text>
62+
</View>
63+
);
64+
},
65+
66+
_renderRow(rowData) {
67+
return (
68+
<Accordion
69+
header={this._renderHeader()}
70+
content={this._renderContent()}
71+
duration={300}
72+
easing="easeOutCubic"
73+
/>
74+
);
75+
}
76+
});
77+
78+
module.exports = AccordionList;

examples/AccordionExample/android/app/build.gradle

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
apply plugin: "com.android.application"
22

3+
import com.android.build.OutputFile
4+
35
/**
4-
* The react.gradle file registers two tasks: bundleDebugJsAndAssets and bundleReleaseJsAndAssets.
6+
* The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
7+
* and bundleReleaseJsAndAssets).
58
* These basically call `react-native bundle` with the correct arguments during the Android build
69
* cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
710
* bundle directly from the development server. Below you can see all the possible configurations
@@ -21,6 +24,15 @@ apply plugin: "com.android.application"
2124
* // whether to bundle JS and assets in release mode
2225
* bundleInRelease: true,
2326
*
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+
*
2436
* // the root of your project, i.e. where "package.json" lives
2537
* root: "../../",
2638
*
@@ -49,6 +61,21 @@ apply plugin: "com.android.application"
4961

5062
apply from: "react.gradle"
5163

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+
5279
android {
5380
compileSdkVersion 23
5481
buildToolsVersion "23.0.1"
@@ -63,16 +90,37 @@ android {
6390
abiFilters "armeabi-v7a", "x86"
6491
}
6592
}
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+
}
66101
buildTypes {
67102
release {
68-
minifyEnabled false // Set this to true to enable Proguard
103+
minifyEnabled enableProguardInReleaseBuilds
69104
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
70105
}
71106
}
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+
}
72120
}
73121

74122
dependencies {
75123
compile fileTree(dir: "libs", include: ["*.jar"])
76124
compile "com.android.support:appcompat-v7:23.0.1"
77-
compile "com.facebook.react:react-native:0.18.+"
125+
compile "com.facebook.react:react-native:+" // From node_modules
78126
}

examples/AccordionExample/android/app/proguard-rules.pro

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,12 @@
4040

4141
-keep class * extends com.facebook.react.bridge.JavaScriptModule { *; }
4242
-keep class * extends com.facebook.react.bridge.NativeModule { *; }
43+
-keepclassmembers,includedescriptorclasses class * { native <methods>; }
4344
-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>; }
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.**
4649

4750
# okhttp
4851

@@ -58,3 +61,7 @@
5861
-dontwarn java.nio.file.*
5962
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
6063
-dontwarn okio.**
64+
65+
# stetho
66+
67+
-dontwarn com.facebook.stetho.**

0 commit comments

Comments
 (0)