react-native-navigation的迁移库

Navigation.js 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 Commands from './commands/Commands';
  7. import LayoutTreeParser from './commands/LayoutTreeParser';
  8. import LayoutTreeCrawler from './commands/LayoutTreeCrawler';
  9. import PrivateEventsListener from './events/PrivateEventsListener';
  10. import PublicEventsRegistry from './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. events() {
  56. return this.publicEventsRegistry;
  57. }
  58. }
  59. const singleton = new Navigation();
  60. export default singleton;