forked from ptomasroos/react-native-scrollable-tab-view
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DefaultTabBar.js
77 lines (66 loc) · 1.67 KB
/
DefaultTabBar.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
'use strict';
var React = require('react-native');
var {
Dimensions,
StyleSheet,
Text,
TouchableOpacity,
View,
Animated,
} = React;
var deviceWidth = Dimensions.get('window').width;
var styles = StyleSheet.create({
tab: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
paddingBottom: 10,
},
tabs: {
height: 50,
flexDirection: 'row',
marginTop: 20,
borderWidth: 1,
borderTopWidth: 0,
borderLeftWidth: 0,
borderRightWidth: 0,
borderBottomColor: '#ccc',
},
});
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 ? 'navy' : 'black', fontWeight: isTabActive ? 'bold' : 'normal'}}>{name}</Text>
</View>
</TouchableOpacity>
);
},
render() {
var numberOfTabs = this.props.tabs.length;
var tabUnderlineStyle = {
position: 'absolute',
width: deviceWidth / numberOfTabs,
height: 4,
backgroundColor: 'navy',
bottom: 0,
};
var left = this.props.scrollValue.interpolate({
inputRange: [0, 1], outputRange: [0, deviceWidth / numberOfTabs]
});
return (
<View style={styles.tabs}>
{this.props.tabs.map((tab, i) => this.renderTabOption(tab, i))}
<Animated.View style={[tabUnderlineStyle, {left}]} />
</View>
);
},
});
module.exports = DefaultTabBar;