react-native-navigation的迁移库

app.js 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. });
  40. return;
  41. case 'after-login':
  42. Navigation.startTabBasedApp({
  43. tabs: [
  44. {
  45. label: 'One',
  46. screen: 'example.FirstTabScreen',
  47. icon: require('../img/one.png'),
  48. selectedIcon: require('../img/one_selected.png'),
  49. title: 'Screen One',
  50. navigatorStyle: {}
  51. },
  52. {
  53. label: 'Two',
  54. screen: 'example.SecondTabScreen',
  55. icon: require('../img/two.png'),
  56. selectedIcon: require('../img/two_selected.png'),
  57. title: 'Screen Two',
  58. navigatorStyle: {}
  59. }
  60. ],
  61. animationType: 'slide-down',
  62. title: 'Redux Example'
  63. });
  64. return;
  65. default:
  66. console.error('Unknown app root');
  67. }
  68. }
  69. }