-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathMovieTabBar.js
85 lines (73 loc) · 1.77 KB
/
MovieTabBar.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
/**
* doubanMovielist
* by zhangyucha0
*/
'use strict';
import React, {
Component
} from 'react';
import {
StyleSheet,
View,
TouchableOpacity,
Text
} from 'react-native';
import Icon from 'react-native-vector-icons/Ionicons';
class MovieTabBar extends Component {
static propTypes = {
goToPage: React.PropTypes.func, // 跳转到对应tab的方法
activeTab: React.PropTypes.number, // 当前被选中的tab下标
tabs: React.PropTypes.array, // 所有tabs集合
tabNames: React.PropTypes.array, // 保存Tab名称
tabIconNames: React.PropTypes.array, // 保存Tab图标
}
setAnimationValue({value}) {
console.log(value);
}
componentDidMount() {
// Animated.Value监听范围 [0, tab数量-1]
this.props.scrollValue.addListener(this.setAnimationValue);
}
renderTabOption(tab, i) {
let color = this.props.activeTab == i ? "#0089A7" : "#ADADAD"; // 判断i是否是当前选中的tab,设置不同的颜色
return (
<TouchableOpacity onPress={()=>this.props.goToPage(i)} style={styles.tab}>
<View style={styles.tabItem}>
<Icon
name={this.props.tabIconNames[i]} // 图标
size={29}
color={color}/>
<Text style={{color: color,fontSize: 11,fontWeight: 'bold'}}>
{this.props.tabNames[i]}
</Text>
</View>
</TouchableOpacity>
);
}
render() {
return (
<View style={styles.tabs}>
{this.props.tabs.map((tab, i) => this.renderTabOption(tab, i))}
</View>
);
}
}
const styles = StyleSheet.create({
tabs: {
flexDirection: 'row',
height: 45,
backgroundColor: '#F5F5F5',
borderTopWidth: 0.17,
borderTopColor: '#000000'
},
tab: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
tabItem: {
flexDirection: 'column',
alignItems: 'center',
},
});
export default MovieTabBar;