TabNavigator
用于使用TabRouter轻松设置带有多个tab的页面。有关实例,请参阅我们的expo demo。
class MyHomeScreen extends React.Component {static navigationOptions = {tabBarLabel: 'Home',// Note: By default the icon is only shown on iOS. Search the showIcon option below.tabBarIcon: ({ tintColor }) => (<Imagesource={require('./chats-icon.png')}style={[styles.icon, {tintColor: tintColor}]}/>),};render() {return (<ButtononPress={() => this.props.navigation.navigate('Notifications')}title="Go to notifications"/>);}}class MyNotificationsScreen extends React.Component {static navigationOptions = {tabBarLabel: 'Notifications',tabBarIcon: ({ tintColor }) => (<Imagesource={require('./notif-icon.png')}style={[styles.icon, {tintColor: tintColor}]}/>),};render() {return (<ButtononPress={() => this.props.navigation.goBack()}title="Go back home"/>);}}const styles = StyleSheet.create({icon: {width: 26,height: 26,},});const MyApp = TabNavigator({Home: {screen: MyHomeScreen,},Notifications: {screen: MyNotificationsScreen,},}, {tabBarPosition: 'top',animationEnabled: true,tabBarOptions: {activeTintColor: '#e91e63',},});
API说明
TabNavigator(RouteConfigs, TabNavigatorConfig)
RouteConfigs
路由配置对象是从路由名称到路由配置的映射,告诉navigator该路由渲染什么。参见StackNavigator示例。
