Skip to content

Commit 4773e00

Browse files
committed
Sync with branch
2 parents 2d98374 + 903601c commit 4773e00

File tree

10 files changed

+318
-289
lines changed

10 files changed

+318
-289
lines changed

README.md

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ import Router from 'react-native-simple-router';
2222

2323
The basics:
2424
```javascript
25+
26+
import React, { StyleSheet } from 'react-native';
27+
2528
// The initial page
2629
class HelloPage extends React.Component {
2730

@@ -31,31 +34,30 @@ class HelloPage extends React.Component {
3134

3235
}
3336

37+
const styles = StyleSheet.create({
38+
header: {
39+
backgroundColor: '#5cafec',
40+
},
41+
});
42+
3443
// Your route object should contain at least:
3544
// - The name of the route (which will become the navigation bar title)
3645
// - The component object for the page to render
37-
var firstRoute = {
46+
const firstRoute = {
3847
name: 'Welcome!',
39-
component: HelloPage
48+
component: HelloPage,
4049
};
4150

4251
// The Router wrapper
4352
class MyApp extends React.Component {
4453

45-
constructor(props) {
46-
super(props);
47-
this.styles = StyleSheet.create({
48-
header: {
49-
backgroundColor: '#5cafec',
50-
},
51-
});
52-
}
53-
5454
render() {
55-
return <Router
56-
firstRoute={firstRoute}
57-
headerStyle={this.styles.header}
58-
/>
55+
return (
56+
<Router
57+
firstRoute={firstRoute}
58+
headerStyle={styles.header}
59+
/>
60+
);
5961
}
6062
}
6163

components/NavBarContainer.js

Lines changed: 40 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
1-
import React from 'react-native';
1+
import React, { StyleSheet, View, PropTypes, Platform, BackAndroid } from 'react-native';
22

33
import NavBarContent from './NavBarContent';
44

5-
const {
6-
StyleSheet,
7-
View,
8-
Component,
9-
Platform,
10-
BackAndroid,
11-
} = React;
12-
13-
class NavBarContainer extends Component {
5+
const propTypes = {
6+
backButtonComponent: PropTypes.func,
7+
borderBottomWidth: PropTypes.number,
8+
borderColor: PropTypes.string,
9+
currentRoute: PropTypes.object.isRequired,
10+
customAction: PropTypes.func,
11+
leftProps: PropTypes.object,
12+
navigator: PropTypes.object.isRequired,
13+
rightCorner: PropTypes.func,
14+
rightProps: PropTypes.object,
15+
style: PropTypes.any.isRequired,
16+
titleProps: PropTypes.object,
17+
titleStyle: PropTypes.any.isRequired,
18+
toBack: PropTypes.func.isRequired,
19+
toRoute: PropTypes.func.isRequired,
20+
};
21+
22+
class NavBarContainer extends React.Component {
1423
constructor(props) {
1524
super(props);
1625

@@ -22,6 +31,23 @@ class NavBarContainer extends Component {
2231
backButtonOpacity: 0,
2332
previousRoute: {}, // Keep previousRoute for smooth transitions
2433
};
34+
35+
this.styles = StyleSheet.create({
36+
navbarContainer: {
37+
position: 'absolute',
38+
top: 0,
39+
left: 0,
40+
right: 0,
41+
height: 64,
42+
},
43+
navbarContainerHidden: {
44+
position: 'absolute',
45+
top: -64,
46+
left: 0,
47+
right: 0,
48+
height: 64,
49+
},
50+
});
2551
}
2652

2753
componentDidMount() {
@@ -76,9 +102,9 @@ class NavBarContainer extends Component {
76102
}
77103

78104
if (this.props.currentRoute.hideNavigationBar) {
79-
navbarStyle = styles.navbarContainerHidden;
105+
navbarStyle = this.styles.navbarContainerHidden;
80106
} else {
81-
navbarStyle = styles.navbarContainer;
107+
navbarStyle = this.styles.navbarContainer;
82108
}
83109

84110
if (this.props.currentRoute.trans) {
@@ -88,7 +114,7 @@ class NavBarContainer extends Component {
88114
backButtonComponent={this.props.backButtonComponent}
89115
rightCorner={this.props.rightCorner}
90116
titleStyle={this.props.titleStyle}
91-
willDisappear="true"
117+
willDisappear
92118
/>
93119
);
94120
} else if (this.props.currentRoute.hideNavigationBar) {
@@ -135,21 +161,6 @@ class NavBarContainer extends Component {
135161
}
136162
}
137163

138-
const styles = StyleSheet.create({
139-
navbarContainer: {
140-
position: 'absolute',
141-
top: 0,
142-
left: 0,
143-
right: 0,
144-
height: 64,
145-
},
146-
navbarContainerHidden: {
147-
position: 'absolute',
148-
top: -64,
149-
left: 0,
150-
right: 0,
151-
height: 64,
152-
},
153-
});
164+
NavBarContainer.propTypes = propTypes;
154165

155166
export default NavBarContainer;

components/NavBarContent.js

Lines changed: 63 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
1-
import React from 'react-native';
1+
import React, { StyleSheet, Text, View, Animated, Easing, PropTypes } from 'react-native';
22
import NavButton from './NavButton';
33

4-
const {
5-
StyleSheet,
6-
Text,
7-
View,
8-
Animated,
9-
Easing,
10-
Component,
11-
} = React;
12-
13-
class NavBarContent extends Component {
4+
const propTypes = {
5+
backButtonComponent: PropTypes.func,
6+
borderBottomWidth: PropTypes.number,
7+
borderColor: PropTypes.string,
8+
customAction: PropTypes.func,
9+
goBack: PropTypes.func,
10+
goForward: PropTypes.func,
11+
leftProps: PropTypes.object,
12+
rightCorner: PropTypes.func,
13+
rightProps: PropTypes.object,
14+
route: PropTypes.object.isRequired,
15+
titleProps: PropTypes.object,
16+
titleStyle: PropTypes.any.isRequired,
17+
willDisappear: PropTypes.bool,
18+
};
19+
20+
class NavBarContent extends React.Component {
1421
constructor(props) {
1522
super(props);
1623

@@ -21,6 +28,46 @@ class NavBarContent extends Component {
2128
this.state = {
2229
opacity: this.props.willDisappear ? new Animated.Value(1) : new Animated.Value(0),
2330
};
31+
32+
this.styles = StyleSheet.create({
33+
navbar: {
34+
position: 'absolute',
35+
top: 0,
36+
left: 0,
37+
right: 0,
38+
height: 64, // Default iOS navbar height
39+
justifyContent: 'center',
40+
alignItems: 'center',
41+
flexDirection: 'row',
42+
paddingTop: 13,
43+
},
44+
navbarText: {
45+
color: 'white',
46+
fontSize: 17,
47+
margin: 10,
48+
marginTop: 14,
49+
fontWeight: '600',
50+
textAlign: 'center',
51+
alignItems: 'center',
52+
},
53+
corner: {
54+
flex: 1,
55+
justifyContent: 'center',
56+
},
57+
58+
alignLeft: {
59+
alignItems: 'flex-start',
60+
},
61+
alignRight: {
62+
alignItems: 'flex-end',
63+
},
64+
buttonTextLeft: {
65+
marginLeft: 10,
66+
},
67+
buttonTextRight: {
68+
marginRight: 10,
69+
},
70+
});
2471
}
2572

2673
componentWillReceiveProps(newProps) {
@@ -95,7 +142,7 @@ class NavBarContent extends Component {
95142
}
96143

97144
leftCorner = (
98-
<View style={[styles.corner, styles.alignLeft]}>
145+
<View style={[this.styles.corner, this.styles.alignLeft]}>
99146
{leftCornerContent}
100147
</View>
101148
);
@@ -117,7 +164,7 @@ class NavBarContent extends Component {
117164
}
118165

119166
rightCorner = (
120-
<View style={[styles.corner, styles.alignRight]}>
167+
<View style={[this.styles.corner, this.styles.alignRight]}>
121168
{rightCornerContent}
122169
</View>
123170
);
@@ -131,7 +178,7 @@ class NavBarContent extends Component {
131178
titleContent = <TitleComponent {...this.props.titleProps} />;
132179
} else {
133180
titleContent = (
134-
<Text style={[styles.navbarText, this.props.titleStyle]} numberOfLines={1}>
181+
<Text style={[this.styles.navbarText, this.props.titleStyle]} numberOfLines={1}>
135182
{this.props.route.name}
136183
</Text>
137184
);
@@ -156,7 +203,7 @@ class NavBarContent extends Component {
156203
<Animated.View
157204
style={
158205
[
159-
styles.navbar,
206+
this.styles.navbar,
160207
transitionStyle,
161208
this.props.route.headerStyle,
162209
{ borderBottomWidth: width, borderColor: color },
@@ -172,44 +219,6 @@ class NavBarContent extends Component {
172219
}
173220
}
174221

175-
const styles = StyleSheet.create({
176-
navbar: {
177-
position: 'absolute',
178-
top: 0,
179-
left: 0,
180-
right: 0,
181-
height: 64, // Default iOS navbar height
182-
justifyContent: 'center',
183-
alignItems: 'center',
184-
flexDirection: 'row',
185-
paddingTop: 13,
186-
},
187-
navbarText: {
188-
color: 'white',
189-
fontSize: 17,
190-
margin: 10,
191-
marginTop: 14,
192-
fontWeight: '600',
193-
textAlign: 'center',
194-
alignItems: 'center',
195-
},
196-
corner: {
197-
flex: 1,
198-
justifyContent: 'center',
199-
},
200-
201-
alignLeft: {
202-
alignItems: 'flex-start',
203-
},
204-
alignRight: {
205-
alignItems: 'flex-end',
206-
},
207-
buttonTextLeft: {
208-
marginLeft: 10,
209-
},
210-
buttonTextRight: {
211-
marginRight: 10,
212-
},
213-
});
222+
NavBarContent.propTypes = propTypes;
214223

215224
export default NavBarContent;

components/NavButton.js

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
1-
import React from 'react-native';
1+
import React, { StyleSheet, Text, View, TouchableHighlight, PropTypes } from 'react-native';
22

3-
const {
4-
StyleSheet,
5-
Text,
6-
View,
7-
TouchableHighlight,
8-
Component,
9-
} = React;
3+
const propTypes = {
4+
backButtonComponent: PropTypes.func,
5+
onPress: PropTypes.func.isRequired,
6+
};
107

11-
class NavButton extends Component {
8+
class NavButton extends React.Component {
129
constructor(props) {
1310
super(props);
1411

12+
this.styles = StyleSheet.create({
13+
navbarText: {
14+
color: 'white',
15+
fontSize: 16,
16+
margin: 10,
17+
fontWeight: '600',
18+
textAlign: 'center',
19+
alignItems: 'center',
20+
},
21+
});
22+
1523
this.onPress = this.onPress.bind(this);
1624
}
1725

@@ -27,7 +35,7 @@ class NavButton extends Component {
2735
BackButton = this.props.backButtonComponent;
2836
backButton = <View><BackButton/></View>;
2937
} else {
30-
backButton = <Text style={styles.navbarText}>Back</Text>;
38+
backButton = <Text style={this.styles.navbarText}>Back</Text>;
3139
}
3240

3341
return (
@@ -38,15 +46,6 @@ class NavButton extends Component {
3846
}
3947
}
4048

41-
const styles = StyleSheet.create({
42-
navbarText: {
43-
color: 'white',
44-
fontSize: 16,
45-
margin: 10,
46-
fontWeight: '600',
47-
textAlign: 'center',
48-
alignItems: 'center',
49-
},
50-
});
49+
NavButton.propTypes = propTypes;
5150

5251
export default NavButton;

0 commit comments

Comments
 (0)