StacksInTabs.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 MainTab = createStackNavigator({
  51. Home: {
  52. screen: MyHomeScreen,
  53. path: '/',
  54. navigationOptions: {
  55. title: 'Welcome',
  56. },
  57. },
  58. Profile: {
  59. screen: MyProfileScreen,
  60. path: '/people/:name',
  61. navigationOptions: ({ navigation }) => ({
  62. title: `${navigation.state.params.name}'s Profile!`,
  63. }),
  64. },
  65. });
  66. const SettingsTab = createStackNavigator({
  67. Settings: {
  68. screen: MySettingsScreen,
  69. path: '/',
  70. navigationOptions: () => ({
  71. title: 'Settings',
  72. }),
  73. },
  74. NotifSettings: {
  75. screen: MyNotificationsSettingsScreen,
  76. navigationOptions: {
  77. title: 'Notifications',
  78. },
  79. },
  80. });
  81. const StacksInTabs = createBottomTabNavigator(
  82. {
  83. MainTab: {
  84. screen: MainTab,
  85. path: '/',
  86. navigationOptions: {
  87. tabBarLabel: 'Home',
  88. tabBarIcon: ({ tintColor, focused }) => (
  89. <Ionicons
  90. name={focused ? 'ios-home' : 'ios-home-outline'}
  91. size={26}
  92. style={{ color: tintColor }}
  93. />
  94. ),
  95. },
  96. },
  97. SettingsTab: {
  98. screen: SettingsTab,
  99. path: '/settings',
  100. navigationOptions: {
  101. tabBarLabel: 'Settings',
  102. tabBarIcon: ({ tintColor, focused }) => (
  103. <Ionicons
  104. name={focused ? 'ios-settings' : 'ios-settings-outline'}
  105. size={26}
  106. style={{ color: tintColor }}
  107. />
  108. ),
  109. },
  110. },
  111. },
  112. {
  113. tabBarOptions: {
  114. showLabel: false,
  115. },
  116. }
  117. );
  118. export default StacksInTabs;