react-native-navigation的迁移库

platformSpecific.android.js 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. import React, {Component} from 'react';
  2. import {AppRegistry, NativeModules} from 'react-native';
  3. import _ from 'lodash';
  4. import PropRegistry from './PropRegistry';
  5. const NativeReactModule = NativeModules.NavigationReactModule;
  6. function startApp(activityParams) {
  7. savePassProps(activityParams);
  8. NativeReactModule.startApp(activityParams);
  9. }
  10. function push(screenParams) {
  11. savePassProps(screenParams);
  12. NativeReactModule.push(screenParams);
  13. }
  14. function pop(screenParams) {
  15. NativeReactModule.pop(screenParams);
  16. }
  17. function popToRoot(screenParams) {
  18. NativeReactModule.popToRoot(screenParams);
  19. }
  20. function newStack(screenParams) {
  21. savePassProps(screenParams);
  22. NativeReactModule.newStack(screenParams);
  23. }
  24. function toggleTopBarVisible(screenInstanceID, visible, animated) {
  25. NativeReactModule.setTopBarVisible(screenInstanceID, visible, animated);
  26. }
  27. function toggleBottomTabsVisible(visible, animated) {
  28. NativeReactModule.setBottomTabsVisible(visible, animated);
  29. }
  30. function setScreenTitleBarTitle(screenInstanceID, title) {
  31. NativeReactModule.setScreenTitleBarTitle(screenInstanceID, title);
  32. }
  33. function setScreenTitleBarSubtitle(screenInstanceID, subtitle) {
  34. NativeReactModule.setScreenTitleBarSubtitle(screenInstanceID, subtitle);
  35. }
  36. function setScreenButtons(screenInstanceID, navigatorEventID, rightButtons, leftButton, fab) {
  37. NativeReactModule.setScreenButtons(screenInstanceID, navigatorEventID, rightButtons, leftButton, fab);
  38. }
  39. function showModal(screenParams) {
  40. savePassProps(screenParams);
  41. NativeReactModule.showModal(screenParams);
  42. }
  43. function showLightBox(params) {
  44. savePassProps(params);
  45. NativeReactModule.showLightBox(params);
  46. }
  47. function dismissLightBox() {
  48. NativeReactModule.dismissLightBox();
  49. }
  50. function dismissTopModal() {
  51. NativeReactModule.dismissTopModal();
  52. }
  53. function dismissAllModals() {
  54. NativeReactModule.dismissAllModals();
  55. }
  56. function showInAppNotification(params) {
  57. savePassProps(params);
  58. NativeReactModule.showSlidingOverlay(params);
  59. }
  60. function dismissInAppNotification(params) {
  61. NativeReactModule.hideSlidingOverlay(params);
  62. }
  63. function savePassProps(params) {
  64. if (params.navigationParams && params.passProps) {
  65. PropRegistry.save(params.navigationParams.screenInstanceID, params.passProps);
  66. }
  67. if (params.screen && params.screen.passProps) {
  68. PropRegistry.save(params.screen.navigationParams.screenInstanceID, params.screen.passProps);
  69. }
  70. if (_.get(params, 'screen.topTabs')) {
  71. _.forEach(params.screen.topTabs, (tab) => savePassProps(tab));
  72. }
  73. if (params.topTabs) {
  74. _.forEach(params.topTabs, (tab) => savePassProps(tab));
  75. }
  76. if (params.tabs) {
  77. _.forEach(params.tabs, (tab) => {
  78. if (!tab.passProps) {
  79. tab.passProps = params.passProps;
  80. }
  81. savePassProps(tab);
  82. });
  83. }
  84. if (params.sideMenu && params.sideMenu.left) {
  85. PropRegistry.save(params.sideMenu.left.navigationParams.screenInstanceID, params.sideMenu.left.passProps);
  86. }
  87. if (params.sideMenu && params.sideMenu.right) {
  88. PropRegistry.save(params.sideMenu.right.navigationParams.screenInstanceID, params.sideMenu.right.passProps);
  89. }
  90. }
  91. function toggleSideMenuVisible(animated, side) {
  92. NativeReactModule.toggleSideMenuVisible(animated, side);
  93. }
  94. function setSideMenuVisible(animated, visible, side) {
  95. NativeReactModule.setSideMenuVisible(animated, visible, side);
  96. }
  97. function setSideMenuEnabled(enabled, side) {
  98. NativeReactModule.setSideMenuEnabled(enabled, side);
  99. }
  100. function selectTopTabByTabIndex(screenInstanceId, index) {
  101. NativeReactModule.selectTopTabByTabIndex(screenInstanceId, index);
  102. }
  103. function selectTopTabByScreen(screenInstanceId) {
  104. NativeReactModule.selectTopTabByScreen(screenInstanceId);
  105. }
  106. function selectBottomTabByNavigatorId(navigatorId) {
  107. NativeReactModule.selectBottomTabByNavigatorId(navigatorId);
  108. }
  109. function selectBottomTabByTabIndex(index) {
  110. NativeReactModule.selectBottomTabByTabIndex(index);
  111. }
  112. function setBottomTabBadgeByIndex(index, badge) {
  113. NativeReactModule.setBottomTabBadgeByIndex(index, badge);
  114. }
  115. function setBottomTabBadgeByNavigatorId(navigatorId, badge) {
  116. NativeReactModule.setBottomTabBadgeByNavigatorId(navigatorId, badge);
  117. }
  118. function setBottomTabButtonByIndex(index, params) {
  119. NativeReactModule.setBottomTabButtonByIndex(index, params);
  120. }
  121. function setBottomTabButtonByNavigatorId(navigatorId, params) {
  122. NativeReactModule.setBottomTabButtonByNavigatorId(navigatorId, params);
  123. }
  124. function showSnackbar(params) {
  125. NativeReactModule.showSnackbar(params);
  126. }
  127. function dismissSnackbar() {
  128. NativeReactModule.dismissSnackbar();
  129. }
  130. function showContextualMenu(screenInstanceID, params, onButtonPressed) {
  131. NativeReactModule.showContextualMenu(screenInstanceID, params, onButtonPressed);
  132. }
  133. function dismissContextualMenu(screenInstanceID) {
  134. NativeReactModule.dismissContextualMenu(screenInstanceID);
  135. }
  136. function setScreenStyle(screenInstanceId, style) {
  137. NativeReactModule.setScreenStyle(screenInstanceId, style);
  138. }
  139. async function isAppLaunched() {
  140. return await NativeReactModule.isAppLaunched();
  141. }
  142. async function isRootLaunched() {
  143. return await NativeReactModule.isRootLaunched();
  144. }
  145. async function getCurrentlyVisibleScreenId() {
  146. return await NativeReactModule.getCurrentlyVisibleScreenId();
  147. }
  148. module.exports = {
  149. startApp,
  150. push,
  151. pop,
  152. popToRoot,
  153. newStack,
  154. toggleTopBarVisible,
  155. toggleBottomTabsVisible,
  156. setScreenTitleBarTitle,
  157. setScreenTitleBarSubtitle,
  158. setScreenButtons,
  159. showModal,
  160. dismissTopModal,
  161. dismissAllModals,
  162. showLightBox,
  163. dismissLightBox,
  164. selectTopTabByScreen,
  165. selectTopTabByTabIndex,
  166. showInAppNotification,
  167. dismissInAppNotification,
  168. toggleSideMenuVisible,
  169. setSideMenuVisible,
  170. setSideMenuEnabled,
  171. selectBottomTabByNavigatorId,
  172. selectBottomTabByTabIndex,
  173. setBottomTabBadgeByNavigatorId,
  174. setBottomTabBadgeByIndex,
  175. setBottomTabButtonByNavigatorId,
  176. setBottomTabButtonByIndex,
  177. showSnackbar,
  178. dismissSnackbar,
  179. showContextualMenu,
  180. dismissContextualMenu,
  181. setScreenStyle,
  182. isAppLaunched,
  183. isRootLaunched,
  184. getCurrentlyVisibleScreenId
  185. };