forked from territoryfan/react-native-tabbar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTabBar.js
More file actions
132 lines (125 loc) · 4.24 KB
/
Copy pathTabBar.js
File metadata and controls
132 lines (125 loc) · 4.24 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
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
127
128
129
130
import {
StyleSheet,
View,
Image,
Text,
TouchableHighlight,
Dimensions,
Animated
} from 'react-native';
import React, { Component } from 'react';
import TabBarItem from "./TabBarItem";
import TabBarCenter from "./TabBarCenter";
export default class TabBar extends Component{
constructor(props) {
super(props);
this.state = {
selectedIndex: 0,
defaultPage: 0,
navFontSize: 12,
navTextColor: "rgb(148, 148, 148)",
navTextColorSelected: 'rgb(51, 163, 244)',
}
}
render() {
const {
children,
} = this.props;
const {
selectedIndex,
navFontSize,
navTextColor,
navTextColorSelected,
} = this.state;
return(
<View style={[styles.container,this.props.style]}>
<TabBarCenter setBtn="0"/>
{children[selectedIndex]}
<View style={styles.content}>
{
React.Children.map(children, (child,i) => {
const imgSrc = selectedIndex == i ? child.props.selectedIcon : child.props.icon;
const color = selectedIndex == i ? navTextColorSelected : navTextColor;
if(i==1) {
return (
<TouchableHighlight
key={i}
underlayColor={"transparent"}
style={[styles.navItem]}
onPress = {
() => {
this.update(i);
}
}
>
<TabBarCenter setBtn="1"/>
</TouchableHighlight>
);
}else{
return (
<TouchableHighlight
key={i}
underlayColor={"transparent"}
style={styles.navItem}
onPress = {
() => {
this.update(i);
}
}
>
<View style={styles.center}>
<Image
style={styles.navImage}
resizeMode="cover"
source={imgSrc}
/>
<Text style={[styles.navText,{color: color,fontSize: navFontSize}]}>
{child.props.title}
</Text>
</View>
</TouchableHighlight>
);
}
})
}
</View>
</View>
);
}
update(index) {
this.setState({
selectedIndex: index,
});
}
}
TabBar.Item = TabBarItem;
const styles = StyleSheet.create({
container: {
flex: 1,
overflow: 'hidden',
},
content: {
height: 50,
flexDirection:"row",
backgroundColor:"#fff",
},
navItem: {
flex: 1,
paddingTop: 6,
paddingBottom: 6,
alignItems: 'center',
},
center: {
width: 56,
alignItems: 'center',
justifyContent: 'center',
},
navImage: {
width: 22,
height: 22,
},
navText: {
marginTop: 3,
alignSelf: 'center',
}
});