组件react-native-tab-navigator的使用
1、npm安装,导入组件react-native-tab-navigator
import TabNavigator from 'react-native-tab-navigator';
2、代码如下
<View style={styles.container}>
<TabNavigator>
<TabNavigator.Item
selected={this.state.selectedTab === 'home'}
selectedTitleStyle={styles.btselcttext}
title="Home"
renderIcon={() => <Image style={styles.image} source={require('./res/images/Home-home.png')} />}
renderSelectedIcon={() => <Image style={styles.image} source={require('./res/images/Home-home1.png')} />}
// badgeText="1"
onPress={() => this.setState({ selectedTab: 'home' })}>
<View style={styles.page}></View>
</TabNavigator.Item>
<TabNavigator.Item
selected={this.state.selectedTab === 'messge'}
selectedTitleStyle={styles.btselcttext}
title="消息"
renderIcon={() => <Image style={styles.image} source={require('./res/images/Home-messge.png')} />}
renderSelectedIcon={() => <Image style={styles.image} source={require('./res/images/Home-messge1.png')} />}
// badgeText="1"
// renderBadge={() => <CustomBadgeView style={{backgroundColor:'red'}} />}
onPress={() => this.setState({ selectedTab: 'messge' })}>
<View style={styles.page}></View>
</TabNavigator.Item>
<TabNavigator.Item
selected={this.state.selectedTab === 'shop'}
selectedTitleStyle={styles.btselcttext}
// title="shop"
renderIcon={() => <Image style={{width:34,height:34,marginTop:20}} source={require('./res/images/Home-shop.png')} />}
renderSelectedIcon={() => <Image style={{width:34,height:34,marginTop:20}} source={require('./res/images/Home-shop.png')} />}
// badgeText="1"
onPress={() => this.setState({ selectedTab: 'shop' })}>
<View style={styles.page}></View>
</TabNavigator.Item>
<TabNavigator.Item
selected={this.state.selectedTab === 'find'}
selectedTitleStyle={styles.btselcttext}
title="发现"
renderIcon={() => <Image style={styles.image} source={require('./res/images/Home-find.png')} />}
renderSelectedIcon={() => <Image style={styles.image} source={require('./res/images/Home-find1.png')} />}
// badgeText="1"
onPress={() => this.setState({ selectedTab: 'find' })}>
<View style={styles.page}></View>
</TabNavigator.Item>
<TabNavigator.Item
selected={this.state.selectedTab === 'profile'}
selectedTitleStyle={styles.btselcttext}
title="我的"
renderIcon={() => <Image style={styles.image} source={require('./res/images/Home-my.png')} />}
renderSelectedIcon={() => <Image style={styles.image} source={require('./res/images/Home-my1.png')} />}
// renderBadge={() => <CustomBadgeView />}
onPress={() => this.setState({ selectedTab: 'profile' })}>
<View style={styles.page1}></View>
</TabNavigator.Item>
</TabNavigator>
</View>
3、路由的嵌套容易造成布局的混乱,比如头部标题等无法显示
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。