react-native-navigation的迁移库

platformSpecific.android.js 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 setScreenTitleBarButtons(screenInstanceID, navigatorEventID, rightButtons, leftButton) {
  37. NativeReactModule.setScreenTitleBarButtons(screenInstanceID, navigatorEventID, rightButtons, leftButton);
  38. }
  39. function showModal(screenParams) {
  40. savePassProps(screenParams);
  41. NativeReactModule.showModal(screenParams);
  42. }
  43. function dismissTopModal() {
  44. NativeReactModule.dismissTopModal();
  45. }
  46. function dismissAllModals() {
  47. NativeReactModule.dismissAllModals();
  48. }
  49. function savePassProps(params) {
  50. if (params.navigationParams && params.passProps) {
  51. PropRegistry.save(params.navigationParams.screenInstanceID, params.passProps);
  52. }
  53. if (params.screen && params.screen.passProps) {
  54. PropRegistry.save(params.screen.navigationParams.screenInstanceID, params.screen.passProps);
  55. }
  56. if (_.get(params, 'screen.topTabs')) {
  57. _.forEach(params.screen.topTabs, (tab) => savePassProps(tab));
  58. }
  59. if (params.topTabs) {
  60. _.forEach(params.topTabs, (tab) => savePassProps(tab));
  61. }
  62. if (params.tabs) {
  63. _.forEach(params.tabs, (tab) => {
  64. if (!tab.passProps) {
  65. tab.passProps = params.passProps;
  66. }
  67. savePassProps(tab);
  68. });
  69. }
  70. if (params.sideMenu) {
  71. PropRegistry.save(params.sideMenu.navigationParams.screenInstanceID, params.sideMenu.passProps);
  72. }
  73. }
  74. function toggleSideMenuVisible(animated) {
  75. NativeReactModule.toggleSideMenuVisible(animated);
  76. }
  77. function setSideMenuVisible(animated, visible) {
  78. NativeReactModule.setSideMenuVisible(animated, visible);
  79. }
  80. function selectBottomTabByNavigatorId(navigatorId) {
  81. NativeReactModule.selectBottomTabByNavigatorId(navigatorId);
  82. }
  83. function selectBottomTabByTabIndex(index) {
  84. NativeReactModule.selectBottomTabByTabIndex(index);
  85. }
  86. function setBottomTabBadgeByIndex(index, badge) {
  87. NativeReactModule.setBottomTabBadgeByIndex(index, badge);
  88. }
  89. function setBottomTabBadgeByNavigatorId(navigatorId, badge) {
  90. NativeReactModule.setBottomTabBadgeByNavigatorId(navigatorId, badge);
  91. }
  92. function showSnackbar(params) {
  93. NativeReactModule.showSnackbar(params);
  94. }
  95. module.exports = {
  96. startApp,
  97. push,
  98. pop,
  99. popToRoot,
  100. newStack,
  101. toggleTopBarVisible,
  102. toggleBottomTabsVisible,
  103. setScreenTitleBarTitle,
  104. setScreenTitleBarSubtitle,
  105. setScreenTitleBarButtons,
  106. showModal,
  107. dismissTopModal,
  108. dismissAllModals,
  109. toggleSideMenuVisible,
  110. setSideMenuVisible,
  111. selectBottomTabByNavigatorId,
  112. selectBottomTabByTabIndex,
  113. setBottomTabBadgeByNavigatorId,
  114. setBottomTabBadgeByIndex,
  115. showSnackbar
  116. };