hybrid-navigation 4.0.8 → 5.0.0

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 (149) hide show
  1. package/HybridNavigation.podspec +9 -1
  2. package/README.md +12 -4
  3. package/android/build.gradle +5 -4
  4. package/android/proguard-rules.pro +3 -0
  5. package/android/src/main/java/com/navigation/androidx/AwesomeActivity.java +114 -23
  6. package/android/src/main/java/com/navigation/androidx/AwesomeFragment.java +116 -13
  7. package/android/src/main/java/com/navigation/androidx/DrawableUtils.java +83 -18
  8. package/android/src/main/java/com/navigation/androidx/DrawerFragment.java +192 -28
  9. package/android/src/main/java/com/navigation/androidx/FragmentHelper.java +11 -0
  10. package/android/src/main/java/com/navigation/androidx/HybridDrawerLayout.java +563 -143
  11. package/android/src/main/java/com/navigation/androidx/LifecycleDelegate.java +47 -15
  12. package/android/src/main/java/com/navigation/androidx/PresentableActivity.java +3 -0
  13. package/android/src/main/java/com/navigation/androidx/PresentationDelegate.java +8 -3
  14. package/android/src/main/java/com/navigation/androidx/StackDelegate.java +29 -9
  15. package/android/src/main/java/com/navigation/androidx/StackFragment.java +28 -3
  16. package/android/src/main/java/com/navigation/androidx/SystemUI.java +59 -90
  17. package/android/src/main/java/com/navigation/androidx/TabBar.java +21 -2
  18. package/android/src/main/java/com/navigation/androidx/TabBarFragment.java +24 -7
  19. package/android/src/main/java/com/navigation/androidx/TabView.java +11 -2
  20. package/android/src/main/java/com/reactnative/hybridnavigation/DispatchResult.java +59 -0
  21. package/android/src/main/java/com/reactnative/hybridnavigation/Garden.java +18 -10
  22. package/android/src/main/java/com/reactnative/hybridnavigation/GlobalStyle.java +15 -2
  23. package/android/src/main/java/com/reactnative/hybridnavigation/HBDRootView.java +3 -8
  24. package/android/src/main/java/com/reactnative/hybridnavigation/HybridFragment.java +113 -6
  25. package/android/src/main/java/com/reactnative/hybridnavigation/HybridNavigationPackage.java +13 -24
  26. package/android/src/main/java/com/reactnative/hybridnavigation/NativeEvent.java +5 -1
  27. package/android/src/main/java/com/reactnative/hybridnavigation/NativeNavigation.java +196 -194
  28. package/android/src/main/java/com/reactnative/hybridnavigation/NavigationCommandQueue.java +499 -0
  29. package/android/src/main/java/com/reactnative/hybridnavigation/Navigator.java +4 -1
  30. package/android/src/main/java/com/reactnative/hybridnavigation/OrientationCoordinator.java +162 -0
  31. package/android/src/main/java/com/reactnative/hybridnavigation/ReactAppCompatActivity.java +103 -66
  32. package/android/src/main/java/com/reactnative/hybridnavigation/ReactFragment.java +50 -87
  33. package/android/src/main/java/com/reactnative/hybridnavigation/ReactManager.java +156 -77
  34. package/android/src/main/java/com/reactnative/hybridnavigation/ReactStackFragment.java +6 -6
  35. package/android/src/main/java/com/reactnative/hybridnavigation/ReactSurfaceCleanup.java +3 -1
  36. package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarProvider.java +8 -1
  37. package/android/src/main/java/com/reactnative/hybridnavigation/SceneLifecycleState.java +21 -0
  38. package/android/src/main/java/com/reactnative/hybridnavigation/SceneLifecycleStateMachine.java +116 -0
  39. package/android/src/main/java/com/reactnative/hybridnavigation/ScreenOrientation.java +42 -0
  40. package/android/src/main/java/com/reactnative/hybridnavigation/Utils.java +17 -0
  41. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/DrawerNavigator.java +14 -6
  42. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/ScreenNavigator.java +62 -22
  43. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/StackNavigator.java +35 -16
  44. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/TabNavigator.java +16 -13
  45. package/dist/DeepLink.d.ts +3 -2
  46. package/dist/DeepLink.js +37 -14
  47. package/dist/NativeEvent.d.ts +4 -12
  48. package/dist/NativeNavigation.d.ts +17 -19
  49. package/dist/Navigation.d.ts +21 -19
  50. package/dist/Navigation.js +83 -89
  51. package/dist/NavigationComponentWrap.d.ts +4 -3
  52. package/dist/NavigationComponentWrap.js +3 -6
  53. package/dist/Navigator.d.ts +31 -42
  54. package/dist/Navigator.js +97 -90
  55. package/dist/Options.d.ts +3 -1
  56. package/dist/Route.d.ts +85 -18
  57. package/dist/handler/DispatchCommandHandler.d.ts +10 -6
  58. package/dist/handler/DispatchCommandHandler.js +41 -17
  59. package/dist/handler/LayoutCommandHandler.d.ts +7 -7
  60. package/dist/handler/LayoutCommandHandler.js +21 -15
  61. package/dist/handler/LifecycleEventHandler.d.ts +26 -0
  62. package/dist/handler/LifecycleEventHandler.js +136 -0
  63. package/dist/handler/ResultEventHandler.d.ts +14 -9
  64. package/dist/handler/ResultEventHandler.js +88 -13
  65. package/dist/hooks.d.ts +5 -2
  66. package/dist/hooks.js +26 -4
  67. package/dist/index.d.ts +13 -0
  68. package/dist/index.js +0 -2
  69. package/dist/routeConfigRegistry.d.ts +6 -0
  70. package/dist/routeConfigRegistry.js +19 -0
  71. package/dist/router/drawer.d.ts +2 -2
  72. package/dist/router/drawer.js +6 -3
  73. package/dist/router/index.d.ts +8 -5
  74. package/dist/router/index.js +127 -43
  75. package/dist/router/screen.d.ts +2 -2
  76. package/dist/router/screen.js +1 -1
  77. package/dist/router/stack.d.ts +2 -2
  78. package/dist/router/stack.js +59 -30
  79. package/dist/router/tabs.d.ts +2 -2
  80. package/dist/router/tabs.js +4 -1
  81. package/dist/store.d.ts +2 -2
  82. package/ios/HBDGlobalStyle.h +26 -0
  83. package/ios/{GlobalStyle.mm → HBDGlobalStyle.mm} +30 -27
  84. package/ios/HybridNavigation.h +4 -1
  85. package/ios/Navigator/HBDDrawerNavigator.mm +24 -8
  86. package/ios/Navigator/HBDNavigatorRegistry.mm +1 -0
  87. package/ios/Navigator/HBDScreenNavigator.mm +106 -52
  88. package/ios/Navigator/HBDStackNavigator.mm +109 -61
  89. package/ios/Navigator/HBDTabNavigator.mm +32 -14
  90. package/ios/React/HBDNativeNavigation.mm +109 -131
  91. package/ios/React/HBDNavigator.h +29 -5
  92. package/ios/React/HBDOrientationCoordinator.h +27 -0
  93. package/ios/React/HBDOrientationCoordinator.mm +282 -0
  94. package/ios/React/HBDReactBridgeManager.h +37 -19
  95. package/ios/React/HBDReactBridgeManager.mm +490 -96
  96. package/ios/React/HBDSceneLifecycleStateMachine.h +38 -0
  97. package/ios/React/HBDSceneLifecycleStateMachine.mm +180 -0
  98. package/ios/View/HBDRootView.h +2 -0
  99. package/ios/View/HBDRootView.mm +148 -0
  100. package/ios/View/UIImage+WithBadge.h +3 -3
  101. package/ios/View/UIImage+WithBadge.mm +10 -15
  102. package/ios/ViewController/HBDDrawerController.mm +127 -6
  103. package/ios/ViewController/HBDNavigationController.mm +17 -4
  104. package/ios/ViewController/HBDReactViewController.mm +59 -121
  105. package/ios/ViewController/HBDTabBarController.h +4 -0
  106. package/ios/ViewController/HBDTabBarController.mm +59 -44
  107. package/ios/ViewController/HBDViewController.h +10 -3
  108. package/ios/ViewController/HBDViewController.mm +161 -147
  109. package/ios/ViewController/UINavigationController+HBD.h +2 -2
  110. package/ios/ViewController/UINavigationController+HBD.mm +3 -3
  111. package/ios/ViewController/UIViewController+HBD.h +17 -10
  112. package/ios/ViewController/UIViewController+HBD.mm +85 -69
  113. package/package.json +1 -1
  114. package/src/DeepLink.ts +41 -14
  115. package/src/NativeEvent.ts +4 -14
  116. package/src/NativeNavigation.ts +22 -33
  117. package/src/Navigation.ts +162 -121
  118. package/src/NavigationComponentWrap.tsx +9 -9
  119. package/src/Navigator.ts +191 -153
  120. package/src/Options.ts +3 -1
  121. package/src/Route.ts +134 -19
  122. package/src/handler/DispatchCommandHandler.ts +55 -21
  123. package/src/handler/LayoutCommandHandler.ts +36 -17
  124. package/src/handler/LifecycleEventHandler.ts +172 -0
  125. package/src/handler/ResultEventHandler.ts +112 -19
  126. package/src/hooks.ts +39 -7
  127. package/src/index.ts +26 -2
  128. package/src/routeConfigRegistry.ts +26 -0
  129. package/src/router/drawer.ts +8 -5
  130. package/src/router/index.ts +161 -50
  131. package/src/router/screen.ts +3 -3
  132. package/src/router/stack.ts +80 -29
  133. package/src/router/tabs.ts +15 -7
  134. package/src/store.ts +1 -1
  135. package/android/src/main/java/androidx/fragment/app/InternalFragment.java +0 -22
  136. package/android/src/main/java/com/navigation/androidx/SystemUI30.java +0 -87
  137. package/android/src/main/java/com/reactnative/hybridnavigation/NativeGarden.java +0 -176
  138. package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBar.java +0 -130
  139. package/android/src/main/res/layout/nav_tab_bar_react.xml +0 -32
  140. package/android/src/main/res/layout/nav_tab_bar_react_indeterminate.xml +0 -32
  141. package/dist/NativeGarden.d.ts +0 -13
  142. package/dist/NativeGarden.js +0 -2
  143. package/dist/handler/VisibilityEventHandler.d.ts +0 -13
  144. package/dist/handler/VisibilityEventHandler.js +0 -39
  145. package/ios/GlobalStyle.h +0 -15
  146. package/ios/React/HBDNativeGarden.h +0 -10
  147. package/ios/React/HBDNativeGarden.mm +0 -111
  148. package/src/NativeGarden.ts +0 -16
  149. package/src/handler/VisibilityEventHandler.ts +0 -52
package/src/Navigation.ts CHANGED
@@ -2,25 +2,61 @@ import type React from 'react';
2
2
  import { AppRegistry, ComponentProvider } from 'react-native';
3
3
 
4
4
  import type { DefaultOptions, NavigationOption, TabBarStyle, TabItemInfo } from './Options';
5
- import type { BuildInLayout, Layout, Route, RouteGraph, RouteConfig } from './Route';
6
-
7
- import LayoutCommandHandler from './handler/LayoutCommandHandler';
8
- import DispatchCommandHandler from './handler/DispatchCommandHandler';
9
- import ResultEventHandler, { ResultType } from './handler/ResultEventHandler';
10
- import VisibilityEventHandler, {
5
+ import type {
6
+ BuildInLayout,
7
+ DispatchResult,
8
+ Layout,
9
+ NavigationResult,
10
+ ResultMap,
11
+ Route,
12
+ RouteConfig,
13
+ RouteGraph,
14
+ RouteName,
15
+ SceneLifecycleState,
16
+ SetRootOptions,
17
+ } from './Route';
18
+
19
+ import { layoutHandler, RootLayoutListener } from './handler/LayoutCommandHandler';
20
+ import { dispatchHandler } from './handler/DispatchCommandHandler';
21
+ import {
22
+ RESULT_BLOCK,
23
+ RESULT_CANCEL,
24
+ RESULT_OK,
25
+ resultHandler,
26
+ } from './handler/ResultEventHandler';
27
+ import {
28
+ GlobalSceneLifecycleListener,
11
29
  GlobalVisibilityEventListener,
30
+ lifecycleHandler,
31
+ SceneLifecycleListener,
12
32
  VisibilityEventListener,
13
- } from './handler/VisibilityEventHandler';
33
+ } from './handler/LifecycleEventHandler';
14
34
 
15
- import NativeEvent from './NativeEvent';
16
35
  import NativeNavigation from './NativeNavigation';
17
- import NativeGarden from './NativeGarden';
36
+ import store from './store';
37
+ import { withNavigation } from './NavigationComponentWrap';
38
+ import {
39
+ bumpRouteConfigVersion,
40
+ clearRouteConfigs,
41
+ setRouteConfig,
42
+ } from './routeConfigRegistry';
18
43
 
19
44
  export type { ResultType } from './handler/ResultEventHandler';
20
45
  import type { DispatchParams, NavigationInterceptor } from './handler/DispatchCommandHandler';
21
- export type { DispatchParams, NavigationInterceptor } from './handler/DispatchCommandHandler';
46
+ export type {
47
+ DispatchParams,
48
+ InterceptParams,
49
+ NavigationInterceptor,
50
+ } from './handler/DispatchCommandHandler';
51
+ export type {
52
+ GlobalSceneLifecycleListener,
53
+ GlobalVisibilityEventListener,
54
+ SceneLifecycleListener,
55
+ VisibilityEventListener,
56
+ } from './handler/LifecycleEventHandler';
57
+ export type { RootLayoutListener } from './handler/LayoutCommandHandler';
22
58
 
23
- export const { RESULT_CANCEL, RESULT_OK, RESULT_BLOCK } = NativeNavigation.getConstants();
59
+ export { RESULT_CANCEL, RESULT_OK, RESULT_BLOCK };
24
60
 
25
61
  export type NavigationSubscription = {
26
62
  remove: () => void;
@@ -31,14 +67,15 @@ export type HOC = (WrappedComponent: React.ComponentType<any>) => React.Componen
31
67
  export interface Navigation {
32
68
  startRegisterComponent(hoc?: HOC): void;
33
69
  endRegisterComponent(): void;
34
- registerComponent(
35
- appKey: string,
70
+ registerComponent<Name extends RouteName = RouteName>(
71
+ appKey: Name,
36
72
  getComponentFunc: ComponentProvider,
37
73
  routeConfig?: RouteConfig,
38
74
  ): void;
39
75
 
40
- routeConfigs(): Map<string, RouteConfig>;
41
- setNavigationComponentWrap(wrap: (moduleName: string) => HOC): void;
76
+ addLifecycleListener(sceneId: string, listener: SceneLifecycleListener): NavigationSubscription;
77
+ addGlobalLifecycleListener(listener: GlobalSceneLifecycleListener): NavigationSubscription;
78
+ getSceneState(sceneId: string): SceneLifecycleState;
42
79
  addGlobalVisibilityEventListener(
43
80
  listener: GlobalVisibilityEventListener,
44
81
  ): NavigationSubscription;
@@ -46,46 +83,53 @@ export interface Navigation {
46
83
  sceneId: string,
47
84
  listener: VisibilityEventListener,
48
85
  ): NavigationSubscription;
49
- dispatch(sceneId: string, action: string, params?: DispatchParams): Promise<boolean>;
50
- setInterceptor(interceptor: NavigationInterceptor): void;
51
- setResult<T extends ResultType>(sceneId: string, resultCode: number, data?: T): void;
52
- result<T extends ResultType>(sceneId: string, resultCode: number): Promise<[number, T]>;
53
- unmount(sceneId: string): void;
54
- setRoot(layout: BuildInLayout | Layout, sticky?: boolean): Promise<boolean>;
55
- setRootLayoutUpdateListener(willSetRoot?: () => void, didSetRoot?: () => void): void;
86
+
87
+ dispatch(sceneId: string, action: string, params?: DispatchParams): Promise<DispatchResult>;
88
+ addInterceptor(interceptor: NavigationInterceptor): NavigationSubscription;
89
+ setResult<T extends ResultMap = ResultMap>(
90
+ sceneId: string,
91
+ resultCode: number,
92
+ data?: T | null,
93
+ ): void;
94
+ result<T = unknown>(sceneId: string, requestCode: number): Promise<NavigationResult<T>>;
95
+ setRoot(layout: BuildInLayout | Layout, options?: SetRootOptions): Promise<DispatchResult>;
96
+ addRootLayoutUpdateListener(
97
+ willSetRoot?: RootLayoutListener,
98
+ didSetRoot?: RootLayoutListener,
99
+ ): NavigationSubscription;
100
+
56
101
  currentTab(sceneId: string): Promise<number>;
57
- findSceneIdByModuleName(moduleName: string): Promise<string | null>;
102
+ findSceneIdByModuleName(moduleName: RouteName): Promise<string | null>;
58
103
  isStackRoot(sceneId: string): Promise<boolean>;
59
- signalFirstRenderComplete(sceneId: string): void;
60
- currentRoute(): Promise<Route>;
104
+ currentRoute(): Promise<Route | null>;
61
105
  routeGraph(): Promise<RouteGraph[]>;
106
+
62
107
  setDefaultOptions(options: DefaultOptions): void;
63
108
  updateOptions(sceneId: string, options: NavigationOption): void;
64
109
  updateTabBar(sceneId: string, options: TabBarStyle): void;
65
110
  setTabItem(sceneId: string, item: TabItemInfo | TabItemInfo[]): void;
66
- setMenuInteractive(sceneId: string, enabled: boolean): void;
111
+ setMenuInteractive(sceneId: string, enabled: boolean): Promise<DispatchResult>;
67
112
  }
68
113
 
69
114
  class NavigationImpl implements Navigation {
70
- private dispatchHandler = new DispatchCommandHandler();
71
- private resultHandler = new ResultEventHandler();
72
- private layoutHandler = new LayoutCommandHandler();
73
- private visibilityHandler = new VisibilityEventHandler();
74
-
75
115
  constructor() {
76
- this.handleTabSwitch();
77
- this.layoutHandler.handleRootLayoutChange();
78
- this.visibilityHandler.handleComponentVisibility();
79
- this.resultHandler.handleComponentResult();
116
+ layoutHandler.handleRootLayoutChange(() => {
117
+ resultHandler.invalidateAll('root_reset');
118
+ });
119
+ lifecycleHandler.handleSceneLifecycle(sceneId => {
120
+ resultHandler.invalidateResultEventListener(sceneId, 'unmounted');
121
+ store.removeNavigator(sceneId);
122
+ });
123
+ resultHandler.handleComponentResult();
80
124
  }
81
125
 
82
- private wrap?: (moduleName: string) => HOC;
83
126
  private hoc?: HOC;
84
127
  private registerEnded = false;
85
128
 
86
129
  startRegisterComponent(hoc?: HOC) {
87
130
  this.hoc = hoc;
88
131
  this.registerEnded = false;
132
+ clearRouteConfigs();
89
133
  NativeNavigation.startRegisterReactComponent();
90
134
  }
91
135
 
@@ -95,50 +139,81 @@ class NavigationImpl implements Navigation {
95
139
  return;
96
140
  }
97
141
  this.registerEnded = true;
142
+ bumpRouteConfigVersion();
98
143
  NativeNavigation.endRegisterReactComponent();
99
144
  }
100
145
 
101
- registerComponent(
102
- appKey: string,
146
+ registerComponent<Name extends RouteName = RouteName>(
147
+ appKey: Name,
103
148
  getComponentFunc: ComponentProvider,
104
149
  routeConfig?: RouteConfig,
105
150
  ) {
106
- if (routeConfig) {
107
- this.registerRoute(appKey, routeConfig);
151
+ if (routeConfig && (routeConfig.path || routeConfig.dependency || routeConfig.mode)) {
152
+ setRouteConfig(appKey, routeConfig);
153
+ }
154
+
155
+ const hoc = this.hoc;
156
+
157
+ if (routeConfig?.options !== undefined || routeConfig?.lazy === true) {
158
+ NativeNavigation.registerReactComponent(appKey, routeConfig.options ?? {});
159
+ let CachedRootComponent: React.ComponentType<any> | undefined;
160
+ AppRegistry.registerComponent(appKey, () => {
161
+ if (!CachedRootComponent) {
162
+ let WrappedComponent = getComponentFunc();
163
+ if (__DEV__ && (WrappedComponent as any)?.navigationItem) {
164
+ console.warn(
165
+ `[hybrid-navigation] "${appKey}" enabled lazy registration via registerComponent(), so withNavigationItem() on the component is ignored.`,
166
+ );
167
+ }
168
+ if (hoc) {
169
+ WrappedComponent = hoc(WrappedComponent);
170
+ }
171
+ CachedRootComponent = withNavigation(appKey)(WrappedComponent);
172
+ }
173
+ return CachedRootComponent;
174
+ });
175
+ return;
108
176
  }
109
177
 
110
178
  let WrappedComponent = getComponentFunc();
111
- if (this.hoc) {
112
- WrappedComponent = this.hoc(WrappedComponent);
179
+ if (hoc) {
180
+ WrappedComponent = hoc(WrappedComponent);
113
181
  }
114
182
 
115
183
  const options: object = (WrappedComponent as any).navigationItem || {};
116
184
  NativeNavigation.registerReactComponent(appKey, options);
117
185
 
118
- let RootComponent = this.wrap!(appKey)(WrappedComponent);
186
+ const RootComponent = withNavigation(appKey)(WrappedComponent);
119
187
  AppRegistry.registerComponent(appKey, () => RootComponent);
120
188
  }
121
189
 
122
- private _routeConfigs = new Map<string, RouteConfig>();
123
-
124
- private registerRoute(moduleName: string, route: RouteConfig) {
125
- this._routeConfigs.set(moduleName, route);
190
+ addLifecycleListener(
191
+ sceneId: string,
192
+ listener: SceneLifecycleListener,
193
+ ): NavigationSubscription {
194
+ lifecycleHandler.addLifecycleListener(sceneId, listener);
195
+ return {
196
+ remove: () => lifecycleHandler.removeLifecycleListener(sceneId, listener),
197
+ };
126
198
  }
127
199
 
128
- routeConfigs() {
129
- return this._routeConfigs;
200
+ addGlobalLifecycleListener(listener: GlobalSceneLifecycleListener): NavigationSubscription {
201
+ lifecycleHandler.addGlobalLifecycleListener(listener);
202
+ return {
203
+ remove: () => lifecycleHandler.removeGlobalLifecycleListener(listener),
204
+ };
130
205
  }
131
206
 
132
- setNavigationComponentWrap(wrap: (moduleName: string) => HOC) {
133
- this.wrap = wrap;
207
+ getSceneState(sceneId: string): SceneLifecycleState {
208
+ return lifecycleHandler.getSceneState(sceneId);
134
209
  }
135
210
 
136
211
  addGlobalVisibilityEventListener(
137
212
  listener: GlobalVisibilityEventListener,
138
213
  ): NavigationSubscription {
139
- this.visibilityHandler.addGlobalVisibilityEventListener(listener);
214
+ lifecycleHandler.addGlobalVisibilityEventListener(listener);
140
215
  return {
141
- remove: () => this.visibilityHandler.removeGlobalVisibilityEventListener(listener),
216
+ remove: () => lifecycleHandler.removeGlobalVisibilityEventListener(listener),
142
217
  };
143
218
  }
144
219
 
@@ -146,120 +221,86 @@ class NavigationImpl implements Navigation {
146
221
  sceneId: string,
147
222
  listener: VisibilityEventListener,
148
223
  ): NavigationSubscription {
149
- this.visibilityHandler.addVisibilityEventListener(sceneId, listener);
224
+ lifecycleHandler.addVisibilityEventListener(sceneId, listener);
150
225
  return {
151
- remove: () => this.visibilityHandler.removeVisibilityEventListener(sceneId, listener),
226
+ remove: () => lifecycleHandler.removeVisibilityEventListener(sceneId, listener),
152
227
  };
153
228
  }
154
229
 
155
230
  dispatch(sceneId: string, action: string, params: DispatchParams = {}) {
156
- return this.dispatchHandler.dispatch(sceneId, action, params);
157
- }
158
-
159
- private handleTabSwitch() {
160
- NativeEvent.onSwitchTab(({ sceneId, from, to }) => {
161
- this.dispatch(sceneId, 'switchTab', { from, to });
162
- });
231
+ return dispatchHandler.dispatch(sceneId, action, params);
163
232
  }
164
233
 
165
- setInterceptor(interceptor: NavigationInterceptor) {
166
- this.dispatchHandler.setInterceptor(interceptor);
234
+ addInterceptor(interceptor: NavigationInterceptor): NavigationSubscription {
235
+ dispatchHandler.addInterceptor(interceptor);
236
+ return {
237
+ remove: () => dispatchHandler.removeInterceptor(interceptor),
238
+ };
167
239
  }
168
240
 
169
- setResult = <T extends ResultType>(
241
+ setResult = <T extends ResultMap = ResultMap>(
170
242
  sceneId: string,
171
243
  resultCode: number,
172
- data: T = null as T,
244
+ data: T | null = null,
173
245
  ): void => {
174
- if (resultCode < RESULT_OK) {
175
- console.warn(
176
- '`resultCode` can only be `RESULT_OK`, `RESULT_CANCEL` or an integer greater than 0.',
177
- );
178
- }
179
- NativeNavigation.setResult(sceneId, resultCode, data as object);
246
+ resultHandler.setResult(sceneId, resultCode, data);
180
247
  };
181
248
 
182
- result<T extends ResultType>(sceneId: string, resultCode: number) {
183
- return this.resultHandler.waitResult<T>(sceneId, resultCode);
184
- }
185
-
186
- unmount(sceneId: string) {
187
- this.resultHandler.invalidateResultEventListener(sceneId);
249
+ result<T = unknown>(sceneId: string, requestCode: number) {
250
+ return resultHandler.waitResult<T>(sceneId, requestCode);
188
251
  }
189
252
 
190
- setRoot(layout: BuildInLayout | Layout, sticky = false) {
191
- return this.layoutHandler.setRoot(layout, sticky);
253
+ setRoot(layout: BuildInLayout | Layout, options?: SetRootOptions) {
254
+ return layoutHandler.setRoot(layout, options);
192
255
  }
193
256
 
194
- setRootLayoutUpdateListener(willSetRoot = () => {}, didSetRoot = () => {}) {
195
- this.layoutHandler.setRootLayoutUpdateListener(willSetRoot, didSetRoot);
257
+ addRootLayoutUpdateListener(
258
+ willSetRoot?: RootLayoutListener,
259
+ didSetRoot?: RootLayoutListener,
260
+ ): NavigationSubscription {
261
+ const remove = layoutHandler.addRootLayoutUpdateListener(willSetRoot, didSetRoot);
262
+ return { remove };
196
263
  }
197
264
 
198
265
  currentTab(sceneId: string) {
199
- return new Promise<number>(resolve => {
200
- NativeNavigation.currentTab(sceneId, (_, index) => {
201
- resolve(index);
202
- });
203
- });
266
+ return NativeNavigation.currentTab(sceneId);
204
267
  }
205
268
 
206
- findSceneIdByModuleName(moduleName: string) {
207
- return new Promise<string | null>(resolve => {
208
- NativeNavigation.findSceneIdByModuleName(moduleName, (_, sceneId) => {
209
- resolve(sceneId);
210
- });
211
- });
269
+ findSceneIdByModuleName(moduleName: RouteName) {
270
+ return NativeNavigation.findSceneIdByModuleName(moduleName);
212
271
  }
213
272
 
214
273
  isStackRoot(sceneId: string) {
215
- return new Promise<boolean>(resolve => {
216
- NativeNavigation.isStackRoot(sceneId, (_, result) => {
217
- resolve(result);
218
- });
219
- });
274
+ return NativeNavigation.isStackRoot(sceneId);
220
275
  }
221
276
 
222
- signalFirstRenderComplete(sceneId: string) {
223
- NativeNavigation.signalFirstRenderComplete(sceneId);
224
- }
225
-
226
- currentRoute(): Promise<Route> {
227
- return new Promise<Route>(resolve => {
228
- NativeNavigation.currentRoute((_, route) => {
229
- resolve(route);
230
- });
231
- });
277
+ currentRoute(): Promise<Route | null> {
278
+ return NativeNavigation.currentRoute();
232
279
  }
233
280
 
234
281
  routeGraph(): Promise<RouteGraph[]> {
235
- return new Promise<RouteGraph[]>(resolve => {
236
- NativeNavigation.routeGraph((_, graph) => {
237
- resolve(graph);
238
- });
239
- });
282
+ return NativeNavigation.routeGraph();
240
283
  }
241
284
 
242
285
  setDefaultOptions(options: DefaultOptions) {
243
- NativeGarden.setStyle(options);
286
+ NativeNavigation.setDefaultOptions(options);
244
287
  }
245
288
 
246
289
  updateOptions(sceneId: string, options: NavigationOption) {
247
- NativeGarden.updateOptions(sceneId, options);
290
+ NativeNavigation.updateOptions(sceneId, options);
248
291
  }
249
292
 
250
293
  updateTabBar(sceneId: string, options: TabBarStyle) {
251
- NativeGarden.updateTabBar(sceneId, options);
294
+ NativeNavigation.updateTabBar(sceneId, options);
252
295
  }
253
296
 
254
297
  setTabItem(sceneId: string, item: TabItemInfo | TabItemInfo[]) {
255
- if (!Array.isArray(item)) {
256
- item = [item];
257
- }
258
- NativeGarden.setTabItem(sceneId, item);
298
+ const items = Array.isArray(item) ? item : [item];
299
+ NativeNavigation.setTabItem(sceneId, items);
259
300
  }
260
301
 
261
302
  setMenuInteractive(sceneId: string, enabled: boolean) {
262
- NativeGarden.setMenuInteractive(sceneId, enabled);
303
+ return this.dispatch(sceneId, 'setMenuInteractive', { enabled });
263
304
  }
264
305
  }
265
306
 
@@ -1,12 +1,15 @@
1
1
  import React, { useEffect } from 'react';
2
2
  import type { NavigationItem } from './Options';
3
+ import type { HasTypedRoutes, RouteName, RoutePropsOf } from './Route';
3
4
  import { Navigator, NavigationContext } from './Navigator';
4
- import Navigation from './Navigation';
5
+ import NativeNavigation from './NativeNavigation';
5
6
 
6
- export interface NavigationProps {
7
- navigator: Navigator;
7
+ export type NavigationProps<Name extends RouteName = RouteName> = (HasTypedRoutes extends true
8
+ ? RoutePropsOf<Name>
9
+ : Record<string, any>) & {
10
+ navigator: Navigator<Name>;
8
11
  sceneId: string;
9
- }
12
+ };
10
13
 
11
14
  interface NativeProps {
12
15
  sceneId: string;
@@ -28,10 +31,7 @@ export function withNavigation(moduleName: string) {
28
31
  }
29
32
 
30
33
  useEffect(() => {
31
- Navigation.signalFirstRenderComplete(sceneId);
32
- return () => {
33
- Navigator.unmount(sceneId);
34
- };
34
+ NativeNavigation.signalFirstRenderComplete(sceneId);
35
35
  }, [sceneId]);
36
36
 
37
37
  const injected = {
@@ -53,7 +53,7 @@ export function withNavigation(moduleName: string) {
53
53
 
54
54
  export function withNavigationItem(item: NavigationItem) {
55
55
  return function (WrappedComponent: React.ComponentType<any>): React.ComponentType<any> {
56
- let navigationItem = (WrappedComponent as any).navigationItem;
56
+ const navigationItem = (WrappedComponent as any).navigationItem;
57
57
  if (navigationItem) {
58
58
  (WrappedComponent as any).navigationItem = {
59
59
  ...navigationItem,