react-native-navigation的迁移库

Navigation.js 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. const NativeCommandsSender = require('./adapters/NativeCommandsSender');
  2. const NativeEventsReceiver = require('./adapters/NativeEventsReceiver');
  3. const UniqueIdProvider = require('./adapters/UniqueIdProvider');
  4. const Store = require('./containers/Store');
  5. const ContainerRegistry = require('./containers/ContainerRegistry');
  6. const Commands = require('./commands/Commands');
  7. const LayoutTreeParser = require('./commands/LayoutTreeParser');
  8. const LayoutTreeCrawler = require('./commands/LayoutTreeCrawler');
  9. const PrivateEventsListener = require('./events/PrivateEventsListener');
  10. const PublicEventsRegistry = require('./events/PublicEventsRegistry');
  11. class Navigation {
  12. constructor() {
  13. this.store = new Store();
  14. this.nativeEventsReceiver = new NativeEventsReceiver();
  15. this.uniqueIdProvider = new UniqueIdProvider();
  16. this.containerRegistry = new ContainerRegistry(this.store);
  17. this.layoutTreeParser = new LayoutTreeParser();
  18. this.layoutTreeCrawler = new LayoutTreeCrawler(this.uniqueIdProvider, this.store);
  19. this.nativeCommandsSender = new NativeCommandsSender();
  20. this.commands = new Commands(this.nativeCommandsSender, this.layoutTreeParser, this.layoutTreeCrawler);
  21. this.publicEventsRegistry = new PublicEventsRegistry(this.nativeEventsReceiver);
  22. this.privateEventsListener = new PrivateEventsListener(this.nativeEventsReceiver, this.store);
  23. this.privateEventsListener.listenAndHandlePrivateEvents();
  24. }
  25. registerContainer(containerName, getContainerFunc) {
  26. this.containerRegistry.registerContainer(containerName, getContainerFunc);
  27. }
  28. setRoot(params) {
  29. return this.commands.setRoot(params);
  30. }
  31. setOptions(containerId, options) {
  32. this.commands.setOptions(containerId, options);
  33. }
  34. showModal(params) {
  35. return this.commands.showModal(params);
  36. }
  37. dismissModal(containerId) {
  38. return this.commands.dismissModal(containerId);
  39. }
  40. dismissAllModals() {
  41. return this.commands.dismissAllModals();
  42. }
  43. push(onContainerId, params) {
  44. return this.commands.push(onContainerId, params);
  45. }
  46. pop(containerId) {
  47. return this.commands.pop(containerId);
  48. }
  49. popTo(containerId) {
  50. return this.commands.popTo(containerId);
  51. }
  52. popToRoot(containerId) {
  53. return this.commands.popToRoot(containerId);
  54. }
  55. switchToTab(onContainerId, tabIndex) {
  56. return this.commands.switchToTab(onContainerId, tabIndex);
  57. }
  58. events() {
  59. return this.publicEventsRegistry;
  60. }
  61. showOverlay(type, options) {
  62. return this.commands.showOverlay(type, options);
  63. }
  64. }
  65. const singleton = new Navigation();
  66. module.exports = singleton;