react-native-navigation的迁移库

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*eslint-disable*/
  2. import React from 'react';
  3. import {AppRegistry} from 'react-native';
  4. import platformSpecific from './deprecated/platformSpecificDeprecated';
  5. import Screen from './Screen';
  6. import PropRegistry from './PropRegistry';
  7. const registeredScreens = {};
  8. function registerScreen(screenID, generator) {
  9. registeredScreens[screenID] = generator;
  10. AppRegistry.registerComponent(screenID, generator);
  11. }
  12. function registerComponent(screenID, generator, store = undefined, Provider = undefined) {
  13. if (store && Provider) {
  14. return _registerComponentRedux(screenID, generator, store, Provider);
  15. } else {
  16. return _registerComponentNoRedux(screenID, generator);
  17. }
  18. }
  19. function _registerComponentNoRedux(screenID, generator) {
  20. const generatorWrapper = function() {
  21. const InternalComponent = generator();
  22. return class extends Screen {
  23. static navigatorStyle = InternalComponent.navigatorStyle || {};
  24. static navigatorButtons = InternalComponent.navigatorButtons || {};
  25. constructor(props) {
  26. super(props);
  27. this.state = {
  28. internalProps: {...props, ...PropRegistry.load(props.screenInstanceID)}
  29. }
  30. }
  31. componentWillReceiveProps(nextProps) {
  32. this.setState({
  33. internalProps: {...PropRegistry.load(this.props.screenInstanceID), ...nextProps}
  34. })
  35. }
  36. render() {
  37. return (
  38. <InternalComponent navigator={this.navigator} {...this.state.internalProps} />
  39. );
  40. }
  41. };
  42. };
  43. registerScreen(screenID, generatorWrapper);
  44. return generatorWrapper;
  45. }
  46. function _registerComponentRedux(screenID, generator, store, Provider) {
  47. const generatorWrapper = function() {
  48. const InternalComponent = generator();
  49. return class extends Screen {
  50. static navigatorStyle = InternalComponent.navigatorStyle || {};
  51. static navigatorButtons = InternalComponent.navigatorButtons || {};
  52. constructor(props) {
  53. super(props);
  54. this.state = {
  55. internalProps: {...props, ...PropRegistry.load(props.screenInstanceID)}
  56. }
  57. }
  58. componentWillReceiveProps(nextProps) {
  59. this.setState({
  60. internalProps: {...PropRegistry.load(this.props.screenInstanceID), ...nextProps}
  61. })
  62. }
  63. render() {
  64. return (
  65. <Provider store={store}>
  66. <InternalComponent navigator={this.navigator} {...this.state.internalProps} />
  67. </Provider>
  68. );
  69. }
  70. };
  71. };
  72. registerScreen(screenID, generatorWrapper);
  73. return generatorWrapper;
  74. }
  75. function getRegisteredScreen(screenID) {
  76. const generator = registeredScreens[screenID];
  77. if (!generator) {
  78. console.error(`Navigation.getRegisteredScreen: ${screenID} used but not yet registered`);
  79. return undefined;
  80. }
  81. return generator();
  82. }
  83. function showModal(params = {}) {
  84. return platformSpecific.showModal(params);
  85. }
  86. function dismissModal(params = {}) {
  87. return platformSpecific.dismissModal(params);
  88. }
  89. function dismissAllModals(params = {}) {
  90. return platformSpecific.dismissAllModals(params);
  91. }
  92. function showLightBox(params = {}) {
  93. return platformSpecific.showLightBox(params);
  94. }
  95. function dismissLightBox(params = {}) {
  96. return platformSpecific.dismissLightBox(params);
  97. }
  98. function showInAppNotification(params = {}) {
  99. return platformSpecific.showInAppNotification(params);
  100. }
  101. function dismissInAppNotification(params = {}) {
  102. return platformSpecific.dismissInAppNotification(params);
  103. }
  104. function startTabBasedApp(params) {
  105. return platformSpecific.startTabBasedApp(params);
  106. }
  107. function startSingleScreenApp(params) {
  108. return platformSpecific.startSingleScreenApp(params);
  109. }
  110. export default {
  111. getRegisteredScreen,
  112. registerComponent,
  113. showModal: showModal,
  114. dismissModal: dismissModal,
  115. dismissAllModals: dismissAllModals,
  116. showLightBox: showLightBox,
  117. dismissLightBox: dismissLightBox,
  118. showInAppNotification: showInAppNotification,
  119. dismissInAppNotification: dismissInAppNotification,
  120. startTabBasedApp: startTabBasedApp,
  121. startSingleScreenApp: startSingleScreenApp
  122. };