react-native-navigation的迁移库

Navigation.js 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import NativeCommandsSender from './adapters/NativeCommandsSender';
  2. import NativeEventsReceiver from './adapters/NativeEventsReceiver';
  3. import UniqueIdProvider from './adapters/UniqueIdProvider';
  4. import Store from './containers/Store';
  5. import ContainerRegistry from './containers/ContainerRegistry';
  6. import AppCommands from './commands/AppCommands';
  7. import ContainerCommands from './commands/ContainerCommands';
  8. import LayoutTreeParser from './commands/LayoutTreeParser';
  9. import LayoutTreeCrawler from './commands/LayoutTreeCrawler';
  10. import PrivateEventsListener from './events/PrivateEventsListener';
  11. import PublicEventsRegistry from './events/PublicEventsRegistry';
  12. class Navigation {
  13. constructor() {
  14. this.store = new Store();
  15. this.nativeEventsReceiver = new NativeEventsReceiver();
  16. this.uniqueIdProvider = new UniqueIdProvider();
  17. this.containerRegistry = new ContainerRegistry(this.store);
  18. this.layoutTreeParser = new LayoutTreeParser();
  19. this.layoutTreeCrawler = new LayoutTreeCrawler(this.uniqueIdProvider, this.store);
  20. this.nativeCommandsSender = new NativeCommandsSender();
  21. this.appCommands = new AppCommands(this.nativeCommandsSender, this.layoutTreeParser, this.layoutTreeCrawler);
  22. this.publicEventsRegistry = new PublicEventsRegistry(this.nativeEventsReceiver);
  23. this.privateEventsListener = new PrivateEventsListener(this.nativeEventsReceiver, this.store);
  24. this.privateEventsListener.listenAndHandlePrivateEvents();
  25. }
  26. registerContainer(containerName, getContainerFunc) {
  27. this.containerRegistry.registerContainer(containerName, getContainerFunc);
  28. }
  29. setRoot(params) {
  30. return this.appCommands.setRoot(params);
  31. }
  32. showModal(params) {
  33. return this.appCommands.showModal(params);
  34. }
  35. dismissModal(id) {
  36. return this.appCommands.dismissModal(id);
  37. }
  38. dismissAllModals() {
  39. return this.appCommands.dismissAllModals();
  40. }
  41. events() {
  42. return this.publicEventsRegistry;
  43. }
  44. on(containerId) {
  45. return new ContainerCommands(containerId, this.nativeCommandsSender, this.layoutTreeParser, this.layoutTreeCrawler);
  46. }
  47. }
  48. const singleton = new Navigation();
  49. export default singleton;