Skip to content

Commit d0ff592

Browse files
committed
Merge pull request #536 from cridenour/feature/react-native-24
[WIP] Get Example app working with React 0.24+
2 parents 75d4d1d + ff69aaa commit d0ff592

File tree

8 files changed

+136
-23
lines changed

8 files changed

+136
-23
lines changed

Example/.buckconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
[android]
3+
target = Google Inc.:Google APIs:23
4+
5+
[maven_repositories]
6+
central = https://repo1.maven.org/maven2

Example/.flowconfig

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@
4242
# Ignore Website
4343
.*/website/.*
4444

45+
# Ignore generators
46+
.*/local-cli/generator.*
47+
48+
# Ignore BUCK generated folders
49+
.*\.buckd/
50+
4551
.*/node_modules/is-my-json-valid/test/.*\.json
4652
.*/node_modules/iconv-lite/encodings/tables/.*\.json
4753
.*/node_modules/y18n/test/.*\.json
@@ -59,6 +65,7 @@
5965
.*/node_modules/isemail/.*\.json
6066
.*/node_modules/tr46/.*\.json
6167

68+
6269
[include]
6370

6471
[libs]
@@ -86,4 +93,4 @@ suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(2[0-2]\\|1[0-9]\\|[0-9
8693
suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy
8794

8895
[version]
89-
0.22.0
96+
^0.22.0

Example/.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,9 @@ local.properties
3232
#
3333
node_modules/
3434
npm-debug.log
35+
36+
# BUCK
37+
buck-out/
38+
\.buckd/
39+
android/app/libs
40+
android/keystores/debug.keystore

Example/Example.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export default class Example extends React.Component {
5959
<Scene key="loginModal" component={Login} title="Login"/>
6060
<Scene key="loginModal2" hideNavBar={true} component={Login2} title="Login2" panHandlers={null} duration={1}/>
6161
</Scene>
62-
<Scene key="tabbar" component={NavigationDrawer}>
62+
<Scene key="tabbar" component={NavigationDrawer} panHandlers={null}>
6363
<Scene key="main" tabs={true} >
6464
<Scene key="tab1" title="Tab #1" icon={TabIcon} navigationBarStyle={{backgroundColor:"red"}} titleStyle={{color:"white"}}>
6565
<Scene key="tab1_1" component={TabView} title="Tab #1_1" onRight={()=>alert("Right button")} rightTitle="Right" />

Example/android/app/BUCK

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import re
2+
3+
# To learn about Buck see [Docs](https://buckbuild.com/).
4+
# To run your application with Buck:
5+
# - install Buck
6+
# - `npm start` - to start the packager
7+
# - `cd android`
8+
# - `cp ~/.android/debug.keystore keystores/debug.keystore`
9+
# - `./gradlew :app:copyDownloadableDepsToLibs` - make all Gradle compile dependencies available to Buck
10+
# - `buck install -r android/app` - compile, install and run application
11+
#
12+
13+
lib_deps = []
14+
for jarfile in glob(['libs/*.jar']):
15+
name = 'jars__' + re.sub(r'^.*/([^/]+)\.jar$', r'\1', jarfile)
16+
lib_deps.append(':' + name)
17+
prebuilt_jar(
18+
name = name,
19+
binary_jar = jarfile,
20+
)
21+
22+
for aarfile in glob(['libs/*.aar']):
23+
name = 'aars__' + re.sub(r'^.*/([^/]+)\.aar$', r'\1', aarfile)
24+
lib_deps.append(':' + name)
25+
android_prebuilt_aar(
26+
name = name,
27+
aar = aarfile,
28+
)
29+
30+
android_library(
31+
name = 'all-libs',
32+
exported_deps = lib_deps
33+
)
34+
35+
android_library(
36+
name = 'app-code',
37+
srcs = glob([
38+
'src/main/java/**/*.java',
39+
]),
40+
deps = [
41+
':all-libs',
42+
':build_config',
43+
':res',
44+
],
45+
)
46+
47+
android_build_config(
48+
name = 'build_config',
49+
package = 'com.example',
50+
)
51+
52+
android_resource(
53+
name = 'res',
54+
res = 'src/main/res',
55+
package = 'com.example',
56+
)
57+
58+
android_binary(
59+
name = 'app',
60+
package_type = 'debug',
61+
manifest = 'src/main/AndroidManifest.xml',
62+
keystore = '//android/keystores:debug',
63+
deps = [
64+
':app-code',
65+
],
66+
)

Example/android/app/build.gradle

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import com.android.build.OutputFile
99
* cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
1010
* bundle directly from the development server. Below you can see all the possible configurations
1111
* and their defaults. If you decide to add a configuration block, make sure to add it before the
12-
* `apply from: "react.gradle"` line.
12+
* `apply from: "../../node_modules/react-native/react.gradle"` line.
1313
*
1414
* project.ext.react = [
1515
* // the name of the generated asset file containing your JS bundle
@@ -59,7 +59,7 @@ import com.android.build.OutputFile
5959
* ]
6060
*/
6161

62-
apply from: "react.gradle"
62+
apply from: "../../node_modules/react-native/react.gradle"
6363

6464
/**
6565
* Set this to true to create two separate APKs instead of one:
@@ -124,3 +124,10 @@ dependencies {
124124
compile "com.android.support:appcompat-v7:23.0.1"
125125
compile "com.facebook.react:react-native:+" // From node_modules
126126
}
127+
128+
// Run this once to be able to run the application with BUCK
129+
// puts all compile dependencies into folder libs for BUCK to use
130+
task copyDownloadableDepsToLibs(type: Copy) {
131+
from configurations.compile
132+
into 'libs'
133+
}

Example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
},
88
"dependencies": {
99
"react": "^0.14.7",
10-
"react-native": "^0.22.2",
10+
"react-native": "^0.24.0-rc5",
1111
"react-native-button": "^1.2.1",
1212
"react-native-drawer": "^1.16.7",
1313
"react-native-modalbox": "^1.3.0",

src/DefaultRenderer.js

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@
99
import React, {Component, Animated, PropTypes, StyleSheet, View, NavigationExperimental} from "react-native";
1010
const {
1111
AnimatedView: NavigationAnimatedView,
12-
Card: NavigationCard,
13-
RootContainer: NavigationRootContainer,
14-
Header: NavigationHeader,
15-
} = NavigationExperimental;
12+
Card: NavigationCard
13+
} = NavigationExperimental;
14+
15+
const {
16+
CardStackPanResponder: NavigationCardStackPanResponder,
17+
CardStackStyleInterpolator: NavigationCardStackStyleInterpolator
18+
} = NavigationCard;
19+
1620
import TabBar from "./TabBar";
1721
import NavBar from "./NavBar";
1822
import Actions from './Actions';
@@ -59,13 +63,13 @@ export default class DefaultRenderer extends Component {
5963
return null;
6064
}
6165
let Component = navigationState.component;
62-
if (navigationState.tabs && !Component){
66+
if (navigationState.tabs && !Component) {
6367
Component = TabBar;
6468
}
6569
if (Component) {
6670
return (
6771
<View style={[{flex: 1}, navigationState.sceneStyle]}>
68-
<Component {...navigationState} navigationState={navigationState} />
72+
<Component {...navigationState} navigationState={navigationState}/>
6973
</View>
7074
)
7175
}
@@ -75,7 +79,6 @@ export default class DefaultRenderer extends Component {
7579

7680
let applyAnimation = selected.applyAnimation || navigationState.applyAnimation;
7781
let style = selected.style || navigationState.style;
78-
let direction = selected.direction || navigationState.direction || "horizontal";
7982

8083
let optionals = {};
8184
if (applyAnimation) {
@@ -85,7 +88,11 @@ export default class DefaultRenderer extends Component {
8588
if (duration === null || duration === undefined) duration = navigationState.duration;
8689
if (duration !== null && duration !== undefined) {
8790
optionals.applyAnimation = function (pos, navState) {
88-
Animated.timing(pos, {toValue: navState.index, duration}).start();
91+
if (duration === 0) {
92+
pos.setValue(navState.index);
93+
} else {
94+
Animated.timing(pos, {toValue: navState.index, duration}).start();
95+
}
8996
};
9097
}
9198
}
@@ -95,7 +102,6 @@ export default class DefaultRenderer extends Component {
95102
navigationState={navigationState}
96103
style={[styles.animatedView, style]}
97104
renderOverlay={this._renderHeader}
98-
direction={direction}
99105
renderScene={this._renderCard}
100106
{...optionals}
101107
/>
@@ -104,25 +110,40 @@ export default class DefaultRenderer extends Component {
104110

105111
_renderHeader(/*NavigationSceneRendererProps*/ props) {
106112
return <NavBar
107-
{...props}
108-
getTitle={state => state.title}
109-
/>;
113+
{...props}
114+
getTitle={state => state.title}
115+
/>;
110116
}
111117

112118
_renderCard(/*NavigationSceneRendererProps*/ props) {
113-
const { key, direction, panHandlers, getSceneStyle } = props.scene.navigationState;
119+
const {key, direction, getSceneStyle} = props.scene.navigationState;
120+
let {panHandlers, animationStyle} = props.scene.navigationState;
121+
122+
// Since we always need to pass a style for the direction, we can avoid #526
123+
let style = {};
124+
if (getSceneStyle) style = getSceneStyle(props);
114125

115-
const optionals = {};
116-
if (getSceneStyle) optionals.style = getSceneStyle(props);
126+
const isVertical = direction === "vertical";
127+
128+
if (typeof(animationStyle) === 'undefined') {
129+
animationStyle = (isVertical ?
130+
NavigationCardStackStyleInterpolator.forVertical(props) :
131+
NavigationCardStackStyleInterpolator.forHorizontal(props));
132+
}
133+
134+
if (typeof(panHandlers) === 'undefined') {
135+
panHandlers = panHandlers || (isVertical ?
136+
NavigationCardStackPanResponder.forVertical(props) :
137+
NavigationCardStackPanResponder.forHorizontal(props));
138+
}
117139

118140
return (
119141
<NavigationCard
120142
{...props}
121143
key={'card_' + key}
122-
direction={direction || 'horizontal'}
144+
style={[animationStyle, style]}
123145
panHandlers={panHandlers}
124146
renderScene={this._renderScene}
125-
{...optionals}
126147
/>
127148
);
128149
}
@@ -136,6 +157,6 @@ export default class DefaultRenderer extends Component {
136157
const styles = StyleSheet.create({
137158
animatedView: {
138159
flex: 1,
139-
backgroundColor:"transparent"
160+
backgroundColor: "transparent"
140161
},
141162
});

0 commit comments

Comments
 (0)