hybrid-navigation 2.13.2 → 2.13.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 (50) hide show
  1. package/README.md +4 -4
  2. package/android/src/main/java/com/reactnative/hybridnavigation/Garden.java +1 -1
  3. package/android/src/main/java/com/reactnative/hybridnavigation/GardenModule.java +1 -1
  4. package/android/src/main/java/com/reactnative/hybridnavigation/GlobalStyle.java +1 -1
  5. package/android/src/main/java/com/reactnative/hybridnavigation/HBDReactRootView.java +1 -1
  6. package/android/src/main/java/com/reactnative/hybridnavigation/NavigationModule.java +31 -36
  7. package/android/src/main/java/com/reactnative/hybridnavigation/NavigatorRegistry.java +0 -2
  8. package/android/src/main/java/com/reactnative/hybridnavigation/ReactAppCompatActivity.java +32 -64
  9. package/android/src/main/java/com/reactnative/hybridnavigation/ReactAppCompatActivityDelegate.java +1 -1
  10. package/android/src/main/java/com/reactnative/hybridnavigation/ReactBridgeManager.java +8 -8
  11. package/android/src/main/java/com/reactnative/hybridnavigation/ReactFragment.java +1 -1
  12. package/android/src/main/java/com/reactnative/hybridnavigation/ReactFrameLayout.java +1 -1
  13. package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarProvider.java +1 -1
  14. package/android/src/main/java/com/reactnative/hybridnavigation/Utils.java +1 -1
  15. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/ScreenNavigator.java +1 -2
  16. package/ios/HybridNavigation/HBDUtils.m +3 -3
  17. package/ios/HybridNavigation/Navigator/HBDNavigatorRegistry.m +2 -2
  18. package/ios/HybridNavigation/Navigator/HBDStackNavigator.m +5 -5
  19. package/ios/HybridNavigation/ReactBridge/HBDGardenModule.m +8 -8
  20. package/ios/HybridNavigation/ReactBridge/HBDNavigationModule.m +22 -15
  21. package/ios/HybridNavigation/ReactBridge/HBDReactBridgeManager.h +2 -3
  22. package/ios/HybridNavigation/ReactBridge/HBDReactBridgeManager.m +35 -29
  23. package/ios/HybridNavigation/ViewController/HBDNavigationController.m +2 -2
  24. package/ios/HybridNavigation/ViewController/HBDViewController.m +1 -1
  25. package/ios/HybridNavigation/ViewController/UIViewController+HBD.m +1 -1
  26. package/lib/Event.d.ts +0 -2
  27. package/lib/Event.js +0 -9
  28. package/lib/GardenModule.d.ts +4 -0
  29. package/lib/GardenModule.js +19 -1
  30. package/lib/Navigation.d.ts +1 -1
  31. package/lib/NavigationModule.d.ts +1 -1
  32. package/lib/NavigationModule.js +6 -2
  33. package/lib/Navigator.js +10 -8
  34. package/lib/handler/DispatchCommandHandler.d.ts +1 -0
  35. package/lib/handler/DispatchCommandHandler.js +17 -16
  36. package/lib/handler/LayoutCommandHandler.d.ts +1 -3
  37. package/lib/handler/LayoutCommandHandler.js +2 -19
  38. package/lib/index.d.ts +1 -4
  39. package/lib/index.js +1 -20
  40. package/lib/router/index.d.ts +2 -1
  41. package/lib/router/index.js +13 -6
  42. package/package.json +1 -1
  43. package/src/Event.ts +0 -11
  44. package/src/GardenModule.ts +27 -1
  45. package/src/NavigationModule.ts +7 -3
  46. package/src/Navigator.ts +10 -8
  47. package/src/handler/DispatchCommandHandler.ts +18 -15
  48. package/src/handler/LayoutCommandHandler.ts +2 -22
  49. package/src/index.ts +1 -24
  50. package/src/router/index.ts +14 -6
@@ -46,7 +46,7 @@ class Router {
46
46
  return { moduleName, mode, path, regexp, dependency };
47
47
  }
48
48
  isRouteConfigInflated = false;
49
- routeDatas = new Map();
49
+ routeDataSet = new Map();
50
50
  inflateRouteData() {
51
51
  if (this.isRouteConfigInflated) {
52
52
  return;
@@ -55,7 +55,7 @@ class Router {
55
55
  const routeConfigs = Navigation.routeConfigs();
56
56
  for (const [moduleName, config] of routeConfigs) {
57
57
  const data = this.convertConfigToData(moduleName, config);
58
- this.routeDatas.set(moduleName, data);
58
+ this.routeDataSet.set(moduleName, data);
59
59
  }
60
60
  }
61
61
  interceptors = [];
@@ -68,14 +68,21 @@ class Router {
68
68
  async intercept(path) {
69
69
  for (let interceptor of this.interceptors.values()) {
70
70
  const result = interceptor(path);
71
- if (result instanceof Promise) {
72
- return await result;
71
+ const intercepted = await this.resolveInterceptResult(result);
72
+ if (intercepted) {
73
+ return true;
73
74
  }
75
+ }
76
+ return false;
77
+ }
78
+ resolveInterceptResult(result) {
79
+ if (result instanceof Promise) {
74
80
  return result;
75
81
  }
82
+ return Promise.resolve(result);
76
83
  }
77
84
  pathToRoute(path, props, options) {
78
- for (const data of this.routeDatas.values()) {
85
+ for (const data of this.routeDataSet.values()) {
79
86
  if (!data.regexp) {
80
87
  continue;
81
88
  }
@@ -96,7 +103,7 @@ class Router {
96
103
  let data = routeData;
97
104
  while (data && data.dependency) {
98
105
  dependencies.push(data.dependency);
99
- data = this.routeDatas.get(data.dependency);
106
+ data = this.routeDataSet.get(data.dependency);
100
107
  }
101
108
  return dependencies.reverse();
102
109
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "hybrid-navigation",
3
3
  "description": "React Native Navigation that supports seamless navigation between Native and React.",
4
- "version": "2.13.2",
4
+ "version": "2.13.5",
5
5
  "main": "./lib/index.js",
6
6
  "typings": "./lib/index.d.ts",
7
7
  "react-native": "src/index",
package/src/Event.ts CHANGED
@@ -1,15 +1,5 @@
1
1
  import { NativeModules, NativeEventEmitter, NativeModule } from 'react-native'
2
- import GardenModule from './GardenModule'
3
2
  import type { Visibility } from './Route'
4
-
5
- function listenStatusBarHeightChange(listener: (statusBarHeight: number) => void) {
6
- const GardenEventReceiver = new NativeEventEmitter(GardenModule)
7
- const { EVENT_STATUSBAR_FRAME_CHANGE } = GardenModule.getConstants()
8
- return GardenEventReceiver.addListener(EVENT_STATUSBAR_FRAME_CHANGE, ({ statusBarHeight }) => {
9
- listener(statusBarHeight)
10
- })
11
- }
12
-
13
3
  interface HBDEventEmitter extends NativeModule {
14
4
  getConstants: () => {
15
5
  EVENT_NAVIGATION: string
@@ -113,7 +103,6 @@ function listenDidSetRoot(didSetRoot: (tag: number) => void) {
113
103
  }
114
104
 
115
105
  export default {
116
- listenStatusBarHeightChange,
117
106
  listenBarButtonItemClick,
118
107
  listenComponentResult,
119
108
  listenComponentVisibility,
@@ -1,4 +1,4 @@
1
- import { NativeModules, NativeModule } from 'react-native'
1
+ import { NativeModules, NativeModule, NativeEventEmitter, Platform } from 'react-native'
2
2
 
3
3
  interface GardenModule extends NativeModule {
4
4
  getConstants: () => {
@@ -21,4 +21,30 @@ interface GardenModule extends NativeModule {
21
21
 
22
22
  const GardenModule: GardenModule = NativeModules.GardenModule
23
23
 
24
+ const { STATUSBAR_HEIGHT, TOOLBAR_HEIGHT, EVENT_STATUSBAR_FRAME_CHANGE } =
25
+ GardenModule.getConstants()
26
+
27
+ let _statusBarHeight = STATUSBAR_HEIGHT
28
+
29
+ if (Platform.OS === 'ios') {
30
+ const GardenEventReceiver = new NativeEventEmitter(GardenModule)
31
+ GardenEventReceiver.addListener(EVENT_STATUSBAR_FRAME_CHANGE, ({ statusBarHeight: height }) => {
32
+ _statusBarHeight = height
33
+ })
34
+ }
35
+
36
+ function statusBarHeight() {
37
+ return _statusBarHeight
38
+ }
39
+
40
+ function toolbarHeight() {
41
+ return TOOLBAR_HEIGHT
42
+ }
43
+
44
+ function topBarHeight() {
45
+ return statusBarHeight() + toolbarHeight()
46
+ }
47
+
48
+ export { statusBarHeight, toolbarHeight, topBarHeight }
49
+
24
50
  export default GardenModule
@@ -13,7 +13,7 @@ interface NavigationModule {
13
13
  endRegisterReactComponent: () => void
14
14
  registerReactComponent: (appKey: string, options: object) => void
15
15
  signalFirstRenderComplete: (sceneId: string) => void
16
- setRoot: (layout: object, sticky: boolean, tag: number) => void
16
+ setRoot: (layout: object, sticky: boolean, callback: Callback) => void
17
17
  setResult: (sceneId: string, resultCode: number, data: object | null) => void
18
18
  dispatch: (sceneId: string, action: string, params: object, callback: Callback) => void
19
19
  currentTab: (sceneId: string, callback: Callback) => void
@@ -49,8 +49,12 @@ function setResult(sceneId: string, resultCode: number, data: object | null) {
49
49
  NavigationModule.setResult(sceneId, resultCode, data)
50
50
  }
51
51
 
52
- function setRoot(layout: object, sticky: boolean, tag: number) {
53
- NavigationModule.setRoot(layout, sticky, tag)
52
+ function setRoot(layout: object, sticky: boolean) {
53
+ return new Promise<boolean>(resolve => {
54
+ NavigationModule.setRoot(layout, sticky, (_, success) => {
55
+ resolve(success)
56
+ })
57
+ })
54
58
  }
55
59
 
56
60
  function dispatch(sceneId: string, action: string, params: object) {
package/src/Navigator.ts CHANGED
@@ -179,12 +179,12 @@ export class Navigator implements Navigator {
179
179
  return await Navigation.result<T>(this.sceneId, 0)
180
180
  }
181
181
 
182
- pop = () => Navigation.dispatch(this.sceneId, 'pop')
182
+ pop = () => Navigation.dispatch(this.sceneId, 'pop', { from: this.moduleName })
183
183
 
184
184
  popTo = (moduleName: string, inclusive: boolean = false) =>
185
- Navigation.dispatch(this.sceneId, 'popTo', { moduleName, inclusive })
185
+ Navigation.dispatch(this.sceneId, 'popTo', { moduleName, inclusive, from: this.moduleName })
186
186
 
187
- popToRoot = () => Navigation.dispatch(this.sceneId, 'popToRoot')
187
+ popToRoot = () => Navigation.dispatch(this.sceneId, 'popToRoot', { from: this.moduleName })
188
188
 
189
189
  redirectTo = <P extends PropsType>(
190
190
  moduleName: string,
@@ -193,6 +193,8 @@ export class Navigator implements Navigator {
193
193
  ) =>
194
194
  Navigation.dispatch(this.sceneId, 'redirectTo', {
195
195
  moduleName,
196
+ from: this.moduleName,
197
+ to: moduleName,
196
198
  props,
197
199
  options,
198
200
  })
@@ -230,7 +232,7 @@ export class Navigator implements Navigator {
230
232
  return await Navigation.result<T>(this.sceneId, requestCode)
231
233
  }
232
234
 
233
- dismiss = () => Navigation.dispatch(this.sceneId, 'dismiss')
235
+ dismiss = () => Navigation.dispatch(this.sceneId, 'dismiss', { from: this.moduleName })
234
236
 
235
237
  showModal = async <T extends ResultType, P extends PropsType = {}>(
236
238
  moduleName: string,
@@ -265,7 +267,7 @@ export class Navigator implements Navigator {
265
267
  return await Navigation.result<T>(this.sceneId, requestCode)
266
268
  }
267
269
 
268
- hideModal = () => Navigation.dispatch(this.sceneId, 'hideModal')
270
+ hideModal = () => Navigation.dispatch(this.sceneId, 'hideModal', { from: this.moduleName })
269
271
 
270
272
  setResult = <T extends ResultType>(resultCode: number, data: T = null as any): void =>
271
273
  Navigation.setResult(this.sceneId, resultCode, data)
@@ -275,11 +277,11 @@ export class Navigator implements Navigator {
275
277
  return Navigation.dispatch(this.sceneId, 'switchTab', { from, to: index, popToRoot })
276
278
  }
277
279
 
278
- toggleMenu = () => Navigation.dispatch(this.sceneId, 'toggleMenu')
280
+ toggleMenu = () => Navigation.dispatch(this.sceneId, 'toggleMenu', { from: this.moduleName })
279
281
 
280
- openMenu = () => Navigation.dispatch(this.sceneId, 'openMenu')
282
+ openMenu = () => Navigation.dispatch(this.sceneId, 'openMenu', { from: this.moduleName })
281
283
 
282
- closeMenu = () => Navigation.dispatch(this.sceneId, 'closeMenu')
284
+ closeMenu = () => Navigation.dispatch(this.sceneId, 'closeMenu', { from: this.moduleName })
283
285
 
284
286
  isStackRoot = () => Navigation.isStackRoot(this.sceneId)
285
287
 
@@ -30,26 +30,29 @@ export default class DispatchCommandHandler {
30
30
  private interceptor: NavigationInterceptor = () => false
31
31
 
32
32
  async dispatch(sceneId: string, action: string, params: DispatchParams): Promise<boolean> {
33
- let intercepted = false
34
33
  const { from, to } = params
35
- if (this.interceptor) {
36
- const result = this.interceptor(action, {
37
- sceneId,
38
- from,
39
- to,
40
- })
41
- if (result instanceof Promise) {
42
- intercepted = await result
43
- } else {
44
- intercepted = result
45
- }
34
+ const intercepted = await this.intercept(action, {
35
+ sceneId,
36
+ from,
37
+ to,
38
+ })
39
+
40
+ if (intercepted) {
41
+ return false
46
42
  }
43
+ return NavigationModule.dispatch(sceneId, action, params)
44
+ }
47
45
 
48
- if (!intercepted) {
49
- return NavigationModule.dispatch(sceneId, action, params)
46
+ private intercept(action: string, params: InterceptParams) {
47
+ if (!this.interceptor) {
48
+ return Promise.resolve(false)
50
49
  }
51
50
 
52
- return false
51
+ const result = this.interceptor(action, params)
52
+ if (result instanceof Promise) {
53
+ return result
54
+ }
55
+ return Promise.resolve(result)
53
56
  }
54
57
 
55
58
  setInterceptor(interceptor: NavigationInterceptor) {
@@ -6,40 +6,20 @@ export default class LayoutCommandHandler {
6
6
  private willSetRoot = () => {}
7
7
  private didSetRoot = () => {}
8
8
 
9
- private canInvokeWillSetRoot = true
10
- private tagGenerator = 0
11
-
12
9
  constructor() {}
13
10
 
14
11
  handleRootLayoutChange() {
15
12
  Event.listenWillSetRoot(() => {
16
- if (this.canInvokeWillSetRoot) {
17
- this.willSetRoot()
18
- }
13
+ this.willSetRoot()
19
14
  })
20
15
 
21
16
  Event.listenDidSetRoot(() => {
22
17
  this.didSetRoot()
23
- this.canInvokeWillSetRoot = true
24
18
  })
25
19
  }
26
20
 
27
21
  setRoot(layout: BuildInLayout | Layout, sticky = false) {
28
- this.willSetRoot()
29
- this.canInvokeWillSetRoot = false
30
-
31
- const flag = this.tagGenerator++
32
- NavigationModule.setRoot(layout, sticky, flag)
33
-
34
- return new Promise<void>(resolve => {
35
- const subscription = Event.listenDidSetRoot((tag: number) => {
36
- // FIXME: 此处恐有内存泄漏
37
- if (tag === flag) {
38
- subscription.remove()
39
- resolve()
40
- }
41
- })
42
- })
22
+ return NavigationModule.setRoot(layout, sticky)
43
23
  }
44
24
 
45
25
  setRootLayoutUpdateListener(willSetRoot = () => {}, didSetRoot = () => {}) {
package/src/index.ts CHANGED
@@ -1,34 +1,11 @@
1
- import { Platform } from 'react-native'
2
- import Event from './Event'
3
- import GardenModule from './GardenModule'
4
1
  import { withNavigation } from './NavigationComponentWrap'
5
2
  import Navigation from './Navigation'
6
3
 
7
4
  Navigation.setNavigationComponentWrap(withNavigation)
8
5
 
9
- const { STATUSBAR_HEIGHT, TOOLBAR_HEIGHT } = GardenModule.getConstants()
10
- let _statusBarHeight = STATUSBAR_HEIGHT
11
- if (Platform.OS === 'ios') {
12
- Event.listenStatusBarHeightChange(height => {
13
- _statusBarHeight = height
14
- })
15
- }
16
-
17
- function statusBarHeight() {
18
- return _statusBarHeight
19
- }
20
-
21
- function toolbarHeight() {
22
- return TOOLBAR_HEIGHT
23
- }
24
-
25
- function topBarHeight() {
26
- return statusBarHeight() + toolbarHeight()
27
- }
28
-
29
6
  export default Navigation
30
- export { statusBarHeight, toolbarHeight, topBarHeight }
31
7
  export { RESULT_OK, RESULT_CANCEL } from './Navigation'
8
+ export { statusBarHeight, toolbarHeight, topBarHeight } from './GardenModule'
32
9
  export { withNavigationItem, NavigationProps, InjectedProps } from './NavigationComponentWrap'
33
10
 
34
11
  export * from './Navigator'
@@ -66,7 +66,7 @@ class Router {
66
66
  }
67
67
 
68
68
  private isRouteConfigInflated = false
69
- private routeDatas = new Map<string, RouteData>()
69
+ private routeDataSet = new Map<string, RouteData>()
70
70
 
71
71
  private inflateRouteData() {
72
72
  if (this.isRouteConfigInflated) {
@@ -76,7 +76,7 @@ class Router {
76
76
  const routeConfigs = Navigation.routeConfigs()
77
77
  for (const [moduleName, config] of routeConfigs) {
78
78
  const data = this.convertConfigToData(moduleName, config)
79
- this.routeDatas.set(moduleName, data)
79
+ this.routeDataSet.set(moduleName, data)
80
80
  }
81
81
  }
82
82
 
@@ -93,15 +93,23 @@ class Router {
93
93
  private async intercept(path: string) {
94
94
  for (let interceptor of this.interceptors.values()) {
95
95
  const result = interceptor(path)
96
- if (result instanceof Promise) {
97
- return await result
96
+ const intercepted = await this.resolveInterceptResult(result)
97
+ if (intercepted) {
98
+ return true
98
99
  }
100
+ }
101
+ return false
102
+ }
103
+
104
+ private resolveInterceptResult(result: boolean | Promise<boolean>) {
105
+ if (result instanceof Promise) {
99
106
  return result
100
107
  }
108
+ return Promise.resolve(result)
101
109
  }
102
110
 
103
111
  private pathToRoute(path: string, props: object, options: NavigationItem): RouteInfo | undefined {
104
- for (const data of this.routeDatas.values()) {
112
+ for (const data of this.routeDataSet.values()) {
105
113
  if (!data.regexp) {
106
114
  continue
107
115
  }
@@ -125,7 +133,7 @@ class Router {
125
133
  let data: RouteData | undefined = routeData
126
134
  while (data && data.dependency) {
127
135
  dependencies.push(data.dependency)
128
- data = this.routeDatas.get(data.dependency)
136
+ data = this.routeDataSet.get(data.dependency)
129
137
  }
130
138
  return dependencies.reverse()
131
139
  }