Drawer.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /**
  2. * @flow
  3. */
  4. import React from 'react';
  5. import { Platform, ScrollView, StatusBar } from 'react-native';
  6. import {
  7. createStackNavigator,
  8. createDrawerNavigator,
  9. SafeAreaView,
  10. } from 'react-navigation';
  11. import MaterialIcons from 'react-native-vector-icons/MaterialIcons';
  12. import SampleText from './SampleText';
  13. import { Button } from './commonComponents/ButtonWithMargin';
  14. const MyNavScreen = ({ navigation, banner }) => (
  15. <ScrollView>
  16. <SafeAreaView forceInset={{ top: 'always' }}>
  17. <SampleText>{banner}</SampleText>
  18. <Button onPress={() => navigation.openDrawer()} title="Open drawer" />
  19. <Button
  20. onPress={() => navigation.navigate('Email')}
  21. title="Open other screen"
  22. />
  23. <Button onPress={() => navigation.goBack(null)} title="Go back" />
  24. </SafeAreaView>
  25. <StatusBar barStyle="default" />
  26. </ScrollView>
  27. );
  28. const InboxScreen = ({ navigation }) => (
  29. <MyNavScreen banner={'Inbox Screen'} navigation={navigation} />
  30. );
  31. InboxScreen.navigationOptions = {
  32. headerTitle: 'Inbox',
  33. };
  34. const EmailScreen = ({ navigation }) => (
  35. <MyNavScreen banner={'Email Screen'} navigation={navigation} />
  36. );
  37. const DraftsScreen = ({ navigation }) => (
  38. <MyNavScreen banner={'Drafts Screen'} navigation={navigation} />
  39. );
  40. DraftsScreen.navigationOptions = {
  41. headerTitle: 'Drafts',
  42. };
  43. const InboxStack = createStackNavigator({
  44. Inbox: { screen: InboxScreen },
  45. Email: { screen: EmailScreen },
  46. });
  47. InboxStack.navigationOptions = {
  48. drawerLabel: 'Inbox',
  49. drawerIcon: ({ tintColor }) => (
  50. <MaterialIcons
  51. name="move-to-inbox"
  52. size={24}
  53. style={{ color: tintColor }}
  54. />
  55. ),
  56. };
  57. const DraftsStack = createStackNavigator({
  58. Drafts: { screen: DraftsScreen },
  59. Email: { screen: EmailScreen },
  60. });
  61. DraftsStack.navigationOptions = {
  62. drawerLabel: 'Drafts',
  63. drawerIcon: ({ tintColor }) => (
  64. <MaterialIcons name="drafts" size={24} style={{ color: tintColor }} />
  65. ),
  66. };
  67. const DrawerExample = createDrawerNavigator(
  68. {
  69. Inbox: {
  70. path: '/',
  71. screen: InboxStack,
  72. },
  73. Drafts: {
  74. path: '/sent',
  75. screen: DraftsStack,
  76. },
  77. },
  78. {
  79. initialRouteName: 'Drafts',
  80. contentOptions: {
  81. activeTintColor: '#e91e63',
  82. },
  83. }
  84. );
  85. export default DrawerExample;