Skip to content

Commit 1d7a32b

Browse files
committed
Merge pull request #38 from charpeni/move-styles
Move styles outside of constructor
2 parents 1ad26bb + 1df39b8 commit 1d7a32b

File tree

3 files changed

+72
-72
lines changed

3 files changed

+72
-72
lines changed

components/NavBarContainer.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,23 @@ const propTypes = {
2121
toRoute: PropTypes.func.isRequired,
2222
};
2323

24+
const styles = StyleSheet.create({
25+
navbarContainer: {
26+
position: 'absolute',
27+
top: 0,
28+
left: 0,
29+
right: 0,
30+
height: Styles.NAV_BAR_HEIGHT,
31+
},
32+
navbarContainerHidden: {
33+
position: 'absolute',
34+
top: -Styles.NAV_BAR_HEIGHT,
35+
left: 0,
36+
right: 0,
37+
height: Styles.NAV_BAR_HEIGHT,
38+
},
39+
});
40+
2441
class NavBarContainer extends React.Component {
2542
constructor(props) {
2643
super(props);
@@ -33,23 +50,6 @@ class NavBarContainer extends React.Component {
3350
backButtonOpacity: 0,
3451
previousRoute: {}, // Keep previousRoute for smooth transitions
3552
};
36-
37-
this.styles = StyleSheet.create({
38-
navbarContainer: {
39-
position: 'absolute',
40-
top: 0,
41-
left: 0,
42-
right: 0,
43-
height: Styles.NAV_BAR_HEIGHT,
44-
},
45-
navbarContainerHidden: {
46-
position: 'absolute',
47-
top: -Styles.NAV_BAR_HEIGHT,
48-
left: 0,
49-
right: 0,
50-
height: Styles.NAV_BAR_HEIGHT,
51-
},
52-
});
5353
}
5454

5555
componentDidMount() {
@@ -104,9 +104,9 @@ class NavBarContainer extends React.Component {
104104
}
105105

106106
if (this.props.currentRoute.hideNavigationBar) {
107-
navbarStyle = this.styles.navbarContainerHidden;
107+
navbarStyle = styles.navbarContainerHidden;
108108
} else {
109-
navbarStyle = this.styles.navbarContainer;
109+
navbarStyle = styles.navbarContainer;
110110
}
111111

112112
if (this.props.currentRoute.trans) {

components/NavBarContent.js

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,47 @@ const propTypes = {
1818
willDisappear: PropTypes.bool,
1919
};
2020

21+
const styles = StyleSheet.create({
22+
navbar: {
23+
position: 'absolute',
24+
top: 0,
25+
left: 0,
26+
right: 0,
27+
height: Styles.NAV_BAR_HEIGHT,
28+
justifyContent: 'center',
29+
alignItems: 'center',
30+
flexDirection: 'row',
31+
paddingTop: Styles.NAV_BAR_PADDING_TOP,
32+
},
33+
navbarText: {
34+
color: 'white',
35+
fontSize: 17,
36+
margin: 10,
37+
marginTop: Styles.NAV_BAR_TEXT_MARGIN_TOP,
38+
marginBottom: Styles.NAV_BAR_TEXT_MARGIN_TOP,
39+
fontWeight: '600',
40+
textAlign: Styles.NAV_BAR_TEXT_ALIGN,
41+
alignItems: 'center',
42+
},
43+
corner: {
44+
flex: 1,
45+
justifyContent: 'center',
46+
},
47+
48+
alignLeft: {
49+
alignItems: 'flex-start',
50+
},
51+
alignRight: {
52+
alignItems: 'flex-end',
53+
},
54+
buttonTextLeft: {
55+
marginLeft: 10,
56+
},
57+
buttonTextRight: {
58+
marginRight: 10,
59+
},
60+
});
61+
2162
class NavBarContent extends React.Component {
2263
constructor(props) {
2364
super(props);
@@ -29,47 +70,6 @@ class NavBarContent extends React.Component {
2970
this.state = {
3071
opacity: this.props.willDisappear ? new Animated.Value(1) : new Animated.Value(0),
3172
};
32-
33-
this.styles = StyleSheet.create({
34-
navbar: {
35-
position: 'absolute',
36-
top: 0,
37-
left: 0,
38-
right: 0,
39-
height: Styles.NAV_BAR_HEIGHT,
40-
justifyContent: 'center',
41-
alignItems: 'center',
42-
flexDirection: 'row',
43-
paddingTop: Styles.NAV_BAR_PADDING_TOP,
44-
},
45-
navbarText: {
46-
color: 'white',
47-
fontSize: 17,
48-
margin: 10,
49-
marginTop: Styles.NAV_BAR_TEXT_MARGIN_TOP,
50-
marginBottom: Styles.NAV_BAR_TEXT_MARGIN_TOP,
51-
fontWeight: '600',
52-
textAlign: Styles.NAV_BAR_TEXT_ALIGN,
53-
alignItems: 'center',
54-
},
55-
corner: {
56-
flex: 1,
57-
justifyContent: 'center',
58-
},
59-
60-
alignLeft: {
61-
alignItems: 'flex-start',
62-
},
63-
alignRight: {
64-
alignItems: 'flex-end',
65-
},
66-
buttonTextLeft: {
67-
marginLeft: 10,
68-
},
69-
buttonTextRight: {
70-
marginRight: 10,
71-
},
72-
});
7373
}
7474

7575
componentWillReceiveProps(newProps) {
@@ -147,7 +147,7 @@ class NavBarContent extends React.Component {
147147

148148
if (Platform.OS === 'ios' || this.props.route.leftCorner || this.props.route.index > 0) {
149149
leftCorner = (
150-
<View style={[this.styles.corner, this.styles.alignLeft]}>
150+
<View style={[styles.corner, styles.alignLeft]}>
151151
{leftCornerContent}
152152
</View>
153153
);
@@ -171,7 +171,7 @@ class NavBarContent extends React.Component {
171171

172172
if (Platform.OS === 'ios' || this.props.route.rightCorner || this.props.rightCorner) {
173173
rightCorner = (
174-
<View style={[this.styles.corner, this.styles.alignRight]}>
174+
<View style={[styles.corner, styles.alignRight]}>
175175
{rightCornerContent}
176176
</View>
177177
);
@@ -186,7 +186,7 @@ class NavBarContent extends React.Component {
186186
titleContent = <TitleComponent {...this.props.titleProps} />;
187187
} else {
188188
titleContent = (
189-
<Text style={[this.styles.navbarText, this.props.titleStyle]} numberOfLines={1}>
189+
<Text style={[styles.navbarText, this.props.titleStyle]} numberOfLines={1}>
190190
{this.props.route.name}
191191
</Text>
192192
);
@@ -211,7 +211,7 @@ class NavBarContent extends React.Component {
211211
<Animated.View
212212
style={
213213
[
214-
this.styles.navbar,
214+
styles.navbar,
215215
transitionStyle,
216216
this.props.route.headerStyle,
217217
{ borderBottomWidth: width, borderColor: color },

index.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ const propTypes = {
2626
titleStyle: PropTypes.any.isRequired,
2727
};
2828

29+
const styles = StyleSheet.create({
30+
container: {
31+
flex: 1,
32+
backgroundColor: '#FFFFFF',
33+
},
34+
});
35+
2936
class Router extends React.Component {
3037
constructor(props) {
3138
super(props);
@@ -44,13 +51,6 @@ class Router extends React.Component {
4451
},
4552
};
4653
this.emitter = new EventEmitter();
47-
48-
this.styles = StyleSheet.create({
49-
container: {
50-
flex: 1,
51-
backgroundColor: '#FFFFFF',
52-
},
53-
});
5454
}
5555

5656
onWillFocus(route) {
@@ -162,7 +162,7 @@ class Router extends React.Component {
162162

163163
return (
164164
<View
165-
style={[this.styles.container, this.props.bgStyle, extraStyling, { marginTop: margin }]}
165+
style={[styles.container, this.props.bgStyle, extraStyling, { marginTop: margin }]}
166166
>
167167
<Content
168168
name={route.name}

0 commit comments

Comments
 (0)