forked from shaoting0730/react_native_weibo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tabBar.js
129 lines (119 loc) · 4.94 KB
/
tabBar.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
127
128
129
/**
* Created by shaotingzhou on 2017/4/24.
*/
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
Image,
TouchableOpacity,
Dimensions,
Platform
} from 'react-native';
import TabNavigator from 'react-native-tab-navigator'
import Home from './APP/Home/home'
import Message from './APP/Message/message'
import New from './APP/New/new'
import Find from './APP/Find/find'
import Mine from './APP/Mine/mine'
var {width,height} = Dimensions.get('window');
export default class TabBar extends Component {
// 构造
constructor(props) {
super(props);
// 初始状态
this.state = {
selectedTab: 'Home' // 默认是第一个
};
}
render() {
return (
<View style={styles.container}>
<TabNavigator>
<TabNavigator.Item
title="首页"
selected={this.state.selectedTab === 'Home'}
selectedTitleStyle={styles.selectedTitleStyle}
renderIcon={() => <Image source={require('./image/home.png')} style={styles.iconStyle} />} // 图标
renderSelectedIcon={() => <Image source={require('./image/home_selected.png')} style={styles.iconStyle} />} // 选中的图标
titleStyle={styles.textStyle}
onPress={() => this.setState({ selectedTab: 'Home' })}>
<Home {...this.props}/>
</TabNavigator.Item>
<TabNavigator.Item
title="消息"
selected={this.state.selectedTab === 'Message'}
selectedTitleStyle={styles.selectedTitleStyle}
renderIcon={() => <Image source={require('./image/message.png')} style={styles.iconStyle} />} // 图标
renderSelectedIcon={() => <Image source={require('./image/message_selcted.png')} style={styles.iconStyle} />} // 选中的图标
titleStyle={styles.textStyle}
onPress={() => this.setState({ selectedTab: 'Message' })}>
<Message {...this.props} />
</TabNavigator.Item>
{<TabNavigator.Item
title=' '
selected={this.state.selectedTab === 'New'}
selectedTitleStyle={styles.selectedTitleStyle}
titleStyle={styles.textStyle}
onPress={() => this.setState({ selectedTab: 'New' })}
>
<New {...this.props}/>
</TabNavigator.Item>}
<TabNavigator.Item
title="发现"
selected={this.state.selectedTab === 'Find'}
selectedTitleStyle={styles.selectedTitleStyle}
renderIcon={() => <Image source={require('./image/find.png')} style={styles.iconStyle} />} // 图标
renderSelectedIcon={() => <Image source={require('./image/find_selected.png')} style={styles.iconStyle} />} // 选中的图标
titleStyle={styles.textStyle}
onPress={() => this.setState({ selectedTab: 'Find' })}>
<Find {...this.props} />
</TabNavigator.Item>
<TabNavigator.Item
title="我的"
selected={this.state.selectedTab === 'Mine'}
selectedTitleStyle={styles.selectedTitleStyle}
renderIcon={() => <Image source={require('./image/mine.png')} style={styles.iconStyle} />} // 图标
renderSelectedIcon={() => <Image source={require('./image/mine_selected.png')} style={styles.iconStyle} />} // 选中的图标
titleStyle={styles.textStyle}
onPress={() => this.setState({ selectedTab: 'Mine' })}>
<Mine {...this.props} />
</TabNavigator.Item>
</TabNavigator>
<TouchableOpacity onPress={() => this.goRoute()} >
<Image
style={styles.newStyle}
source={require('./image/new.png')}
/>
</TouchableOpacity>
</View>
);
}
goRoute =() =>{
this.props.navigator.push({
component:New
})
}
}
const styles = StyleSheet.create({
container: {
height: Platform.OS === 'ios' ? height : height-20 ,
},
iconStyle: {
width: 25,
height: 25,
},
newStyle: {
position: 'absolute',
marginLeft: width / 2 - 25,
width: 50,
height: 40,
bottom:2,
borderRadius: 5
},
selectedTitleStyle: {
color: 'red'
},
});