/
navbar.js
126 lines (117 loc) · 3.97 KB
/
navbar.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
const navBarFactory = function ({ React, Dimensions }) {
const {
TouchableOpacity,
Text,
StatusBar,
View,
} = React;
const {
func,
object,
string
} = React.PropTypes;
const navBarHeight = 44;
const statusBarHeight = 20;
const styles = {
navBar: {
width: Dimensions.getWidth(),
},
navBarContainer: {
backgroundColor: '#fff',
borderColor: '#c9c9c9',
borderBottomWidth: 1,
height: navBarHeight,
padding: 5
},
buttonText: {
alignItems: 'center',
height: navBarHeight - 10,
position: 'absolute',
justifyContent: 'center'
},
buttonTextCenter: {
right: 5,
left: 5
},
buttonTextLeft: {
left: 5
},
buttonTextRight: {
right: 5,
},
titleText: {
fontSize: 17,
color: '#000'
}
};
return function NavBar( props ) {
NavBar.propTypes = {
backgroundColor: string,
titleCenter: React.PropTypes.shape({
color: string,
onPress: func,
onPressIn: func,
onPressOut: func,
onLongPress: func,
text: string,
style: object
}),
titleLeft: React.PropTypes.shape({
color: string,
onPress: func,
onPressIn: func,
onPressOut: func,
onLongPress: func,
text: string,
style: object
}),
titleRight: React.PropTypes.shape({
color: string,
onPress: func,
onPressIn: func,
onPressOut: func,
onLongPress: func,
text: string,
style: object
}),
};
return {
props,
getTitleNavBar(title, type) {
if (title) {
const touchableProps = {
onPress: title.onPress,
onPressIn: title.onPressIn,
onPressOut: title.onPressOut,
onLongPress: title.onLongPress
};
const _activeOpacity = !title.onPress && !title.onPressIn && !title.onPressOut && !title.onLongPress ? 1 : 0;
return (
<TouchableOpacity style = {[ type, styles.buttonText ]}
activeOpacity = { _activeOpacity }
{...touchableProps }>
<Text style = {[ styles.titleText, { color: title.color }, title.style ]}>
{ title.text }
</Text>
</TouchableOpacity>
)
}
},
render() {
const _statusBarStyle = this.props.statusBarHidden ? { height: 0 } : { height: statusBarHeight };
this.props.statusBarHidden ? StatusBar.setHidden(true) : StatusBar.setHidden(false);
return (
<View style = { styles.navBar } >
<View style = {[ _statusBarStyle, { backgroundColor: this.props.backgroundColor }]}></View>
<View style = {[ styles.navBarContainer, { backgroundColor: this.props.backgroundColor }]}>
{ this.getTitleNavBar( this.props.titleCenter, styles.buttonTextCenter ) }
{ this.getTitleNavBar( this.props.titleLeft, styles.buttonTextLeft ) }
{ this.getTitleNavBar( this.props.titleRight, styles.buttonTextRight ) }
</View>
</View>
)
}
}
}
}
export default navBarFactory;