-
Notifications
You must be signed in to change notification settings - Fork 165
Expand file tree
/
Copy pathMainScreen.js
More file actions
90 lines (81 loc) · 2.98 KB
/
Copy pathMainScreen.js
File metadata and controls
90 lines (81 loc) · 2.98 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
/**
* Created by yuanguozheng on 16/1/19.
*/
'use strict';
import React, {
Component,
StyleSheet,
Image,
Text,
View,
Navigator
} from 'react-native';
import Header from './Header';
import HomePage from './home/HomePage';
import TabNavigator from 'react-native-tab-navigator';
const HOME = 'home';
const HOME_NORMAL = require('./images/tabs/home_normal.png');
const HOME_FOCUS = require('./images/tabs/home_focus.png');
const CATEGORY = 'category';
const CATEGORY_NORMAL = require('./images/tabs/category_normal.png');
const CATEGORY_FOCUS = require('./images/tabs/category_focus.png');
const FAXIAN = 'faxian';
const FAXIAN_NORMAL = require('./images/tabs/faxian_normal.png');
const FAXIAN_FOCUS = require('./images/tabs/faxian_focus.png');
const CART = 'cart';
const CART_NORMAL = require('./images/tabs/cart_normal.png');
const CART_FOCUS = require('./images/tabs/cart_focus.png');
const PERSONAL = 'personal';
const PERSONAL_NORMAL = require('./images/tabs/personal_normal.png');
const PERSONAL_FOCUS = require('./images/tabs/personal_focus.png');
export default class MainScreen extends Component {
constructor(props) {
super(props);
this.state = {selectedTab: HOME}
}
_renderTabItem(img, selectedImg, tag, childView) {
return (
<TabNavigator.Item
selected={this.state.selectedTab === tag}
renderIcon={() => <Image style={styles.tabIcon} source={img}/>}
renderSelectedIcon={() => <Image style={styles.tabIcon} source={selectedImg}/>}
onPress={() => this.setState({ selectedTab: tag })}>
{childView}
</TabNavigator.Item>
);
}
static _createChildView(tag) {
return (
<View style={{flex:1,backgroundColor:'#00baff',alignItems:'center',justifyContent:'center'}}>
<Text style={{fontSize:22}}>{tag}</Text>
</View>
)
}
render() {
return (
<View style={{flex: 1}}>
<Header />
<TabNavigator hidesTabTouch={true} tabBarStyle={styles.tab}>
{this._renderTabItem(HOME_NORMAL, HOME_FOCUS, HOME, <HomePage nav={this.props.nav}/>)}
{this._renderTabItem(CATEGORY_NORMAL, CATEGORY_FOCUS, CATEGORY, MainScreen._createChildView(CATEGORY))}
{this._renderTabItem(FAXIAN_NORMAL, FAXIAN_FOCUS, FAXIAN, MainScreen._createChildView(FAXIAN))}
{this._renderTabItem(CART_NORMAL, CART_FOCUS, CART, MainScreen._createChildView(CART))}
{this._renderTabItem(PERSONAL_NORMAL, PERSONAL_FOCUS, PERSONAL, MainScreen._createChildView(PERSONAL))}
</TabNavigator>
</View >
);
}
}
const styles = StyleSheet.create({
tab: {
height: 52,
backgroundColor: '#303030',
alignItems: 'center',
},
tabIcon: {
width: 30,
height: 35,
resizeMode: 'stretch',
marginTop: 12.5
}
});