hybrid-navigation 2.18.3 → 2.18.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/LICENSE +1 -1
  2. package/android/src/main/java/com/reactnative/hybridnavigation/HBDReactRootView.java +4 -54
  3. package/android/src/main/java/com/reactnative/hybridnavigation/ReactFragment.java +0 -3
  4. package/{lib → dist}/Navigation.js +3 -2
  5. package/{lib → dist}/NavigationComponentWrap.js +6 -5
  6. package/{lib → dist}/Navigator.d.ts +0 -1
  7. package/{lib → dist}/Navigator.js +15 -4
  8. package/{lib → dist}/hooks.js +2 -1
  9. package/{lib → dist}/router/index.js +6 -2
  10. package/{lib → dist}/router/stack.js +1 -1
  11. package/ios/HybridNavigation/HBDUtils.h +2 -0
  12. package/ios/HybridNavigation/HBDUtils.m +12 -3
  13. package/ios/HybridNavigation/ReactBridge/HBDGardenModule.m +2 -6
  14. package/ios/HybridNavigation/ReactBridge/HBDNavigationModule.m +11 -12
  15. package/ios/HybridNavigation/ViewController/HBDDrawerController.m +1 -1
  16. package/ios/HybridNavigation/ViewController/HBDNavigationController.m +1 -1
  17. package/ios/HybridNavigation/ViewController/HBDViewController.m +1 -1
  18. package/package.json +47 -78
  19. package/src/DeepLink.ts +52 -52
  20. package/src/Event.ts +88 -83
  21. package/src/GardenModule.ts +30 -30
  22. package/src/Navigation.ts +293 -281
  23. package/src/NavigationComponentWrap.tsx +52 -47
  24. package/src/NavigationModule.ts +77 -77
  25. package/src/Navigator.ts +212 -201
  26. package/src/Options.ts +120 -112
  27. package/src/Route.ts +59 -59
  28. package/src/handler/BarButtonEventHandler.ts +50 -46
  29. package/src/handler/DispatchCommandHandler.ts +56 -52
  30. package/src/handler/LayoutCommandHandler.ts +21 -21
  31. package/src/handler/ResultEventHandler.ts +63 -49
  32. package/src/handler/VisibilityEventHandler.ts +57 -40
  33. package/src/hooks.ts +23 -21
  34. package/src/index.ts +15 -15
  35. package/src/router/drawer.ts +24 -24
  36. package/src/router/index.ts +206 -198
  37. package/src/router/screen.ts +28 -28
  38. package/src/router/stack.ts +76 -76
  39. package/src/router/tabs.ts +28 -28
  40. package/src/store.ts +9 -9
  41. package/README.md +0 -79
  42. /package/{lib → dist}/DeepLink.d.ts +0 -0
  43. /package/{lib → dist}/DeepLink.js +0 -0
  44. /package/{lib → dist}/Event.d.ts +0 -0
  45. /package/{lib → dist}/Event.js +0 -0
  46. /package/{lib → dist}/GardenModule.d.ts +0 -0
  47. /package/{lib → dist}/GardenModule.js +0 -0
  48. /package/{lib → dist}/Navigation.d.ts +0 -0
  49. /package/{lib → dist}/NavigationComponentWrap.d.ts +0 -0
  50. /package/{lib → dist}/NavigationModule.d.ts +0 -0
  51. /package/{lib → dist}/NavigationModule.js +0 -0
  52. /package/{lib → dist}/Options.d.ts +0 -0
  53. /package/{lib → dist}/Options.js +0 -0
  54. /package/{lib → dist}/Route.d.ts +0 -0
  55. /package/{lib → dist}/Route.js +0 -0
  56. /package/{lib → dist}/handler/BarButtonEventHandler.d.ts +0 -0
  57. /package/{lib → dist}/handler/BarButtonEventHandler.js +0 -0
  58. /package/{lib → dist}/handler/DispatchCommandHandler.d.ts +0 -0
  59. /package/{lib → dist}/handler/DispatchCommandHandler.js +0 -0
  60. /package/{lib → dist}/handler/LayoutCommandHandler.d.ts +0 -0
  61. /package/{lib → dist}/handler/LayoutCommandHandler.js +0 -0
  62. /package/{lib → dist}/handler/ResultEventHandler.d.ts +0 -0
  63. /package/{lib → dist}/handler/ResultEventHandler.js +0 -0
  64. /package/{lib → dist}/handler/VisibilityEventHandler.d.ts +0 -0
  65. /package/{lib → dist}/handler/VisibilityEventHandler.js +0 -0
  66. /package/{lib → dist}/hooks.d.ts +0 -0
  67. /package/{lib → dist}/index.d.ts +0 -0
  68. /package/{lib → dist}/index.js +0 -0
  69. /package/{lib → dist}/router/drawer.d.ts +0 -0
  70. /package/{lib → dist}/router/drawer.js +0 -0
  71. /package/{lib → dist}/router/index.d.ts +0 -0
  72. /package/{lib → dist}/router/screen.d.ts +0 -0
  73. /package/{lib → dist}/router/screen.js +0 -0
  74. /package/{lib → dist}/router/stack.d.ts +0 -0
  75. /package/{lib → dist}/router/tabs.d.ts +0 -0
  76. /package/{lib → dist}/router/tabs.js +0 -0
  77. /package/{lib → dist}/store.d.ts +0 -0
  78. /package/{lib → dist}/store.js +0 -0
package/src/Navigation.ts CHANGED
@@ -1,300 +1,312 @@
1
- import type React from 'react'
2
- import { AppRegistry, ComponentProvider } from 'react-native'
1
+ import type React from 'react';
2
+ import {AppRegistry, ComponentProvider} from 'react-native';
3
3
 
4
4
  import type {
5
- BarButtonItem,
6
- DefaultOptions,
7
- NavigationOption,
8
- TabBarStyle,
9
- TabItemInfo,
10
- TitleItem,
11
- } from './Options'
12
- import type { BuildInLayout, Layout, Route, RouteGraph, RouteConfig } from './Route'
13
-
14
- import BarButtonEventHandler from './handler/BarButtonEventHandler'
15
- import LayoutCommandHandler from './handler/LayoutCommandHandler'
16
- import DispatchCommandHandler from './handler/DispatchCommandHandler'
17
- import ResultEventHandler, { ResultType } from './handler/ResultEventHandler'
5
+ BarButtonItem,
6
+ DefaultOptions,
7
+ NavigationOption,
8
+ TabBarStyle,
9
+ TabItemInfo,
10
+ TitleItem,
11
+ } from './Options';
12
+ import type {BuildInLayout, Layout, Route, RouteGraph, RouteConfig} from './Route';
13
+
14
+ import BarButtonEventHandler from './handler/BarButtonEventHandler';
15
+ import LayoutCommandHandler from './handler/LayoutCommandHandler';
16
+ import DispatchCommandHandler from './handler/DispatchCommandHandler';
17
+ import ResultEventHandler, {ResultType} from './handler/ResultEventHandler';
18
18
  import VisibilityEventHandler, {
19
- GlobalVisibilityEventListener,
20
- VisibilityEventListener,
21
- } from './handler/VisibilityEventHandler'
19
+ GlobalVisibilityEventListener,
20
+ VisibilityEventListener,
21
+ } from './handler/VisibilityEventHandler';
22
22
 
23
- import Event from './Event'
24
- import GardenModule from './GardenModule'
25
- import NavigationModule from './NavigationModule'
23
+ import Event from './Event';
24
+ import GardenModule from './GardenModule';
25
+ import NavigationModule from './NavigationModule';
26
26
 
27
- export type { ResultType } from './handler/ResultEventHandler'
28
- import type { DispatchParams, NavigationInterceptor } from './handler/DispatchCommandHandler'
29
- export type { DispatchParams, NavigationInterceptor } from './handler/DispatchCommandHandler'
27
+ export type {ResultType} from './handler/ResultEventHandler';
28
+ import type {DispatchParams, NavigationInterceptor} from './handler/DispatchCommandHandler';
29
+ export type {DispatchParams, NavigationInterceptor} from './handler/DispatchCommandHandler';
30
30
 
31
- type BarButtonClickEventListener = (sceneId: string, value: Function) => void
31
+ type BarButtonClickEventListener = (sceneId: string, value: Function) => void;
32
32
 
33
33
  type Nullable<T> = {
34
- [P in keyof T]: T[P] extends T[P] | undefined ? T[P] | null : T[P]
35
- }
34
+ [P in keyof T]: T[P] extends T[P] | undefined ? T[P] | null : T[P];
35
+ };
36
36
 
37
- export const { RESULT_CANCEL, RESULT_OK, RESULT_BLOCK } = NavigationModule.getConstants()
37
+ export const {RESULT_CANCEL, RESULT_OK, RESULT_BLOCK} = NavigationModule.getConstants();
38
38
 
39
39
  export type NavigationSubscription = {
40
- remove: () => void
41
- }
40
+ remove: () => void;
41
+ };
42
42
 
43
- export type HOC = (WrappedComponent: React.ComponentType<any>) => React.ComponentType<any>
43
+ export type HOC = (WrappedComponent: React.ComponentType<any>) => React.ComponentType<any>;
44
44
 
45
45
  export interface Navigation {
46
- startRegisterComponent(hoc?: HOC): void
47
- endRegisterComponent(): void
48
- registerComponent(
49
- appKey: string,
50
- getComponentFunc: ComponentProvider,
51
- routeConfig?: RouteConfig,
52
- ): void
53
-
54
- routeConfigs(): Map<string, RouteConfig>
55
- setNavigationComponentWrap(wrap: (moduleName: string) => HOC): void
56
- addGlobalVisibilityEventListener(listener: GlobalVisibilityEventListener): NavigationSubscription
57
- addVisibilityEventListener(
58
- sceneId: string,
59
- listener: VisibilityEventListener,
60
- ): NavigationSubscription
61
- dispatch(sceneId: string, action: string, params?: DispatchParams): Promise<boolean>
62
- setInterceptor(interceptor: NavigationInterceptor): void
63
- setResult<T extends ResultType>(sceneId: string, resultCode: number, data?: T): void
64
- result<T extends ResultType>(sceneId: string, resultCode: number): Promise<[number, T]>
65
- unmount(sceneId: string): void
66
- setRoot(layout: BuildInLayout | Layout, sticky?: boolean): Promise<boolean>
67
- setRootLayoutUpdateListener(willSetRoot?: () => void, didSetRoot?: () => void): void
68
- currentTab(sceneId: string): Promise<number>
69
- findSceneIdByModuleName(moduleName: string): Promise<string | null>
70
- isStackRoot(sceneId: string): Promise<boolean>
71
- signalFirstRenderComplete(sceneId: string): void
72
- currentRoute(): Promise<Route>
73
- routeGraph(): Promise<RouteGraph[]>
74
- setDefaultOptions(options: DefaultOptions): void
75
- setLeftBarButtonItem(sceneId: string, buttonItem: Nullable<BarButtonItem> | null): void
76
- setRightBarButtonItem(sceneId: string, buttonItem: Nullable<BarButtonItem> | null): void
77
- setLeftBarButtonItems(sceneId: string, buttonItems: Array<Nullable<BarButtonItem>> | null): void
78
- setRightBarButtonItems(sceneId: string, buttonItems: Array<Nullable<BarButtonItem>> | null): void
79
- setTitleItem(sceneId: string, titleItem: TitleItem): void
80
- updateOptions(sceneId: string, options: NavigationOption): void
81
- updateTabBar(sceneId: string, options: TabBarStyle): void
82
- setTabItem(sceneId: string, item: TabItemInfo | TabItemInfo[]): void
83
- setMenuInteractive(sceneId: string, enabled: boolean): void
84
- setBarButtonClickEventListener(listener: BarButtonClickEventListener): void
46
+ startRegisterComponent(hoc?: HOC): void;
47
+ endRegisterComponent(): void;
48
+ registerComponent(
49
+ appKey: string,
50
+ getComponentFunc: ComponentProvider,
51
+ routeConfig?: RouteConfig,
52
+ ): void;
53
+
54
+ routeConfigs(): Map<string, RouteConfig>;
55
+ setNavigationComponentWrap(wrap: (moduleName: string) => HOC): void;
56
+ addGlobalVisibilityEventListener(
57
+ listener: GlobalVisibilityEventListener,
58
+ ): NavigationSubscription;
59
+ addVisibilityEventListener(
60
+ sceneId: string,
61
+ listener: VisibilityEventListener,
62
+ ): NavigationSubscription;
63
+ dispatch(sceneId: string, action: string, params?: DispatchParams): Promise<boolean>;
64
+ setInterceptor(interceptor: NavigationInterceptor): void;
65
+ setResult<T extends ResultType>(sceneId: string, resultCode: number, data?: T): void;
66
+ result<T extends ResultType>(sceneId: string, resultCode: number): Promise<[number, T]>;
67
+ unmount(sceneId: string): void;
68
+ setRoot(layout: BuildInLayout | Layout, sticky?: boolean): Promise<boolean>;
69
+ setRootLayoutUpdateListener(willSetRoot?: () => void, didSetRoot?: () => void): void;
70
+ currentTab(sceneId: string): Promise<number>;
71
+ findSceneIdByModuleName(moduleName: string): Promise<string | null>;
72
+ isStackRoot(sceneId: string): Promise<boolean>;
73
+ signalFirstRenderComplete(sceneId: string): void;
74
+ currentRoute(): Promise<Route>;
75
+ routeGraph(): Promise<RouteGraph[]>;
76
+ setDefaultOptions(options: DefaultOptions): void;
77
+ setLeftBarButtonItem(sceneId: string, buttonItem: Nullable<BarButtonItem> | null): void;
78
+ setRightBarButtonItem(sceneId: string, buttonItem: Nullable<BarButtonItem> | null): void;
79
+ setLeftBarButtonItems(
80
+ sceneId: string,
81
+ buttonItems: Array<Nullable<BarButtonItem>> | null,
82
+ ): void;
83
+ setRightBarButtonItems(
84
+ sceneId: string,
85
+ buttonItems: Array<Nullable<BarButtonItem>> | null,
86
+ ): void;
87
+ setTitleItem(sceneId: string, titleItem: TitleItem): void;
88
+ updateOptions(sceneId: string, options: NavigationOption): void;
89
+ updateTabBar(sceneId: string, options: TabBarStyle): void;
90
+ setTabItem(sceneId: string, item: TabItemInfo | TabItemInfo[]): void;
91
+ setMenuInteractive(sceneId: string, enabled: boolean): void;
92
+ setBarButtonClickEventListener(listener: BarButtonClickEventListener): void;
85
93
  }
86
94
 
87
95
  class NavigationImpl implements Navigation {
88
- private dispatchHandler = new DispatchCommandHandler()
89
- private resultHandler = new ResultEventHandler()
90
- private buttonHandler = new BarButtonEventHandler()
91
- private layoutHandler = new LayoutCommandHandler()
92
- private visibilityHandler = new VisibilityEventHandler()
93
-
94
- constructor() {
95
- this.handleTabSwitch()
96
- this.layoutHandler.handleRootLayoutChange()
97
- this.visibilityHandler.handleComponentVisibility()
98
- this.resultHandler.handleComponentResult()
99
- }
100
-
101
- private wrap?: (moduleName: string) => HOC
102
- private hoc?: HOC
103
- private registerEnded = false
104
-
105
- startRegisterComponent(hoc?: HOC) {
106
- this.hoc = hoc
107
- this.registerEnded = false
108
- NavigationModule.startRegisterReactComponent()
109
- }
110
-
111
- endRegisterComponent() {
112
- if (this.registerEnded) {
113
- console.warn(`Please don't call ReactRegistry#endRegisterComponent multiple times.`)
114
- return
115
- }
116
- this.registerEnded = true
117
- NavigationModule.endRegisterReactComponent()
118
- }
119
-
120
- registerComponent(
121
- appKey: string,
122
- getComponentFunc: ComponentProvider,
123
- routeConfig?: RouteConfig,
124
- ) {
125
- if (routeConfig) {
126
- this.registerRoute(appKey, routeConfig)
127
- }
128
-
129
- let WrappedComponent = getComponentFunc()
130
- if (this.hoc) {
131
- WrappedComponent = this.hoc(WrappedComponent)
132
- }
133
-
134
- // build static options
135
- let options: object =
136
- this.bindBarButtonClickEvent('permanent', (WrappedComponent as any).navigationItem) || {}
137
- NavigationModule.registerReactComponent(appKey, options)
138
-
139
- let RootComponent = this.wrap!(appKey)(WrappedComponent)
140
- AppRegistry.registerComponent(appKey, () => RootComponent)
141
- }
142
-
143
- private _routeConfigs = new Map<string, RouteConfig>()
144
-
145
- private registerRoute(moduleName: string, route: RouteConfig) {
146
- this._routeConfigs.set(moduleName, route)
147
- }
148
-
149
- routeConfigs() {
150
- return this._routeConfigs
151
- }
152
-
153
- setNavigationComponentWrap(wrap: (moduleName: string) => HOC) {
154
- this.wrap = wrap
155
- }
156
-
157
- addGlobalVisibilityEventListener(
158
- listener: GlobalVisibilityEventListener,
159
- ): NavigationSubscription {
160
- this.visibilityHandler.addGlobalVisibilityEventListener(listener)
161
- return {
162
- remove: () => this.visibilityHandler.removeGlobalVisibilityEventListener(listener),
163
- }
164
- }
165
-
166
- addVisibilityEventListener(
167
- sceneId: string,
168
- listener: VisibilityEventListener,
169
- ): NavigationSubscription {
170
- this.visibilityHandler.addVisibilityEventListener(sceneId, listener)
171
- return {
172
- remove: () => this.visibilityHandler.removeVisibilityEventListener(sceneId, listener),
173
- }
174
- }
175
-
176
- dispatch(sceneId: string, action: string, params: DispatchParams = {}) {
177
- return this.dispatchHandler.dispatch(sceneId, action, params)
178
- }
179
-
180
- private handleTabSwitch() {
181
- Event.listenTabSwitch((sceneId: string, from: number, to: number) => {
182
- this.dispatch(sceneId, 'switchTab', { from, to })
183
- })
184
- }
185
-
186
- setInterceptor(interceptor: NavigationInterceptor) {
187
- this.dispatchHandler.setInterceptor(interceptor)
188
- }
189
-
190
- setResult = <T extends ResultType>(
191
- sceneId: string,
192
- resultCode: number,
193
- data: T = null as T,
194
- ): void => {
195
- if (resultCode < RESULT_OK) {
196
- console.warn(
197
- '`resultCode` can only be `RESULT_OK`, `RESULT_CANCEL` or an integer greater than 0.',
198
- )
199
- }
200
- NavigationModule.setResult(sceneId, resultCode, data)
201
- }
202
-
203
- result<T extends ResultType>(sceneId: string, resultCode: number) {
204
- return this.resultHandler.waitResult<T>(sceneId, resultCode)
205
- }
206
-
207
- unmount(sceneId: string) {
208
- this.resultHandler.invalidateResultEventListener(sceneId)
209
- this.buttonHandler.unbindBarButtonClickEvent(sceneId)
210
- }
211
-
212
- setRoot(layout: BuildInLayout | Layout, sticky = false) {
213
- return this.layoutHandler.setRoot(layout, sticky)
214
- }
215
-
216
- setRootLayoutUpdateListener(willSetRoot = () => {}, didSetRoot = () => {}) {
217
- this.layoutHandler.setRootLayoutUpdateListener(willSetRoot, didSetRoot)
218
- }
219
-
220
- currentTab(sceneId: string) {
221
- return NavigationModule.currentTab(sceneId)
222
- }
223
-
224
- findSceneIdByModuleName(moduleName: string) {
225
- return NavigationModule.findSceneIdByModuleName(moduleName)
226
- }
227
-
228
- isStackRoot(sceneId: string) {
229
- return NavigationModule.isStackRoot(sceneId)
230
- }
231
-
232
- signalFirstRenderComplete(sceneId: string) {
233
- NavigationModule.signalFirstRenderComplete(sceneId)
234
- }
235
-
236
- currentRoute(): Promise<Route> {
237
- return NavigationModule.currentRoute()
238
- }
239
-
240
- routeGraph(): Promise<RouteGraph[]> {
241
- return NavigationModule.routeGraph()
242
- }
243
-
244
- setDefaultOptions(options: DefaultOptions) {
245
- GardenModule.setStyle(options)
246
- }
247
-
248
- setLeftBarButtonItem(sceneId: string, buttonItem: Nullable<BarButtonItem> | null) {
249
- const options = this.bindBarButtonClickEvent(sceneId, buttonItem)
250
- GardenModule.setLeftBarButtonItem(sceneId, options)
251
- }
252
-
253
- setRightBarButtonItem(sceneId: string, buttonItem: Nullable<BarButtonItem> | null) {
254
- const options = this.bindBarButtonClickEvent(sceneId, buttonItem)
255
- GardenModule.setRightBarButtonItem(sceneId, options)
256
- }
257
-
258
- setLeftBarButtonItems(sceneId: string, buttonItems: Array<Nullable<BarButtonItem>> | null) {
259
- const options = this.bindBarButtonClickEvent(sceneId, buttonItems)
260
- GardenModule.setLeftBarButtonItems(sceneId, options)
261
- }
262
-
263
- setRightBarButtonItems(sceneId: string, buttonItems: Array<Nullable<BarButtonItem>> | null) {
264
- const options = this.bindBarButtonClickEvent(sceneId, buttonItems)
265
- GardenModule.setRightBarButtonItems(sceneId, options)
266
- }
267
-
268
- setTitleItem(sceneId: string, titleItem: TitleItem) {
269
- GardenModule.setTitleItem(sceneId, titleItem)
270
- }
271
-
272
- updateOptions(sceneId: string, options: NavigationOption) {
273
- GardenModule.updateOptions(sceneId, options)
274
- }
275
-
276
- updateTabBar(sceneId: string, options: TabBarStyle) {
277
- GardenModule.updateTabBar(sceneId, options)
278
- }
279
-
280
- setTabItem(sceneId: string, item: TabItemInfo | TabItemInfo[]) {
281
- if (!Array.isArray(item)) {
282
- item = [item]
283
- }
284
- GardenModule.setTabItem(sceneId, item)
285
- }
286
-
287
- setMenuInteractive(sceneId: string, enabled: boolean) {
288
- GardenModule.setMenuInteractive(sceneId, enabled)
289
- }
290
-
291
- setBarButtonClickEventListener(listener: BarButtonClickEventListener) {
292
- this.buttonHandler.setBarButtonClickEventListener(listener)
293
- }
294
-
295
- private bindBarButtonClickEvent(sceneId: string, item: object | null | undefined): object | null {
296
- return this.buttonHandler.bindBarButtonClickEvent(sceneId, item)
297
- }
96
+ private dispatchHandler = new DispatchCommandHandler();
97
+ private resultHandler = new ResultEventHandler();
98
+ private buttonHandler = new BarButtonEventHandler();
99
+ private layoutHandler = new LayoutCommandHandler();
100
+ private visibilityHandler = new VisibilityEventHandler();
101
+
102
+ constructor() {
103
+ this.handleTabSwitch();
104
+ this.layoutHandler.handleRootLayoutChange();
105
+ this.visibilityHandler.handleComponentVisibility();
106
+ this.resultHandler.handleComponentResult();
107
+ }
108
+
109
+ private wrap?: (moduleName: string) => HOC;
110
+ private hoc?: HOC;
111
+ private registerEnded = false;
112
+
113
+ startRegisterComponent(hoc?: HOC) {
114
+ this.hoc = hoc;
115
+ this.registerEnded = false;
116
+ NavigationModule.startRegisterReactComponent();
117
+ }
118
+
119
+ endRegisterComponent() {
120
+ if (this.registerEnded) {
121
+ console.warn("Please don't call ReactRegistry#endRegisterComponent multiple times.");
122
+ return;
123
+ }
124
+ this.registerEnded = true;
125
+ NavigationModule.endRegisterReactComponent();
126
+ }
127
+
128
+ registerComponent(
129
+ appKey: string,
130
+ getComponentFunc: ComponentProvider,
131
+ routeConfig?: RouteConfig,
132
+ ) {
133
+ if (routeConfig) {
134
+ this.registerRoute(appKey, routeConfig);
135
+ }
136
+
137
+ let WrappedComponent = getComponentFunc();
138
+ if (this.hoc) {
139
+ WrappedComponent = this.hoc(WrappedComponent);
140
+ }
141
+
142
+ // build static options
143
+ let options: object =
144
+ this.bindBarButtonClickEvent('permanent', (WrappedComponent as any).navigationItem) ||
145
+ {};
146
+ NavigationModule.registerReactComponent(appKey, options);
147
+
148
+ let RootComponent = this.wrap!(appKey)(WrappedComponent);
149
+ AppRegistry.registerComponent(appKey, () => RootComponent);
150
+ }
151
+
152
+ private _routeConfigs = new Map<string, RouteConfig>();
153
+
154
+ private registerRoute(moduleName: string, route: RouteConfig) {
155
+ this._routeConfigs.set(moduleName, route);
156
+ }
157
+
158
+ routeConfigs() {
159
+ return this._routeConfigs;
160
+ }
161
+
162
+ setNavigationComponentWrap(wrap: (moduleName: string) => HOC) {
163
+ this.wrap = wrap;
164
+ }
165
+
166
+ addGlobalVisibilityEventListener(
167
+ listener: GlobalVisibilityEventListener,
168
+ ): NavigationSubscription {
169
+ this.visibilityHandler.addGlobalVisibilityEventListener(listener);
170
+ return {
171
+ remove: () => this.visibilityHandler.removeGlobalVisibilityEventListener(listener),
172
+ };
173
+ }
174
+
175
+ addVisibilityEventListener(
176
+ sceneId: string,
177
+ listener: VisibilityEventListener,
178
+ ): NavigationSubscription {
179
+ this.visibilityHandler.addVisibilityEventListener(sceneId, listener);
180
+ return {
181
+ remove: () => this.visibilityHandler.removeVisibilityEventListener(sceneId, listener),
182
+ };
183
+ }
184
+
185
+ dispatch(sceneId: string, action: string, params: DispatchParams = {}) {
186
+ return this.dispatchHandler.dispatch(sceneId, action, params);
187
+ }
188
+
189
+ private handleTabSwitch() {
190
+ Event.listenTabSwitch((sceneId: string, from: number, to: number) => {
191
+ this.dispatch(sceneId, 'switchTab', {from, to});
192
+ });
193
+ }
194
+
195
+ setInterceptor(interceptor: NavigationInterceptor) {
196
+ this.dispatchHandler.setInterceptor(interceptor);
197
+ }
198
+
199
+ setResult = <T extends ResultType>(
200
+ sceneId: string,
201
+ resultCode: number,
202
+ data: T = null as T,
203
+ ): void => {
204
+ if (resultCode < RESULT_OK) {
205
+ console.warn(
206
+ '`resultCode` can only be `RESULT_OK`, `RESULT_CANCEL` or an integer greater than 0.',
207
+ );
208
+ }
209
+ NavigationModule.setResult(sceneId, resultCode, data);
210
+ };
211
+
212
+ result<T extends ResultType>(sceneId: string, resultCode: number) {
213
+ return this.resultHandler.waitResult<T>(sceneId, resultCode);
214
+ }
215
+
216
+ unmount(sceneId: string) {
217
+ this.resultHandler.invalidateResultEventListener(sceneId);
218
+ this.buttonHandler.unbindBarButtonClickEvent(sceneId);
219
+ }
220
+
221
+ setRoot(layout: BuildInLayout | Layout, sticky = false) {
222
+ return this.layoutHandler.setRoot(layout, sticky);
223
+ }
224
+
225
+ setRootLayoutUpdateListener(willSetRoot = () => {}, didSetRoot = () => {}) {
226
+ this.layoutHandler.setRootLayoutUpdateListener(willSetRoot, didSetRoot);
227
+ }
228
+
229
+ currentTab(sceneId: string) {
230
+ return NavigationModule.currentTab(sceneId);
231
+ }
232
+
233
+ findSceneIdByModuleName(moduleName: string) {
234
+ return NavigationModule.findSceneIdByModuleName(moduleName);
235
+ }
236
+
237
+ isStackRoot(sceneId: string) {
238
+ return NavigationModule.isStackRoot(sceneId);
239
+ }
240
+
241
+ signalFirstRenderComplete(sceneId: string) {
242
+ NavigationModule.signalFirstRenderComplete(sceneId);
243
+ }
244
+
245
+ currentRoute(): Promise<Route> {
246
+ return NavigationModule.currentRoute();
247
+ }
248
+
249
+ routeGraph(): Promise<RouteGraph[]> {
250
+ return NavigationModule.routeGraph();
251
+ }
252
+
253
+ setDefaultOptions(options: DefaultOptions) {
254
+ GardenModule.setStyle(options);
255
+ }
256
+
257
+ setLeftBarButtonItem(sceneId: string, buttonItem: Nullable<BarButtonItem> | null) {
258
+ const options = this.bindBarButtonClickEvent(sceneId, buttonItem);
259
+ GardenModule.setLeftBarButtonItem(sceneId, options);
260
+ }
261
+
262
+ setRightBarButtonItem(sceneId: string, buttonItem: Nullable<BarButtonItem> | null) {
263
+ const options = this.bindBarButtonClickEvent(sceneId, buttonItem);
264
+ GardenModule.setRightBarButtonItem(sceneId, options);
265
+ }
266
+
267
+ setLeftBarButtonItems(sceneId: string, buttonItems: Array<Nullable<BarButtonItem>> | null) {
268
+ const options = this.bindBarButtonClickEvent(sceneId, buttonItems);
269
+ GardenModule.setLeftBarButtonItems(sceneId, options);
270
+ }
271
+
272
+ setRightBarButtonItems(sceneId: string, buttonItems: Array<Nullable<BarButtonItem>> | null) {
273
+ const options = this.bindBarButtonClickEvent(sceneId, buttonItems);
274
+ GardenModule.setRightBarButtonItems(sceneId, options);
275
+ }
276
+
277
+ setTitleItem(sceneId: string, titleItem: TitleItem) {
278
+ GardenModule.setTitleItem(sceneId, titleItem);
279
+ }
280
+
281
+ updateOptions(sceneId: string, options: NavigationOption) {
282
+ GardenModule.updateOptions(sceneId, options);
283
+ }
284
+
285
+ updateTabBar(sceneId: string, options: TabBarStyle) {
286
+ GardenModule.updateTabBar(sceneId, options);
287
+ }
288
+
289
+ setTabItem(sceneId: string, item: TabItemInfo | TabItemInfo[]) {
290
+ if (!Array.isArray(item)) {
291
+ item = [item];
292
+ }
293
+ GardenModule.setTabItem(sceneId, item);
294
+ }
295
+
296
+ setMenuInteractive(sceneId: string, enabled: boolean) {
297
+ GardenModule.setMenuInteractive(sceneId, enabled);
298
+ }
299
+
300
+ setBarButtonClickEventListener(listener: BarButtonClickEventListener) {
301
+ this.buttonHandler.setBarButtonClickEventListener(listener);
302
+ }
303
+
304
+ private bindBarButtonClickEvent(
305
+ sceneId: string,
306
+ item: object | null | undefined,
307
+ ): object | null {
308
+ return this.buttonHandler.bindBarButtonClickEvent(sceneId, item);
309
+ }
298
310
  }
299
311
 
300
- export default new NavigationImpl() as Navigation
312
+ export default new NavigationImpl() as Navigation;