StackWithHeaderPreset.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /**
  2. * @flow
  3. */
  4. import type { NavigationScreenProp } from 'react-navigation';
  5. import * as React from 'react';
  6. import { ScrollView, StatusBar } from 'react-native';
  7. import { createStackNavigator, SafeAreaView } from 'react-navigation';
  8. import invariant from 'invariant';
  9. import { Button } from './commonComponents/ButtonWithMargin';
  10. type NavScreenProps = {
  11. navigation: NavigationScreenProp<*>,
  12. };
  13. class HomeScreen extends React.Component<NavScreenProps> {
  14. static navigationOptions = {
  15. title: 'Welcome',
  16. };
  17. render() {
  18. const { navigation } = this.props;
  19. const { push } = navigation;
  20. invariant(push, 'missing `push` action creator for StackNavigator');
  21. return (
  22. <SafeAreaView style={{ paddingTop: 30 }}>
  23. <Button onPress={() => push('Other')} title="Push another screen" />
  24. <Button
  25. onPress={() => push('ScreenWithNoHeader')}
  26. title="Push screen with no header"
  27. />
  28. <Button onPress={() => navigation.goBack(null)} title="Go Home" />
  29. <StatusBar barStyle="default" />
  30. </SafeAreaView>
  31. );
  32. }
  33. }
  34. class OtherScreen extends React.Component<NavScreenProps> {
  35. static navigationOptions = {
  36. title: 'Your title here',
  37. };
  38. render() {
  39. const { navigation } = this.props;
  40. const { push, pop } = navigation;
  41. invariant(push && pop, 'missing action creators for StackNavigator');
  42. return (
  43. <SafeAreaView style={{ paddingTop: 30 }}>
  44. <Button
  45. onPress={() => push('ScreenWithLongTitle')}
  46. title="Push another screen"
  47. />
  48. <Button
  49. onPress={() => push('ScreenWithNoHeader')}
  50. title="Push screen with no header"
  51. />
  52. <Button onPress={() => pop()} title="Pop" />
  53. <Button onPress={() => navigation.goBack(null)} title="Go back" />
  54. <StatusBar barStyle="default" />
  55. </SafeAreaView>
  56. );
  57. }
  58. }
  59. class ScreenWithLongTitle extends React.Component<NavScreenProps> {
  60. static navigationOptions = {
  61. title: "Another title that's kind of long",
  62. };
  63. render() {
  64. const { navigation } = this.props;
  65. const { pop } = navigation;
  66. invariant(pop, 'missing `pop` action creator for StackNavigator');
  67. return (
  68. <SafeAreaView style={{ paddingTop: 30 }}>
  69. <Button onPress={() => pop()} title="Pop" />
  70. <Button onPress={() => navigation.goBack(null)} title="Go back" />
  71. <StatusBar barStyle="default" />
  72. </SafeAreaView>
  73. );
  74. }
  75. }
  76. class ScreenWithNoHeader extends React.Component<NavScreenProps> {
  77. static navigationOptions = {
  78. header: null,
  79. title: 'No Header',
  80. };
  81. render() {
  82. const { navigation } = this.props;
  83. const { push, pop } = navigation;
  84. invariant(push && pop, 'missing action creators for StackNavigator');
  85. return (
  86. <SafeAreaView style={{ paddingTop: 30 }}>
  87. <Button onPress={() => push('Other')} title="Push another screen" />
  88. <Button onPress={() => pop()} title="Pop" />
  89. <Button onPress={() => navigation.goBack(null)} title="Go back" />
  90. <StatusBar barStyle="default" />
  91. </SafeAreaView>
  92. );
  93. }
  94. }
  95. const StackWithHeaderPreset = createStackNavigator(
  96. {
  97. Home: HomeScreen,
  98. Other: OtherScreen,
  99. ScreenWithNoHeader: ScreenWithNoHeader,
  100. ScreenWithLongTitle: ScreenWithLongTitle,
  101. },
  102. {
  103. headerTransitionPreset: 'uikit',
  104. }
  105. );
  106. export default StackWithHeaderPreset;