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, MainScreen._createChildView(HOME))}
{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 >
);
}