react-native-navigation的迁移库

platformSpecific.android.js 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. //TODO this needs to be handled in a common place,
  51. //TODO also, all global passProps should be handled differently
  52. if (params.navigationParams && params.passProps) {
  53. PropRegistry.save(params.navigationParams.screenInstanceID, params.passProps);
  54. }
  55. if (params.screen && params.screen.passProps) {
  56. PropRegistry.save(params.screen.navigationParams.screenInstanceID, params.screen.passProps);
  57. }
  58. if (_.get(params, 'screen.topTabs')) {
  59. _.forEach(params.screen.topTabs, (tab) => savePassProps(tab));
  60. }
  61. if (params.tabs) {
  62. _.forEach(params.tabs, (tab) => {
  63. tab.passProps = params.passProps;
  64. savePassProps(tab);
  65. });
  66. }
  67. if (params.sideMenu) {
  68. PropRegistry.save(params.sideMenu.navigationParams.screenInstanceID, params.sideMenu.passProps);
  69. }
  70. }
  71. function toggleSideMenuVisible(animated) {
  72. NativeReactModule.toggleSideMenuVisible(animated);
  73. }
  74. function setSideMenuVisible(animated, visible) {
  75. NativeReactModule.setSideMenuVisible(animated, visible);
  76. }
  77. function selectBottomTabByNavigatorId(navigatorId) {
  78. NativeReactModule.selectBottomTabByNavigatorId(navigatorId);
  79. }
  80. function selectBottomTabByTabIndex(index) {
  81. NativeReactModule.selectBottomTabByTabIndex(index);
  82. }
  83. function setBottomTabBadgeByIndex(index, badge) {
  84. NativeReactModule.setBottomTabBadgeByIndex(index, badge);
  85. }
  86. function setBottomTabBadgeByNavigatorId(navigatorId, badge) {
  87. NativeReactModule.setBottomTabBadgeByNavigatorId(navigatorId, badge);
  88. }
  89. function showSnackbar(params) {
  90. NativeReactModule.showSnackbar(params);
  91. }
  92. module.exports = {
  93. startApp,
  94. push,
  95. pop,
  96. popToRoot,
  97. newStack,
  98. toggleTopBarVisible,
  99. toggleBottomTabsVisible,
  100. setScreenTitleBarTitle,
  101. setScreenTitleBarSubtitle,
  102. setScreenTitleBarButtons,
  103. showModal,
  104. dismissTopModal,
  105. dismissAllModals,
  106. toggleSideMenuVisible,
  107. setSideMenuVisible,
  108. selectBottomTabByNavigatorId,
  109. selectBottomTabByTabIndex,
  110. setBottomTabBadgeByNavigatorId,
  111. setBottomTabBadgeByIndex,
  112. showSnackbar
  113. };