hybrid-navigation 2.13.0-beta.3 → 2.13.1

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 (58) hide show
  1. package/android/src/main/java/com/reactnative/hybridnavigation/ReactFragment.java +3 -20
  2. package/lib/Event.d.ts +12 -16
  3. package/lib/Event.js +20 -66
  4. package/lib/Garden.d.ts +49 -6
  5. package/lib/Garden.js +56 -32
  6. package/lib/Navigation.d.ts +68 -0
  7. package/lib/Navigation.js +162 -0
  8. package/lib/NavigationComponentWrap.d.ts +19 -0
  9. package/lib/NavigationComponentWrap.js +46 -0
  10. package/lib/Navigator.d.ts +46 -32
  11. package/lib/Navigator.js +110 -169
  12. package/lib/ReactRegistry.d.ts +19 -13
  13. package/lib/ReactRegistry.js +21 -73
  14. package/lib/Route.d.ts +13 -8
  15. package/lib/handler/BarButtonEventHandler.d.ts +10 -0
  16. package/lib/handler/BarButtonEventHandler.js +38 -0
  17. package/lib/handler/DispatchCommandHandler.d.ts +26 -0
  18. package/lib/handler/DispatchCommandHandler.js +28 -0
  19. package/lib/handler/LayoutCommandHandler.d.ts +11 -0
  20. package/lib/handler/LayoutCommandHandler.js +39 -0
  21. package/lib/handler/ResultEventHandler.d.ts +15 -0
  22. package/lib/handler/ResultEventHandler.js +47 -0
  23. package/lib/handler/VisibilityEventHandler.d.ts +13 -0
  24. package/lib/handler/VisibilityEventHandler.js +32 -0
  25. package/lib/hooks.d.ts +4 -0
  26. package/lib/hooks.js +13 -18
  27. package/lib/index.d.ts +8 -1
  28. package/lib/index.js +26 -2
  29. package/lib/router/drawer.d.ts +3 -1
  30. package/lib/router/drawer.js +17 -17
  31. package/lib/router/index.d.ts +19 -15
  32. package/lib/router/index.js +140 -116
  33. package/lib/router/screen.d.ts +5 -1
  34. package/lib/router/screen.js +29 -0
  35. package/lib/router/stack.d.ts +5 -1
  36. package/lib/router/stack.js +59 -46
  37. package/lib/router/tabs.d.ts +3 -1
  38. package/lib/router/tabs.js +18 -28
  39. package/package.json +1 -1
  40. package/src/Event.ts +25 -90
  41. package/src/Garden.ts +60 -38
  42. package/src/Navigation.ts +253 -0
  43. package/src/NavigationComponentWrap.tsx +73 -0
  44. package/src/Navigator.ts +124 -233
  45. package/src/ReactRegistry.tsx +23 -99
  46. package/src/Route.ts +14 -9
  47. package/src/handler/BarButtonEventHandler.ts +50 -0
  48. package/src/handler/DispatchCommandHandler.ts +58 -0
  49. package/src/handler/LayoutCommandHandler.ts +49 -0
  50. package/src/handler/ResultEventHandler.ts +67 -0
  51. package/src/handler/VisibilityEventHandler.ts +44 -0
  52. package/src/hooks.ts +18 -30
  53. package/src/index.ts +38 -4
  54. package/src/router/drawer.ts +20 -17
  55. package/src/router/index.ts +150 -119
  56. package/src/router/screen.ts +34 -1
  57. package/src/router/stack.ts +61 -48
  58. package/src/router/tabs.ts +19 -29
package/src/Navigator.ts CHANGED
@@ -1,13 +1,15 @@
1
1
  import { createContext } from 'react'
2
2
 
3
- import NavigationModule from './NavigationModule'
4
- import Event from './Event'
5
3
  import store from './store'
6
- import { Visibility, Layout, BuildInLayout, Route, RouteGraph } from './Route'
7
- import { NavigationItem } from './Options'
4
+ import type { Visibility, Layout, BuildInLayout, Route, RouteGraph } from './Route'
5
+ import type { NavigationItem } from './Options'
8
6
  import { Garden } from './Garden'
9
-
10
- const { RESULT_CANCEL } = NavigationModule.getConstants()
7
+ import Navigation, {
8
+ NavigationInterceptor,
9
+ DispatchParams,
10
+ ResultType,
11
+ RESULT_CANCEL,
12
+ } from './Navigation'
11
13
 
12
14
  export const NavigationContext = createContext<any>(null)
13
15
 
@@ -15,102 +17,27 @@ interface NavigationState {
15
17
  params: { readonly [index: string]: any }
16
18
  }
17
19
 
18
- interface IndexType {
19
- [index: string]: any
20
- }
21
20
  interface PropsType {
22
21
  [index: string]: any
23
22
  }
24
23
 
25
- interface DispatchParams {
26
- animated?: boolean
27
- moduleName?: string
28
- layout?: BuildInLayout | Layout
29
- popToRoot?: boolean
30
- requestCode?: number
31
- props?: object
32
- options?: NavigationItem
33
- [index: string]: any
34
- }
35
-
36
- interface InterceptParams {
37
- sceneId: string
38
- from?: number | string
39
- to?: number | string
40
- }
41
- export interface NavigationInterceptor {
42
- (action: string, params: InterceptParams): boolean | Promise<boolean>
43
- }
44
-
45
- let interceptor: NavigationInterceptor
46
- let shouldCallWillSetRootCallback = 0
47
- let willSetRootCallback: () => void
48
- let didSetRootCallback: () => void
49
24
  let tagGenerator = 0
50
25
 
51
- Event.listenSetRoot(
52
- () => {
53
- if (shouldCallWillSetRootCallback === 0 && willSetRootCallback) {
54
- willSetRootCallback()
55
- }
56
- },
57
- () => {
58
- didSetRootCallback && didSetRootCallback()
59
- shouldCallWillSetRootCallback = 0
60
- },
61
- )
62
-
63
- Event.listenSwitchTab((sceneId: string, from: number, to: number) => {
64
- Navigator.dispatch(sceneId, 'switchTab', { from, to })
26
+ Navigation.addGlobalVisibilityEventListener((sceneId: string, visibility: Visibility) => {
27
+ const navigator = store.getNavigator(sceneId)
28
+ if (navigator) {
29
+ navigator.visibility = visibility
30
+ }
65
31
  })
66
32
 
67
- type ResultType = IndexType | null
68
- interface ResultListener<T extends ResultType> {
69
- (resultCode: number, data: T): void
70
- cancel: () => void
71
- sceneId: string
72
- }
73
-
74
- const globalResultListeners = new Map<number, ResultListener<any>>()
75
-
76
- Event.listenComponentResult(
77
- (sceneId: string, requestCode: number, resultCode: number, data: any) => {
78
- if (requestCode < 0) {
79
- const listener = globalResultListeners.get(requestCode)
80
- if (listener) {
81
- globalResultListeners.delete(requestCode)
82
- listener(resultCode, data)
83
- }
84
- } else {
85
- const navigator = Navigator.of(sceneId)
86
- navigator.result(resultCode, data)
87
- }
88
- },
89
- )
90
-
91
- Event.listenComponentVisibility(
92
- (sceneId: string) => {
93
- const navigator = store.getNavigator(sceneId)
94
- if (navigator) {
95
- navigator.visibility = 'visible'
96
- }
97
- },
98
- (sceneId: string) => {
99
- const navigator = store.getNavigator(sceneId)
100
- if (navigator) {
101
- navigator.visibility = 'invisible'
102
- }
103
- },
104
- )
105
-
106
- Event.setBarButtonClickHandlerFactory(() => {
107
- return (sceneId, value) => {
108
- const navigator = Navigator.of(sceneId)
109
- value(navigator)
110
- }
33
+ Navigation.setBarButtonClickEventListener((sceneId, value) => {
34
+ const navigator = Navigator.of(sceneId)
35
+ value(navigator)
111
36
  })
112
37
 
113
- export class Navigator {
38
+ export interface Navigator {}
39
+
40
+ export class Navigator implements Navigator {
114
41
  static of(sceneId: string) {
115
42
  let navigator = store.getNavigator(sceneId)
116
43
  if (!navigator) {
@@ -120,88 +47,87 @@ export class Navigator {
120
47
  return navigator
121
48
  }
122
49
 
50
+ static async current(): Promise<Navigator> {
51
+ const route = await Navigation.currentRoute()
52
+ return Navigator.of(route.sceneId)
53
+ }
54
+
55
+ /**
56
+ * @deprecated Garden is deprecated, use Navigation.findSceneIdByModuleName() instead.
57
+ * @param moduleName
58
+ * @returns
59
+ */
123
60
  static async find(moduleName: string) {
124
- const sceneId = await NavigationModule.findSceneIdByModuleName(moduleName)
61
+ const sceneId = await Navigation.findSceneIdByModuleName(moduleName)
125
62
  if (sceneId) {
126
63
  return Navigator.of(sceneId)
127
64
  }
128
65
  }
129
66
 
130
- static async current(): Promise<Navigator> {
131
- const route = await Navigator.currentRoute()
132
- return Navigator.of(route.sceneId)
133
- }
134
-
67
+ /**
68
+ * @deprecated Use Navigation.currentRoute() instead
69
+ * @returns
70
+ */
135
71
  static currentRoute(): Promise<Route> {
136
- return NavigationModule.currentRoute()
72
+ return Navigation.currentRoute()
137
73
  }
138
74
 
75
+ /**
76
+ * @deprecated Use Navigation.routeGraph() instead
77
+ * @returns
78
+ */
139
79
  static routeGraph(): Promise<RouteGraph[]> {
140
- return NavigationModule.routeGraph()
80
+ return Navigation.routeGraph()
141
81
  }
142
82
 
83
+ /**
84
+ * @deprecated Use Navigation.setRoot() instead
85
+ * @param layout
86
+ * @param sticky
87
+ */
143
88
  static setRoot(layout: BuildInLayout | Layout, sticky = false) {
144
- if (willSetRootCallback) {
145
- shouldCallWillSetRootCallback++
146
- willSetRootCallback()
147
- }
148
-
149
- const flag = --tagGenerator
150
- NavigationModule.setRoot(layout, sticky, flag)
151
-
152
- return new Promise<void>(resolve => {
153
- const subscription = Event.listenSetRoot(
154
- () => {},
155
- (tag: number) => {
156
- if (tag === flag) {
157
- subscription.remove()
158
- resolve()
159
- }
160
- },
161
- )
162
- })
89
+ Navigation.setRoot(layout, sticky)
163
90
  }
164
91
 
92
+ /**
93
+ * @deprecated Use Navigation.setRootLayoutUpdateListener() instead
94
+ * @param willSetRoot
95
+ * @param didSetRoot
96
+ */
165
97
  static setRootLayoutUpdateListener(willSetRoot = () => {}, didSetRoot = () => {}) {
166
- willSetRootCallback = willSetRoot
167
- didSetRootCallback = didSetRoot
98
+ Navigation.setRootLayoutUpdateListener(willSetRoot, didSetRoot)
168
99
  }
169
100
 
101
+ /**
102
+ * @deprecated Use Navigation.dispatch() instead
103
+ * @param sceneId
104
+ * @param action
105
+ * @param params
106
+ * @returns
107
+ */
170
108
  static async dispatch(
171
109
  sceneId: string,
172
110
  action: string,
173
111
  params: DispatchParams = {},
174
112
  ): Promise<boolean> {
175
- let intercepted = false
176
- const { from, to } = params
177
- if (interceptor) {
178
- const result = interceptor(action, {
179
- sceneId,
180
- from,
181
- to,
182
- })
183
- if (result instanceof Promise) {
184
- intercepted = await result
185
- } else {
186
- intercepted = result
187
- }
188
- }
189
-
190
- if (!intercepted) {
191
- return NavigationModule.dispatch(sceneId, action, params)
192
- }
193
-
194
- return false
113
+ return Navigation.dispatch(sceneId, action, params)
195
114
  }
196
115
 
197
- static setInterceptor(interceptFn: NavigationInterceptor) {
198
- interceptor = interceptFn
116
+ /**
117
+ * @deprecated Use Navigation.setInterceptor() instead
118
+ * @param interceptor
119
+ */
120
+ static setInterceptor(interceptor: NavigationInterceptor) {
121
+ Navigation.setInterceptor(interceptor)
199
122
  }
200
123
 
201
124
  constructor(public sceneId: string, public moduleName?: string) {}
202
125
 
203
126
  private _garden?: Garden
204
127
 
128
+ /**
129
+ * @deprecated Garden is deprecated, Use Navigation related methods instead.
130
+ */
205
131
  get garden() {
206
132
  if (!this._garden) {
207
133
  this._garden = new Garden(this.sceneId)
@@ -219,65 +145,9 @@ export class Navigator {
219
145
  this.state.params = { ...this.state.params, ...params }
220
146
  }
221
147
 
222
- dispatch = (action: string, params: DispatchParams = {}) => {
223
- return Navigator.dispatch(this.sceneId, action, {
224
- from: this.moduleName,
225
- to: params.moduleName,
226
- ...params,
227
- })
228
- }
229
-
230
- result = (resultCode: number, data: ResultType) => {
231
- if (this.resultListener) {
232
- this.resultListener(resultCode, data)
233
- this.resultListener = null
234
- }
235
- }
236
-
237
148
  unmount = () => {
238
- Event.removeBarButtonClickEvent(this.sceneId)
239
149
  store.removeNavigator(this.sceneId)
240
-
241
- const codes: number[] = []
242
- for (const [requestCode, listener] of globalResultListeners) {
243
- if (listener.sceneId === this.sceneId) {
244
- codes.push(requestCode)
245
- listener.cancel()
246
- }
247
- }
248
- codes.forEach(code => globalResultListeners.delete(code))
249
-
250
- if (this.resultListener) {
251
- this.resultListener.cancel()
252
- this.resultListener = null
253
- }
254
- }
255
-
256
- private resultListener: ResultListener<any> | null = null
257
-
258
- private waitResult<T extends ResultType>(requestCode: number): Promise<[number, T]> {
259
- if (this.resultListener) {
260
- this.resultListener.cancel()
261
- this.resultListener = null
262
- }
263
-
264
- return new Promise<[number, T]>(resolve => {
265
- const listener = (resultCode: number, data: T) => {
266
- resolve([resultCode, data])
267
- }
268
-
269
- listener.cancel = () => {
270
- resolve([RESULT_CANCEL, null] as [number, T])
271
- }
272
-
273
- listener.sceneId = this.sceneId
274
-
275
- if (requestCode < 0) {
276
- globalResultListeners.set(requestCode, listener)
277
- } else {
278
- this.resultListener = listener
279
- }
280
- })
150
+ Navigation.unmount(this.sceneId)
281
151
  }
282
152
 
283
153
  push = async <T extends ResultType, P extends PropsType = {}>(
@@ -285,69 +155,82 @@ export class Navigator {
285
155
  props: P = {} as P,
286
156
  options: NavigationItem = {},
287
157
  ) => {
288
- const success = await this.dispatch('push', { moduleName, props, options })
158
+ const success = await Navigation.dispatch(this.sceneId, 'push', {
159
+ moduleName,
160
+ from: this.moduleName,
161
+ to: moduleName,
162
+ props,
163
+ options,
164
+ })
289
165
  if (!success) {
290
- return [RESULT_CANCEL] as unknown as [number, T]
166
+ return [RESULT_CANCEL, null] as [number, T]
291
167
  }
292
- return await this.waitResult<T>(0)
168
+ return await Navigation.result<T>(this.sceneId, 0)
293
169
  }
294
170
 
295
171
  pushLayout = async <T extends ResultType>(layout: BuildInLayout | Layout) => {
296
- const success = await this.dispatch('pushLayout', { layout })
172
+ const success = await Navigation.dispatch(this.sceneId, 'pushLayout', {
173
+ from: this.moduleName,
174
+ layout,
175
+ })
297
176
  if (!success) {
298
- return [RESULT_CANCEL] as unknown as [number, T]
177
+ return [RESULT_CANCEL, null] as [number, T]
299
178
  }
300
- return await this.waitResult<T>(0)
179
+ return await Navigation.result<T>(this.sceneId, 0)
301
180
  }
302
181
 
303
- pop = () => this.dispatch('pop')
182
+ pop = () => Navigation.dispatch(this.sceneId, 'pop')
304
183
 
305
184
  popTo = (moduleName: string, inclusive: boolean = false) =>
306
- this.dispatch('popTo', { moduleName, inclusive })
185
+ Navigation.dispatch(this.sceneId, 'popTo', { moduleName, inclusive })
307
186
 
308
- popToRoot = () => this.dispatch('popToRoot')
187
+ popToRoot = () => Navigation.dispatch(this.sceneId, 'popToRoot')
309
188
 
310
189
  redirectTo = <P extends PropsType>(
311
190
  moduleName: string,
312
191
  props: P = {} as P,
313
192
  options: NavigationItem = {},
314
193
  ) =>
315
- this.dispatch('redirectTo', {
194
+ Navigation.dispatch(this.sceneId, 'redirectTo', {
316
195
  moduleName,
317
196
  props,
318
197
  options,
319
198
  })
320
199
 
321
- isStackRoot = () => NavigationModule.isStackRoot(this.sceneId)
322
-
323
200
  present = async <T extends ResultType, P extends PropsType = {}>(
324
201
  moduleName: string,
325
202
  props: P = {} as P,
326
203
  options: NavigationItem = {},
327
204
  ) => {
328
205
  const requestCode = --tagGenerator
329
- const success = await this.dispatch('present', {
206
+ const success = await Navigation.dispatch(this.sceneId, 'present', {
330
207
  moduleName,
208
+ from: this.moduleName,
209
+ to: moduleName,
331
210
  props,
332
211
  options,
333
212
  requestCode,
334
213
  })
335
214
  if (!success) {
336
- return [RESULT_CANCEL] as unknown as [number, T]
215
+ return [RESULT_CANCEL, null] as [number, T]
337
216
  }
338
- return await this.waitResult<T>(requestCode)
217
+ return await Navigation.result<T>(this.sceneId, requestCode)
339
218
  }
340
219
 
341
220
  presentLayout = async <T extends ResultType>(layout: BuildInLayout | Layout) => {
342
221
  const requestCode = --tagGenerator
343
- const success = await this.dispatch('presentLayout', { layout, requestCode })
222
+ const success = await Navigation.dispatch(this.sceneId, 'presentLayout', {
223
+ layout,
224
+ from: this.moduleName,
225
+ requestCode,
226
+ })
344
227
  if (!success) {
345
- return [RESULT_CANCEL] as unknown as [number, T]
228
+ return [RESULT_CANCEL, null] as [number, T]
346
229
  }
347
- return await this.waitResult<T>(requestCode)
230
+ return await Navigation.result<T>(this.sceneId, requestCode)
348
231
  }
349
232
 
350
- dismiss = () => this.dispatch('dismiss')
233
+ dismiss = () => Navigation.dispatch(this.sceneId, 'dismiss')
351
234
 
352
235
  showModal = async <T extends ResultType, P extends PropsType = {}>(
353
236
  moduleName: string,
@@ -355,42 +238,50 @@ export class Navigator {
355
238
  options: NavigationItem = {},
356
239
  ) => {
357
240
  const requestCode = --tagGenerator
358
- const success = await this.dispatch('showModal', {
241
+ const success = await Navigation.dispatch(this.sceneId, 'showModal', {
359
242
  moduleName,
243
+ from: this.moduleName,
244
+ to: moduleName,
360
245
  props,
361
246
  options,
362
247
  requestCode,
363
248
  })
364
249
  if (!success) {
365
- return [RESULT_CANCEL] as unknown as [number, T]
250
+ return [RESULT_CANCEL, null] as [number, T]
366
251
  }
367
- return await this.waitResult<T>(requestCode)
252
+ return await Navigation.result<T>(this.sceneId, requestCode)
368
253
  }
369
254
 
370
255
  showModalLayout = async <T extends ResultType>(layout: BuildInLayout | Layout) => {
371
256
  const requestCode = --tagGenerator
372
- const success = await this.dispatch('showModalLayout', { layout, requestCode })
257
+ const success = await Navigation.dispatch(this.sceneId, 'showModalLayout', {
258
+ from: this.moduleName,
259
+ layout,
260
+ requestCode,
261
+ })
373
262
  if (!success) {
374
- return [RESULT_CANCEL] as unknown as [number, T]
263
+ return [RESULT_CANCEL, null] as [number, T]
375
264
  }
376
- return await this.waitResult<T>(requestCode)
265
+ return await Navigation.result<T>(this.sceneId, requestCode)
377
266
  }
378
267
 
379
- hideModal = () => this.dispatch('hideModal')
268
+ hideModal = () => Navigation.dispatch(this.sceneId, 'hideModal')
380
269
 
381
270
  setResult = <T extends ResultType>(resultCode: number, data: T = null as any): void =>
382
- NavigationModule.setResult(this.sceneId, resultCode, data)
271
+ Navigation.setResult(this.sceneId, resultCode, data)
383
272
 
384
273
  switchTab = async (index: number, popToRoot: boolean = false) => {
385
- const from = await NavigationModule.currentTab(this.sceneId)
386
- return this.dispatch('switchTab', { from, to: index, popToRoot })
274
+ const from = await Navigation.currentTab(this.sceneId)
275
+ return Navigation.dispatch(this.sceneId, 'switchTab', { from, to: index, popToRoot })
387
276
  }
388
277
 
389
- toggleMenu = () => this.dispatch('toggleMenu')
278
+ toggleMenu = () => Navigation.dispatch(this.sceneId, 'toggleMenu')
279
+
280
+ openMenu = () => Navigation.dispatch(this.sceneId, 'openMenu')
390
281
 
391
- openMenu = () => this.dispatch('openMenu')
282
+ closeMenu = () => Navigation.dispatch(this.sceneId, 'closeMenu')
392
283
 
393
- closeMenu = () => this.dispatch('closeMenu')
284
+ isStackRoot = () => Navigation.isStackRoot(this.sceneId)
394
285
 
395
- signalFirstRenderComplete = () => NavigationModule.signalFirstRenderComplete(this.sceneId)
286
+ signalFirstRenderComplete = () => Navigation.signalFirstRenderComplete(this.sceneId)
396
287
  }
@@ -1,115 +1,39 @@
1
- import { AppRegistry, ComponentProvider } from 'react-native'
2
- import React, { useEffect } from 'react'
3
- import { Navigator, NavigationContext } from './Navigator'
4
- import { Garden } from './Garden'
5
- import { router } from './router'
6
- import NavigationModule from './NavigationModule'
7
- import Event from './Event'
8
- import { NavigationItem } from './Options'
9
- import { RouteConfig } from './Route'
1
+ import { ComponentProvider } from 'react-native'
2
+ import type { RouteConfig } from './Route'
10
3
 
11
- export interface InjectedProps {
12
- navigator: Navigator
13
- garden: Garden
14
- sceneId: string
15
- }
16
-
17
- interface Props {
18
- sceneId: string
19
- }
20
-
21
- function getDisplayName(WrappedComponent: React.ComponentType<any>) {
22
- return WrappedComponent.displayName || WrappedComponent.name || 'Component'
23
- }
24
-
25
- function withNavigation(moduleName: string) {
26
- return function (WrappedComponent: React.ComponentType<any>) {
27
- const FC = React.forwardRef((props: Props, ref: React.Ref<React.ComponentType<any>>) => {
28
- const { sceneId } = props
29
-
30
- const navigator = Navigator.of(sceneId)
31
- if (navigator.moduleName === undefined) {
32
- navigator.moduleName = moduleName
33
- }
34
-
35
- const garden = navigator.garden
36
-
37
- useEffect(() => {
38
- navigator.signalFirstRenderComplete()
39
- return () => {
40
- navigator.unmount()
41
- }
42
- }, [navigator])
43
-
44
- const injected = {
45
- garden,
46
- navigator,
47
- }
48
-
49
- return (
50
- <NavigationContext.Provider value={navigator}>
51
- <WrappedComponent ref={ref} {...props} {...injected} />
52
- </NavigationContext.Provider>
53
- )
54
- })
55
-
56
- FC.displayName = `withNavigation(${getDisplayName(WrappedComponent)})`
57
- return FC
58
- }
59
- }
60
-
61
- export type HOC = (WrappedComponent: React.ComponentType<any>) => React.ComponentType<any>
62
- let wrap: HOC | undefined
4
+ import Navigation, { HOC } from './Navigation'
63
5
 
6
+ /**
7
+ * @deprecated use Navigation instead. import Navigation from 'hybrid-navigation'
8
+ */
64
9
  export class ReactRegistry {
65
- static registerEnded: boolean
10
+ /**
11
+ * @deprecated Use Navigation.startRegisterComponent() instead.
12
+ * @param hoc
13
+ */
66
14
  static startRegisterComponent(hoc?: HOC) {
67
- wrap = hoc
68
- ReactRegistry.registerEnded = false
69
- NavigationModule.startRegisterReactComponent()
15
+ Navigation.startRegisterComponent(hoc)
70
16
  }
71
17
 
18
+ /**
19
+ * @deprecated Use Navigation.endRegisterComponent() instead.
20
+ */
72
21
  static endRegisterComponent() {
73
- if (ReactRegistry.registerEnded) {
74
- console.warn(`Please don't call ReactRegistry#endRegisterComponent multiple times.`)
75
- return
76
- }
77
- ReactRegistry.registerEnded = true
78
- NavigationModule.endRegisterReactComponent()
22
+ Navigation.endRegisterComponent()
79
23
  }
80
24
 
25
+ /**
26
+ *
27
+ * @deprecated Use Navigation.registerComponent() instead.
28
+ * @param appKey
29
+ * @param getComponentFunc
30
+ * @param routeConfig
31
+ */
81
32
  static registerComponent(
82
33
  appKey: string,
83
34
  getComponentFunc: ComponentProvider,
84
35
  routeConfig?: RouteConfig,
85
36
  ) {
86
- if (routeConfig) {
87
- router.registerRoute(appKey, routeConfig)
88
- }
89
-
90
- let WrappedComponent = getComponentFunc()
91
- if (wrap) {
92
- WrappedComponent = wrap(WrappedComponent)
93
- }
94
-
95
- // build static options
96
- let options: object =
97
- Event.bindBarButtonClickEvent('permanent', (WrappedComponent as any).navigationItem) || {}
98
- NavigationModule.registerReactComponent(appKey, options)
99
-
100
- let RootComponent = withNavigation(appKey)(WrappedComponent)
101
- AppRegistry.registerComponent(appKey, () => RootComponent)
102
- }
103
- }
104
-
105
- export function withNavigationItem(item: NavigationItem) {
106
- return function (WrappedComponent: React.ComponentType<any>): React.ComponentType<any> {
107
- let navigationItem = (WrappedComponent as any).navigationItem
108
- if (navigationItem) {
109
- ;(WrappedComponent as any).navigationItem = { ...navigationItem, ...item }
110
- } else {
111
- ;(WrappedComponent as any).navigationItem = item
112
- }
113
- return WrappedComponent
37
+ Navigation.registerComponent(appKey, getComponentFunc, routeConfig)
114
38
  }
115
39
  }
package/src/Route.ts CHANGED
@@ -65,14 +65,6 @@ export interface RouteConfig {
65
65
  mode?: RouteMode
66
66
  }
67
67
 
68
- export interface RouteInfo {
69
- moduleName: string
70
- dependencies: string[]
71
- mode: RouteMode
72
- props: object
73
- options: object
74
- }
75
-
76
68
  export interface RouteData {
77
69
  moduleName: string
78
70
  regexp?: RegExp
@@ -81,8 +73,21 @@ export interface RouteData {
81
73
  mode: RouteMode
82
74
  }
83
75
 
76
+ export interface RouteInfo {
77
+ moduleName: string
78
+ mode: RouteMode
79
+ dependencies: string[]
80
+ props: object
81
+ options: object
82
+ }
83
+
84
84
  export interface RouteHandler {
85
- (graph: RouteGraph, route: RouteInfo, next: RouteHandler): Promise<boolean>
85
+ /**
86
+ * @param graph - current RouteGraph to process
87
+ * @param target - route may add to the graph
88
+ * @reurns [boolean, RouteGraph] - if the route is handled, return true and childGraph for next Handler to process, [false, graph] otherwise
89
+ */
90
+ process: (graph: RouteGraph, target: RouteInfo) => Promise<[boolean, RouteGraph | null]>
86
91
  }
87
92
 
88
93
  export type RouteInterceptor = (path: string) => boolean | Promise<boolean>