react-native-navigation的迁移库

NativeCommandsSender.ts 3.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import { NativeModules } from 'react-native';
  2. interface NativeCommandsModule {
  3. setRoot(commandId: string, layout: { root: any; modals: any[]; overlays: any[] }): Promise<any>;
  4. setDefaultOptions(options: object): void;
  5. mergeOptions(componentId: string, options: object): void;
  6. push(commandId: string, onComponentId: string, layout: object): Promise<any>;
  7. pop(commandId: string, componentId: string, options?: object): Promise<any>;
  8. popTo(commandId: string, componentId: string, options?: object): Promise<any>;
  9. popToRoot(commandId: string, componentId: string, options?: object): Promise<any>;
  10. setStackRoot(commandId: string, onComponentId: string, layout: object): Promise<any>;
  11. showModal(commandId: string, layout: object): Promise<any>;
  12. dismissModal(commandId: string, componentId: string, options?: object): Promise<any>;
  13. dismissAllModals(commandId: string, options?: object): Promise<any>;
  14. showOverlay(commandId: string, layout: object): Promise<any>;
  15. dismissOverlay(commandId: string, componentId: string): Promise<any>;
  16. getLaunchArgs(commandId: string): Promise<any>;
  17. }
  18. export class NativeCommandsSender {
  19. private readonly nativeCommandsModule: NativeCommandsModule;
  20. constructor() {
  21. this.nativeCommandsModule = NativeModules.RNNBridgeModule;
  22. }
  23. setRoot(commandId: string, layout: { root: any; modals: any[]; overlays: any[] }) {
  24. return this.nativeCommandsModule.setRoot(commandId, layout);
  25. }
  26. setDefaultOptions(options: object) {
  27. return this.nativeCommandsModule.setDefaultOptions(options);
  28. }
  29. mergeOptions(componentId: string, options: object) {
  30. return this.nativeCommandsModule.mergeOptions(componentId, options);
  31. }
  32. push(commandId: string, onComponentId: string, layout: object) {
  33. return this.nativeCommandsModule.push(commandId, onComponentId, layout);
  34. }
  35. pop(commandId: string, componentId: string, options?: object) {
  36. return this.nativeCommandsModule.pop(commandId, componentId, options);
  37. }
  38. popTo(commandId: string, componentId: string, options?: object) {
  39. return this.nativeCommandsModule.popTo(commandId, componentId, options);
  40. }
  41. popToRoot(commandId: string, componentId: string, options?: object) {
  42. return this.nativeCommandsModule.popToRoot(commandId, componentId, options);
  43. }
  44. setStackRoot(commandId: string, onComponentId: string, layout: object) {
  45. return this.nativeCommandsModule.setStackRoot(commandId, onComponentId, layout);
  46. }
  47. showModal(commandId: string, layout: object) {
  48. return this.nativeCommandsModule.showModal(commandId, layout);
  49. }
  50. dismissModal(commandId: string, componentId: string, options?: object) {
  51. return this.nativeCommandsModule.dismissModal(commandId, componentId, options);
  52. }
  53. dismissAllModals(commandId: string, options?: object) {
  54. return this.nativeCommandsModule.dismissAllModals(commandId, options);
  55. }
  56. showOverlay(commandId: string, layout: object) {
  57. return this.nativeCommandsModule.showOverlay(commandId, layout);
  58. }
  59. dismissOverlay(commandId: string, componentId: string) {
  60. return this.nativeCommandsModule.dismissOverlay(commandId, componentId);
  61. }
  62. getLaunchArgs(commandId: string) {
  63. return this.nativeCommandsModule.getLaunchArgs(commandId);
  64. }
  65. }