StacksOverTabs.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /**
  2. * @flow
  3. */
  4. import React from 'react';
  5. import { ScrollView, StatusBar } from 'react-native';
  6. import {
  7. SafeAreaView,
  8. createStackNavigator,
  9. createBottomTabNavigator,
  10. } from 'react-navigation';
  11. import Ionicons from 'react-native-vector-icons/Ionicons';
  12. import SampleText from './SampleText';
  13. import { Button } from './commonComponents/ButtonWithMargin';
  14. const MyNavScreen = ({ navigation, banner }) => (
  15. <ScrollView>
  16. <SafeAreaView forceInset={{ horizontal: 'always' }}>
  17. <SampleText>{banner}</SampleText>
  18. <Button
  19. onPress={() => navigation.navigate('Profile', { name: 'Jordan' })}
  20. title="Open profile screen"
  21. />
  22. <Button
  23. onPress={() => navigation.navigate('NotifSettings')}
  24. title="Open notifications screen"
  25. />
  26. <Button
  27. onPress={() => navigation.navigate('SettingsTab')}
  28. title="Go to settings tab"
  29. />
  30. <Button onPress={() => navigation.goBack(null)} title="Go back" />
  31. </SafeAreaView>
  32. <StatusBar barStyle="default" />
  33. </ScrollView>
  34. );
  35. const MyHomeScreen = ({ navigation }) => (
  36. <MyNavScreen banner="Home Screen" navigation={navigation} />
  37. );
  38. const MyProfileScreen = ({ navigation }) => (
  39. <MyNavScreen
  40. banner={`${navigation.state.params.name}s Profile`}
  41. navigation={navigation}
  42. />
  43. );
  44. const MyNotificationsSettingsScreen = ({ navigation }) => (
  45. <MyNavScreen banner="Notifications Screen" navigation={navigation} />
  46. );
  47. const MySettingsScreen = ({ navigation }) => (
  48. <MyNavScreen banner="Settings Screen" navigation={navigation} />
  49. );
  50. const TabNav = createBottomTabNavigator(
  51. {
  52. MainTab: {
  53. screen: MyHomeScreen,
  54. path: '/',
  55. navigationOptions: {
  56. title: 'Welcome',
  57. tabBarLabel: 'Home',
  58. tabBarIcon: ({ tintColor, focused }) => (
  59. <Ionicons
  60. name={focused ? 'ios-home' : 'ios-home-outline'}
  61. size={26}
  62. style={{ color: tintColor }}
  63. />
  64. ),
  65. },
  66. },
  67. SettingsTab: {
  68. screen: MySettingsScreen,
  69. path: '/settings',
  70. navigationOptions: {
  71. title: 'Settings',
  72. tabBarIcon: ({ tintColor, focused }) => (
  73. <Ionicons
  74. name={focused ? 'ios-settings' : 'ios-settings-outline'}
  75. size={26}
  76. style={{ color: tintColor }}
  77. />
  78. ),
  79. },
  80. },
  81. },
  82. {
  83. tabBarPosition: 'bottom',
  84. animationEnabled: false,
  85. swipeEnabled: false,
  86. }
  87. );
  88. TabNav.navigationOptions = ({ navigation }) => {
  89. let { routeName } = navigation.state.routes[navigation.state.index];
  90. let title;
  91. if (routeName === 'SettingsTab') {
  92. title = 'Settings';
  93. } else if (routeName === 'MainTab') {
  94. title = 'Home';
  95. }
  96. return {
  97. title,
  98. };
  99. };
  100. const StacksOverTabs = createStackNavigator({
  101. Root: {
  102. screen: TabNav,
  103. },
  104. NotifSettings: {
  105. screen: MyNotificationsSettingsScreen,
  106. navigationOptions: {
  107. title: 'Notifications',
  108. },
  109. },
  110. Profile: {
  111. screen: MyProfileScreen,
  112. path: '/people/:name',
  113. navigationOptions: ({ navigation }) => ({
  114. title: `${navigation.state.params.name}'s Profile!`,
  115. }),
  116. },
  117. });
  118. export default StacksOverTabs;