react-native-navigation的迁移库

app.js 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. import {createStore, applyMiddleware, combineReducers} from 'redux';
  2. import {Provider} from 'react-redux';
  3. import {Navigation} from 'react-native-navigation';
  4. import thunk from 'redux-thunk';
  5. import * as reducers from './reducers';
  6. import * as appActions from './reducers/app/actions';
  7. // redux related book keeping
  8. const createStoreWithMiddleware = applyMiddleware(thunk)(createStore);
  9. const reducer = combineReducers(reducers);
  10. const store = createStoreWithMiddleware(reducer);
  11. // screen related book keeping
  12. import {registerScreens} from './screens';
  13. registerScreens(store, Provider);
  14. // notice that this is just a simple class, it's not a React component
  15. export default class App {
  16. constructor() {
  17. // since react-redux only works on components, we need to subscribe this class manually
  18. store.subscribe(this.onStoreUpdate.bind(this));
  19. store.dispatch(appActions.appInitialized());
  20. }
  21. onStoreUpdate() {
  22. const {root} = store.getState().app;
  23. // handle a root change
  24. // if your app doesn't change roots in runtime, you can remove onStoreUpdate() altogether
  25. if (this.currentRoot != root) {
  26. this.currentRoot = root;
  27. this.startApp(root);
  28. }
  29. }
  30. startApp(root) {
  31. switch (root) {
  32. case 'login':
  33. Navigation.startSingleScreenApp({
  34. screen: {
  35. screen: 'example.LoginScreen',
  36. title: 'Login',
  37. navigatorStyle: {}
  38. },
  39. passProps: {
  40. str: 'This is a prop passed in \'startSingleScreenApp()\'!',
  41. obj: {
  42. str: 'This is a prop passed in an object!',
  43. arr: [
  44. {
  45. str: 'This is a prop in an object in an array in an object!'
  46. }
  47. ],
  48. arr2: [
  49. [
  50. 'array of strings',
  51. 'with two strings'
  52. ],
  53. [
  54. 1, 2, 3
  55. ]
  56. ]
  57. },
  58. num: 1234,
  59. fn: function() {
  60. return 'Hello from a function!';
  61. }
  62. }
  63. });
  64. // Navigation.startSingleScreenApp({
  65. // screen: {
  66. // screen: 'example.FirstTabScreen',
  67. // title: 'Login',
  68. // topTabs: [
  69. // {
  70. // screenId: 'example.ListScreen',
  71. // title: 'Tab1',
  72. // passProps: {
  73. // str: 'This is a prop passed to Tab1'
  74. // }
  75. // },
  76. // {
  77. // screenId: 'example.PushedScreen',
  78. // title: 'Tab2',
  79. // passProps: {
  80. // str: 'This is a prop passed to Tab2'
  81. // }
  82. //
  83. // },
  84. // {
  85. // screenId: 'example.PushedScreen',
  86. // title: 'Tab3',
  87. // passProps: {
  88. // str: 'This is a prop passed to Tab3'
  89. // }
  90. // },
  91. // {
  92. // screenId: 'example.FirstTabScreen',
  93. // title: 'Tab4',
  94. // passProps: {
  95. // str: 'This is a prop passed to Tab4',
  96. // fn: () => 'Hello from a function passed as passProps!'
  97. // }
  98. // }
  99. // ],
  100. // navigatorStyle: {}
  101. // },
  102. // drawer: { // optional, add this if you want a side menu drawer in your app
  103. // left: { // optional, define if you want a drawer from the left
  104. // screen: 'example.SideMenu' // unique ID registered with Navigation.registerScreen
  105. // },
  106. // disableOpenGesture: false // optional, can the drawer be opened with a swipe instead of button
  107. // }
  108. // });
  109. return;
  110. case 'after-login':
  111. Navigation.startTabBasedApp({
  112. tabs: [
  113. {
  114. label: 'One',
  115. screen: 'example.FirstTabScreen',
  116. icon: require('../img/one.png'),
  117. selectedIcon: require('../img/one_selected.png'),
  118. title: 'Screen One',
  119. overrideBackPress: true,
  120. navigatorStyle: {}
  121. },
  122. {
  123. label: 'Two',
  124. screen: 'example.SecondTabScreen',
  125. icon: require('../img/two.png'),
  126. selectedIcon: require('../img/two_selected.png'),
  127. title: 'Screen Two',
  128. navigatorStyle: {}
  129. }
  130. ],
  131. passProps: {
  132. str: 'This is a prop passed in \'startTabBasedApp\'!',
  133. obj: {
  134. str: 'This is a prop passed in an object!',
  135. arr: [
  136. {
  137. str: 'This is a prop in an object in an array in an object!'
  138. }
  139. ]
  140. },
  141. num: 1234
  142. },
  143. animationType: 'slide-down',
  144. title: 'Redux Example',
  145. drawer: { // optional, add this if you want a side menu drawer in your app
  146. left: { // optional, define if you want a drawer from the left
  147. screen: 'example.BottomTabsSideMenu' // unique ID registered with Navigation.registerScreen
  148. },
  149. disableOpenGesture: false, // optional, can the drawer be opened with a swipe instead of button
  150. passProps: {
  151. title: 'Hello from SideMenu'
  152. }
  153. }
  154. });
  155. return;
  156. default:
  157. console.error('Unknown app root');
  158. }
  159. }
  160. }