TabNavigator

用于使用TabRouter轻松设置带有多个tab的页面。有关实例,请参阅我们的expo demo

  1. class MyHomeScreen extends React.Component {
  2. static navigationOptions = {
  3. tabBarLabel: 'Home',
  4. // Note: By default the icon is only shown on iOS. Search the showIcon option below.
  5. tabBarIcon: ({ tintColor }) => (
  6. <Image
  7. source={require('./chats-icon.png')}
  8. style={[styles.icon, {tintColor: tintColor}]}
  9. />
  10. ),
  11. };
  12. render() {
  13. return (
  14. <Button
  15. onPress={() => this.props.navigation.navigate('Notifications')}
  16. title="Go to notifications"
  17. />
  18. );
  19. }
  20. }
  21. class MyNotificationsScreen extends React.Component {
  22. static navigationOptions = {
  23. tabBarLabel: 'Notifications',
  24. tabBarIcon: ({ tintColor }) => (
  25. <Image
  26. source={require('./notif-icon.png')}
  27. style={[styles.icon, {tintColor: tintColor}]}
  28. />
  29. ),
  30. };
  31. render() {
  32. return (
  33. <Button
  34. onPress={() => this.props.navigation.goBack()}
  35. title="Go back home"
  36. />
  37. );
  38. }
  39. }
  40. const styles = StyleSheet.create({
  41. icon: {
  42. width: 26,
  43. height: 26,
  44. },
  45. });
  46. const MyApp = TabNavigator({
  47. Home: {
  48. screen: MyHomeScreen,
  49. },
  50. Notifications: {
  51. screen: MyNotificationsScreen,
  52. },
  53. }, {
  54. tabBarPosition: 'top',
  55. animationEnabled: true,
  56. tabBarOptions: {
  57. activeTintColor: '#e91e63',
  58. },
  59. });

API说明

  1. TabNavigator(RouteConfigs, TabNavigatorConfig)

RouteConfigs

路由配置对象是从路由名称到路由配置的映射,告诉navigator该路由渲染什么。参见StackNavigator示例

TabNavigatorConfig

未完待续。。。