forked from osdio/noder-react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTabBar.js
More file actions
91 lines (80 loc) · 2.4 KB
/
TabBar.js
File metadata and controls
91 lines (80 loc) · 2.4 KB
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
'use strict';
var React = require('react-native');
var {
StyleSheet,
Text,
View,
TouchableOpacity,
} = React;
var deviceWidth = require('Dimensions').get('window').width;
var precomputeStyle = require('precomputeStyle');
var TAB_UNDERLINE_REF = 'TAB_UNDERLINE';
var underLineColor = '#3498DB'
var activeTabTextColor = 'rgba(0,0,0,9)'
var normalTabTextColor = 'rgba(0,0,0,0.4)'
var styles = StyleSheet.create({
tab: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
paddingBottom: 10,
paddingTop: 10
},
tabs: {
height: 50 + 4,
flexDirection: 'row',
marginTop: 0,
borderWidth: 1,
borderTopWidth: 0,
borderLeftWidth: 0,
borderRightWidth: 0,
borderBottomColor: 'rgba(0,0,0,0.06)',
//shadowColor: 'rgba(0,0,0,1)',
//shadowOffset: {
// width: -1,
// height: -2
//},
//shadowOpacity: 0.1,
//alignItems: 'center'
},
});
var DefaultTabBar = React.createClass({
propTypes: {
goToPage: React.PropTypes.func,
activeTab: React.PropTypes.number,
tabs: React.PropTypes.array
},
renderTabOption(name, page) {
var isTabActive = this.props.activeTab === page;
return (
<TouchableOpacity key={name} onPress={() => this.props.goToPage(page)}>
<View style={[styles.tab]}>
<Text
style={{color: isTabActive ? activeTabTextColor : normalTabTextColor, fontWeight: isTabActive ? 'bold' : 'normal'}}>{name}</Text>
</View>
</TouchableOpacity>
);
},
setAnimationValue(value) {
this.refs[TAB_UNDERLINE_REF].setNativeProps(precomputeStyle({
left: (deviceWidth * value) / this.props.tabs.length
}));
},
render() {
var numberOfTabs = this.props.tabs.length;
var tabUnderlineStyle = {
position: 'absolute',
width: deviceWidth / numberOfTabs,
height: 4,
backgroundColor: underLineColor,
bottom: 0,
};
return (
<View style={styles.tabs}>
{this.props.tabs.map((tab, i) => this.renderTabOption(tab, i))}
<View style={tabUnderlineStyle} ref={TAB_UNDERLINE_REF}/>
</View>
);
},
});
module.exports = DefaultTabBar;