hybrid-navigation 5.3.0 → 5.5.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 (150) hide show
  1. package/HybridNavigation.podspec +1 -0
  2. package/android/proguard-rules.pro +5 -0
  3. package/android/src/main/java/com/navigation/androidx/AppUtils.java +8 -1
  4. package/android/src/main/java/com/navigation/androidx/AwesomeActivity.java +115 -36
  5. package/android/src/main/java/com/navigation/androidx/AwesomeFragment.java +153 -100
  6. package/android/src/main/java/com/navigation/androidx/DefaultTabBarProvider.java +1 -1
  7. package/android/src/main/java/com/navigation/androidx/DrawableUtils.java +5 -1
  8. package/android/src/main/java/com/navigation/androidx/DrawerFragment.java +95 -39
  9. package/android/src/main/java/com/navigation/androidx/FragmentHelper.java +195 -29
  10. package/android/src/main/java/com/navigation/androidx/HybridDrawerLayout.java +225 -27
  11. package/android/src/main/java/com/navigation/androidx/LifecycleDelegate.java +33 -9
  12. package/android/src/main/java/com/navigation/androidx/PresentationDelegate.java +5 -107
  13. package/android/src/main/java/com/navigation/androidx/StackDelegate.java +37 -10
  14. package/android/src/main/java/com/navigation/androidx/StackFragment.java +82 -19
  15. package/android/src/main/java/com/navigation/androidx/Style.java +8 -4
  16. package/android/src/main/java/com/navigation/androidx/SystemUI.java +17 -5
  17. package/android/src/main/java/com/navigation/androidx/TabBar.java +69 -29
  18. package/android/src/main/java/com/navigation/androidx/TabBarFragment.java +48 -11
  19. package/android/src/main/java/com/navigation/androidx/TabBarItem.java +1 -2
  20. package/android/src/main/java/com/navigation/androidx/TabView.java +20 -10
  21. package/android/src/main/java/com/reactnative/hybridnavigation/Constants.java +1 -0
  22. package/android/src/main/java/com/reactnative/hybridnavigation/Garden.java +19 -15
  23. package/android/src/main/java/com/reactnative/hybridnavigation/GlobalStyle.java +10 -48
  24. package/android/src/main/java/com/reactnative/hybridnavigation/HBDRootView.java +22 -23
  25. package/android/src/main/java/com/reactnative/hybridnavigation/HybridFragment.java +54 -22
  26. package/android/src/main/java/com/reactnative/hybridnavigation/NativeEvent.java +4 -2
  27. package/android/src/main/java/com/reactnative/hybridnavigation/NativeNavigation.java +35 -64
  28. package/android/src/main/java/com/reactnative/hybridnavigation/NavigationCommandQueue.java +185 -121
  29. package/android/src/main/java/com/reactnative/hybridnavigation/Navigator.java +21 -5
  30. package/android/src/main/java/com/reactnative/hybridnavigation/NavigatorRegistry.java +27 -30
  31. package/android/src/main/java/com/reactnative/hybridnavigation/OrientationCoordinator.java +41 -4
  32. package/android/src/main/java/com/reactnative/hybridnavigation/Parameters.java +55 -154
  33. package/android/src/main/java/com/reactnative/hybridnavigation/ReactAppCompatActivity.java +30 -1
  34. package/android/src/main/java/com/reactnative/hybridnavigation/ReactAppCompatActivityDelegate.java +12 -37
  35. package/android/src/main/java/com/reactnative/hybridnavigation/ReactFragment.java +31 -181
  36. package/android/src/main/java/com/reactnative/hybridnavigation/ReactManager.java +115 -71
  37. package/android/src/main/java/com/reactnative/hybridnavigation/ReactStackFragment.java +27 -16
  38. package/android/src/main/java/com/reactnative/hybridnavigation/ReactSurfaceCleanup.java +50 -8
  39. package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarFragment.java +34 -4
  40. package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarProvider.java +39 -10
  41. package/android/src/main/java/com/reactnative/hybridnavigation/RemovalPlan.java +76 -0
  42. package/android/src/main/java/com/reactnative/hybridnavigation/SceneLifecycleStateMachine.java +72 -6
  43. package/android/src/main/java/com/reactnative/hybridnavigation/Utils.java +19 -3
  44. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/DrawerNavigator.java +11 -5
  45. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/ScreenNavigator.java +217 -99
  46. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/StackNavigator.java +122 -59
  47. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/TabNavigator.java +87 -24
  48. package/dist/DeepLink.d.ts +3 -1
  49. package/dist/DeepLink.js +39 -19
  50. package/dist/NativeNavigation.d.ts +8 -5
  51. package/dist/Navigation.d.ts +9 -24
  52. package/dist/Navigation.js +32 -97
  53. package/dist/NavigationComponentWrap.d.ts +1 -2
  54. package/dist/NavigationComponentWrap.js +0 -15
  55. package/dist/Navigator.d.ts +7 -5
  56. package/dist/Navigator.js +38 -33
  57. package/dist/Options.d.ts +1 -6
  58. package/dist/Options.js +1 -2
  59. package/dist/Route.d.ts +24 -12
  60. package/dist/handler/DispatchCommandHandler.d.ts +4 -5
  61. package/dist/handler/DispatchCommandHandler.js +37 -16
  62. package/dist/handler/LayoutCommandHandler.js +18 -3
  63. package/dist/handler/LeaveGuardHandler.d.ts +12 -8
  64. package/dist/handler/LeaveGuardHandler.js +174 -281
  65. package/dist/handler/LifecycleEventHandler.d.ts +7 -4
  66. package/dist/handler/LifecycleEventHandler.js +119 -32
  67. package/dist/handler/ResultEventHandler.d.ts +2 -2
  68. package/dist/handler/ResultEventHandler.js +72 -36
  69. package/dist/handler/SceneExitHandler.d.ts +6 -0
  70. package/dist/handler/SceneExitHandler.js +48 -8
  71. package/dist/hooks.d.ts +1 -0
  72. package/dist/hooks.js +39 -23
  73. package/dist/index.d.ts +9 -8
  74. package/dist/index.js +5 -8
  75. package/dist/routeGraph.d.ts +5 -0
  76. package/dist/routeGraph.js +47 -0
  77. package/dist/router/drawer.d.ts +2 -2
  78. package/dist/router/drawer.js +19 -9
  79. package/dist/router/helpers.d.ts +17 -0
  80. package/dist/router/helpers.js +90 -0
  81. package/dist/router/index.d.ts +2 -2
  82. package/dist/router/index.js +169 -97
  83. package/dist/router/screen.d.ts +2 -2
  84. package/dist/router/screen.js +16 -7
  85. package/dist/router/stack.d.ts +2 -2
  86. package/dist/router/stack.js +24 -49
  87. package/dist/router/tabs.js +5 -1
  88. package/dist/store.d.ts +2 -0
  89. package/dist/store.js +4 -0
  90. package/ios/HBDGlobalStyle.h +0 -1
  91. package/ios/HBDGlobalStyle.mm +27 -39
  92. package/ios/HBDUtils.h +0 -2
  93. package/ios/HBDUtils.mm +81 -41
  94. package/ios/Navigator/HBDDrawerNavigator.mm +31 -26
  95. package/ios/Navigator/HBDNavigatorRegistry.mm +23 -26
  96. package/ios/Navigator/HBDScreenNavigator.mm +240 -137
  97. package/ios/Navigator/HBDStackNavigator.mm +147 -97
  98. package/ios/Navigator/HBDTabNavigator.mm +99 -46
  99. package/ios/React/HBDNativeEvent.mm +38 -5
  100. package/ios/React/HBDNativeNavigation.mm +49 -51
  101. package/ios/React/HBDNavigationCommandQueue.h +55 -0
  102. package/ios/React/HBDNavigationCommandQueue.mm +341 -0
  103. package/ios/React/HBDNavigator.h +20 -0
  104. package/ios/React/HBDOrientationCoordinator.mm +26 -3
  105. package/ios/React/HBDReactBridgeManager.h +18 -6
  106. package/ios/React/HBDReactBridgeManager.mm +536 -315
  107. package/ios/React/HBDSceneLifecycleStateMachine.h +2 -0
  108. package/ios/React/HBDSceneLifecycleStateMachine.mm +18 -0
  109. package/ios/View/HBDRootView.h +1 -0
  110. package/ios/View/HBDRootView.mm +112 -4
  111. package/ios/View/UIImage+WithBadge.mm +9 -7
  112. package/ios/ViewController/HBDDrawerController.h +10 -0
  113. package/ios/ViewController/HBDDrawerController.mm +103 -71
  114. package/ios/ViewController/HBDNavigationController.mm +166 -58
  115. package/ios/ViewController/HBDReactViewController.h +0 -2
  116. package/ios/ViewController/HBDReactViewController.mm +13 -102
  117. package/ios/ViewController/HBDTabBarController.mm +67 -33
  118. package/ios/ViewController/HBDViewController.h +6 -0
  119. package/ios/ViewController/HBDViewController.mm +94 -37
  120. package/ios/ViewController/UINavigationController+HBD.h +2 -2
  121. package/ios/ViewController/UINavigationController+HBD.mm +13 -13
  122. package/ios/ViewController/UIViewController+HBD.h +23 -1
  123. package/ios/ViewController/UIViewController+HBD.mm +298 -40
  124. package/package.json +1 -1
  125. package/src/DeepLink.ts +39 -19
  126. package/src/NativeNavigation.ts +17 -5
  127. package/src/Navigation.ts +49 -170
  128. package/src/NavigationComponentWrap.tsx +1 -16
  129. package/src/Navigator.ts +50 -52
  130. package/src/Options.ts +4 -9
  131. package/src/Route.ts +37 -19
  132. package/src/handler/DispatchCommandHandler.ts +42 -20
  133. package/src/handler/LayoutCommandHandler.ts +15 -3
  134. package/src/handler/LeaveGuardHandler.ts +224 -329
  135. package/src/handler/LifecycleEventHandler.ts +131 -37
  136. package/src/handler/ResultEventHandler.ts +71 -37
  137. package/src/handler/SceneExitHandler.ts +60 -9
  138. package/src/hooks.ts +54 -26
  139. package/src/index.ts +77 -8
  140. package/src/routeGraph.ts +50 -0
  141. package/src/router/drawer.ts +21 -10
  142. package/src/router/helpers.ts +113 -0
  143. package/src/router/index.ts +187 -112
  144. package/src/router/screen.ts +35 -8
  145. package/src/router/stack.ts +40 -53
  146. package/src/router/tabs.ts +5 -1
  147. package/src/store.ts +5 -0
  148. package/dist/sceneCoverage.d.ts +0 -2
  149. package/dist/sceneCoverage.js +0 -25
  150. package/src/sceneCoverage.ts +0 -30
package/src/Navigation.ts CHANGED
@@ -1,40 +1,32 @@
1
1
  import type React from 'react';
2
2
  import { AppRegistry, ComponentProvider } from 'react-native';
3
3
 
4
- import type { DefaultOptions, NavigationOption, TabBarStyle, TabItemInfo } from './Options';
4
+ import type { DefaultOptions } from './Options';
5
5
  import type {
6
- BeforeRemoveListener,
7
- BeforeRemoveOptions,
8
6
  DispatchResult,
9
7
  Layout,
10
- NavigationResult,
11
8
  NavigationSnapshot,
12
- ResultMap,
13
9
  Route,
14
10
  RouteConfig,
15
- RouteGraph,
16
11
  RouteName,
17
- SceneLifecycleState,
18
12
  SetRootOptions,
19
13
  } from './Route';
20
14
 
21
15
  import { layoutHandler, RootLayoutListener } from './handler/LayoutCommandHandler';
22
16
  import { dispatchHandler } from './handler/DispatchCommandHandler';
23
- import {
24
- RESULT_BLOCK,
25
- RESULT_CANCEL,
26
- RESULT_OK,
27
- resultHandler,
28
- } from './handler/ResultEventHandler';
17
+ import { RESULT_CANCEL, RESULT_OK, resultHandler } from './handler/ResultEventHandler';
29
18
  import {
30
19
  GlobalSceneLifecycleListener,
31
20
  lifecycleHandler,
32
- SceneLifecycleListener,
33
21
  } from './handler/LifecycleEventHandler';
34
22
 
35
- import { leaveGuardHandler, BEFORE_REMOVE_SOURCE_PROP } from './handler/LeaveGuardHandler';
23
+ import { leaveGuardHandler } from './handler/LeaveGuardHandler';
24
+ import {
25
+ cleanupSceneExitHandler,
26
+ clearExitHandlers,
27
+ setExitHandlerPresenceListener,
28
+ } from './handler/SceneExitHandler';
36
29
  import NativeNavigation from './NativeNavigation';
37
- import { isSceneCoveredInLayers } from './sceneCoverage';
38
30
  import store from './store';
39
31
  import { withNavigation } from './NavigationComponentWrap';
40
32
  import {
@@ -55,7 +47,7 @@ export type {
55
47
  } from './handler/LifecycleEventHandler';
56
48
  export type { RootLayoutListener } from './handler/LayoutCommandHandler';
57
49
 
58
- export { RESULT_CANCEL, RESULT_OK, RESULT_BLOCK };
50
+ export { RESULT_CANCEL, RESULT_OK };
59
51
 
60
52
  export type NavigationSubscription = {
61
53
  remove: () => void;
@@ -72,56 +64,45 @@ export interface Navigation {
72
64
  routeConfig?: RouteConfig,
73
65
  ): void;
74
66
 
75
- addLifecycleListener(sceneId: string, listener: SceneLifecycleListener): NavigationSubscription;
76
- addGlobalLifecycleListener(listener: GlobalSceneLifecycleListener): NavigationSubscription;
77
- getSceneState(sceneId: string): SceneLifecycleState;
78
-
79
- dispatch(sceneId: string, action: string, params?: DispatchParams): Promise<DispatchResult>;
80
- addInterceptor(interceptor: NavigationInterceptor): NavigationSubscription;
81
- setResult<T extends ResultMap = ResultMap>(
82
- sceneId: string,
83
- resultCode: number,
84
- data?: T | null,
85
- ): void;
86
- result<T = unknown>(sceneId: string, requestCode: number): Promise<NavigationResult<T>>;
67
+ setDefaultOptions(options: DefaultOptions): void;
87
68
  setRoot(layout: Layout, options?: SetRootOptions): Promise<DispatchResult>;
88
69
  addRootLayoutUpdateListener(
89
70
  willSetRoot?: RootLayoutListener,
90
71
  didSetRoot?: RootLayoutListener,
91
72
  ): NavigationSubscription;
92
73
 
93
- currentTab(sceneId: string): Promise<number>;
94
- findSceneIdByModuleName(moduleName: RouteName): Promise<string | null>;
95
- isStackRoot(sceneId: string): Promise<boolean>;
74
+ dispatch(sceneId: string, action: string, params?: DispatchParams): Promise<DispatchResult>;
75
+ addInterceptor(interceptor: NavigationInterceptor): NavigationSubscription;
76
+
96
77
  currentRoute(): Promise<Route | null>;
97
78
  navigationSnapshot(): Promise<NavigationSnapshot>;
98
- addBeforeRemoveListener(
99
- sceneId: string,
100
- listener: BeforeRemoveListener,
101
- options?: BeforeRemoveOptions,
102
- ): NavigationSubscription;
103
- isSceneCovered(sceneId: string): Promise<boolean>;
104
- /** @deprecated Use (await navigationSnapshot()).layers instead. */
105
- routeGraph(): Promise<RouteGraph[]>;
106
-
107
- setDefaultOptions(options: DefaultOptions): void;
108
- updateOptions(sceneId: string, options: NavigationOption): void;
109
- updateTabBar(sceneId: string, options: TabBarStyle): void;
110
- setTabItem(sceneId: string, item: TabItemInfo | TabItemInfo[]): void;
111
- setMenuInteractive(sceneId: string, enabled: boolean): Promise<DispatchResult>;
79
+ addGlobalLifecycleListener(listener: GlobalSceneLifecycleListener): NavigationSubscription;
112
80
  }
113
81
 
114
82
  class NavigationImpl implements Navigation {
115
83
  constructor() {
116
- leaveGuardHandler.setDispatcher((sceneId, action, params) => dispatchHandler.dispatch(sceneId, action, params));
117
- leaveGuardHandler.handleNativeBeforeRemoveRequests();
84
+ setExitHandlerPresenceListener((sceneId, active) => {
85
+ leaveGuardHandler.setExitHandlerActive(sceneId, active);
86
+ });
87
+ leaveGuardHandler.handleNativeBeforeRemoveRequests(sceneId =>
88
+ dispatchHandler.dispatch(
89
+ sceneId,
90
+ 'close',
91
+ { from: store.getNavigator(sceneId)?.moduleName },
92
+ { source: 'back' },
93
+ ),
94
+ );
118
95
  layoutHandler.handleRootLayoutChange(() => {
119
96
  leaveGuardHandler.onRootReset();
97
+ lifecycleHandler.clearVisibleHolds();
120
98
  resultHandler.invalidateAll('root_reset');
99
+ clearExitHandlers();
100
+ store.clearNavigators();
121
101
  });
122
102
  lifecycleHandler.handleSceneLifecycle(sceneId => {
123
103
  leaveGuardHandler.onSceneDestroyed(sceneId);
124
104
  resultHandler.invalidateResultEventListener(sceneId, 'unmounted');
105
+ cleanupSceneExitHandler(sceneId);
125
106
  store.removeNavigator(sceneId);
126
107
  });
127
108
  resultHandler.handleComponentResult();
@@ -157,83 +138,22 @@ class NavigationImpl implements Navigation {
157
138
  }
158
139
 
159
140
  const hoc = this.hoc;
160
-
161
- if (routeConfig?.options !== undefined || routeConfig?.lazy === true) {
162
- NativeNavigation.registerReactComponent(appKey, routeConfig.options ?? {});
163
- let CachedRootComponent: React.ComponentType<any> | undefined;
164
- AppRegistry.registerComponent(appKey, () => {
165
- if (!CachedRootComponent) {
166
- let WrappedComponent = getComponentFunc();
167
- if (__DEV__ && (WrappedComponent as any)?.navigationItem) {
168
- console.warn(
169
- `[hybrid-navigation] "${appKey}" enabled lazy registration via registerComponent(), so withNavigationItem() on the component is ignored.`,
170
- );
171
- }
172
- if (hoc) {
173
- WrappedComponent = hoc(WrappedComponent);
174
- }
175
- CachedRootComponent = withNavigation(appKey)(WrappedComponent);
141
+ NativeNavigation.registerReactComponent(appKey, routeConfig?.options ?? {});
142
+ let CachedRootComponent: React.ComponentType<any> | undefined;
143
+ AppRegistry.registerComponent(appKey, () => {
144
+ if (!CachedRootComponent) {
145
+ let WrappedComponent = getComponentFunc();
146
+ if (hoc) {
147
+ WrappedComponent = hoc(WrappedComponent);
176
148
  }
177
- return CachedRootComponent;
178
- });
179
- return;
180
- }
181
-
182
- let WrappedComponent = getComponentFunc();
183
- if (hoc) {
184
- WrappedComponent = hoc(WrappedComponent);
185
- }
186
-
187
- const options: object = (WrappedComponent as any).navigationItem || {};
188
- NativeNavigation.registerReactComponent(appKey, options);
189
-
190
- const RootComponent = withNavigation(appKey)(WrappedComponent);
191
- AppRegistry.registerComponent(appKey, () => RootComponent);
192
- }
193
-
194
- addLifecycleListener(
195
- sceneId: string,
196
- listener: SceneLifecycleListener,
197
- ): NavigationSubscription {
198
- lifecycleHandler.addLifecycleListener(sceneId, listener);
199
- return {
200
- remove: () => lifecycleHandler.removeLifecycleListener(sceneId, listener),
201
- };
202
- }
203
-
204
- addGlobalLifecycleListener(listener: GlobalSceneLifecycleListener): NavigationSubscription {
205
- lifecycleHandler.addGlobalLifecycleListener(listener);
206
- return {
207
- remove: () => lifecycleHandler.removeGlobalLifecycleListener(listener),
208
- };
209
- }
210
-
211
- getSceneState(sceneId: string): SceneLifecycleState {
212
- return lifecycleHandler.getSceneState(sceneId);
213
- }
214
-
215
-
216
- dispatch(sceneId: string, action: string, params: DispatchParams = {}) {
217
- return dispatchHandler.dispatch(sceneId, action, { ...params, [BEFORE_REMOVE_SOURCE_PROP]: 'external' });
218
- }
219
-
220
- addInterceptor(interceptor: NavigationInterceptor): NavigationSubscription {
221
- dispatchHandler.addInterceptor(interceptor);
222
- return {
223
- remove: () => dispatchHandler.removeInterceptor(interceptor),
224
- };
149
+ CachedRootComponent = withNavigation(appKey)(WrappedComponent);
150
+ }
151
+ return CachedRootComponent;
152
+ });
225
153
  }
226
154
 
227
- setResult = <T extends ResultMap = ResultMap>(
228
- sceneId: string,
229
- resultCode: number,
230
- data: T | null = null,
231
- ): void => {
232
- resultHandler.setResult(sceneId, resultCode, data);
233
- };
234
-
235
- result<T = unknown>(sceneId: string, requestCode: number) {
236
- return resultHandler.waitResult<T>(sceneId, requestCode);
155
+ setDefaultOptions(options: DefaultOptions) {
156
+ NativeNavigation.setDefaultOptions(options);
237
157
  }
238
158
 
239
159
  setRoot(layout: Layout, options?: SetRootOptions) {
@@ -248,16 +168,13 @@ class NavigationImpl implements Navigation {
248
168
  return { remove };
249
169
  }
250
170
 
251
- currentTab(sceneId: string) {
252
- return NativeNavigation.currentTab(sceneId);
253
- }
254
-
255
- findSceneIdByModuleName(moduleName: RouteName) {
256
- return NativeNavigation.findSceneIdByModuleName(moduleName);
171
+ dispatch(sceneId: string, action: string, params: DispatchParams = {}) {
172
+ return dispatchHandler.dispatch(sceneId, action, params, { source: 'external' });
257
173
  }
258
174
 
259
- isStackRoot(sceneId: string) {
260
- return NativeNavigation.isStackRoot(sceneId);
175
+ addInterceptor(interceptor: NavigationInterceptor): NavigationSubscription {
176
+ const remove = dispatchHandler.addInterceptor(interceptor);
177
+ return { remove };
261
178
  }
262
179
 
263
180
  currentRoute(): Promise<Route | null> {
@@ -268,48 +185,10 @@ class NavigationImpl implements Navigation {
268
185
  return NativeNavigation.navigationSnapshot();
269
186
  }
270
187
 
271
- addBeforeRemoveListener(
272
- sceneId: string,
273
- listener: BeforeRemoveListener,
274
- options?: BeforeRemoveOptions,
275
- ): NavigationSubscription {
276
- const remove = leaveGuardHandler.addListener(sceneId, listener, options);
188
+ addGlobalLifecycleListener(listener: GlobalSceneLifecycleListener): NavigationSubscription {
189
+ const remove = lifecycleHandler.addGlobalLifecycleListener(listener);
277
190
  return { remove };
278
191
  }
279
-
280
- async isSceneCovered(sceneId: string): Promise<boolean> {
281
- try {
282
- const { layers } = await NativeNavigation.navigationSnapshot();
283
- return isSceneCoveredInLayers(layers, sceneId, 'visual');
284
- } catch {
285
- return false;
286
- }
287
- }
288
-
289
- async routeGraph(): Promise<RouteGraph[]> {
290
- return (await NativeNavigation.navigationSnapshot()).layers;
291
- }
292
-
293
- setDefaultOptions(options: DefaultOptions) {
294
- NativeNavigation.setDefaultOptions(options);
295
- }
296
-
297
- updateOptions(sceneId: string, options: NavigationOption) {
298
- NativeNavigation.updateOptions(sceneId, options);
299
- }
300
-
301
- updateTabBar(sceneId: string, options: TabBarStyle) {
302
- NativeNavigation.updateTabBar(sceneId, options);
303
- }
304
-
305
- setTabItem(sceneId: string, item: TabItemInfo | TabItemInfo[]) {
306
- const items = Array.isArray(item) ? item : [item];
307
- NativeNavigation.setTabItem(sceneId, items);
308
- }
309
-
310
- setMenuInteractive(sceneId: string, enabled: boolean) {
311
- return this.dispatch(sceneId, 'setMenuInteractive', { enabled });
312
- }
313
192
  }
314
193
 
315
194
  export default new NavigationImpl() as Navigation;
@@ -1,5 +1,4 @@
1
1
  import React, { useEffect } from 'react';
2
- import type { NavigationItem } from './Options';
3
2
  import type { HasTypedRoutes, InitialMetrics, RouteName, RoutePropsOf } from './Route';
4
3
  import { Navigator, NavigationContext } from './Navigator';
5
4
  import NativeNavigation from './NativeNavigation';
@@ -9,6 +8,7 @@ export type NavigationProps<Name extends RouteName = RouteName> = (HasTypedRoute
9
8
  : Record<string, any>) & {
10
9
  navigator: Navigator<Name>;
11
10
  initialMetrics?: InitialMetrics;
11
+ tabBarInset?: number;
12
12
  sceneId: string;
13
13
  };
14
14
 
@@ -51,18 +51,3 @@ export function withNavigation(moduleName: string) {
51
51
  return FC;
52
52
  };
53
53
  }
54
-
55
- export function withNavigationItem(item: NavigationItem) {
56
- return function (WrappedComponent: React.ComponentType<any>): React.ComponentType<any> {
57
- const navigationItem = (WrappedComponent as any).navigationItem;
58
- if (navigationItem) {
59
- (WrappedComponent as any).navigationItem = {
60
- ...navigationItem,
61
- ...item,
62
- };
63
- } else {
64
- (WrappedComponent as any).navigationItem = item;
65
- }
66
- return WrappedComponent;
67
- };
68
- }
package/src/Navigator.ts CHANGED
@@ -3,13 +3,20 @@ import { createContext } from 'react';
3
3
  import store from './store';
4
4
  import NativeNavigation from './NativeNavigation';
5
5
  import { dispatchHandler } from './handler/DispatchCommandHandler';
6
- import { lifecycleHandler } from './handler/LifecycleEventHandler';
7
- import { RESULT_BLOCK, resultHandler } from './handler/ResultEventHandler';
6
+ import { leaveGuardHandler } from './handler/LeaveGuardHandler';
7
+ import {
8
+ lifecycleHandler,
9
+ type SceneLifecycleListener,
10
+ } from './handler/LifecycleEventHandler';
11
+ import { resultHandler } from './handler/ResultEventHandler';
12
+ import { isSceneCoveredInLayers } from './routeGraph';
13
+ import type { NavigationSubscription } from './Navigation';
8
14
  import type { NavigationOption, TabBarStyle, TabItemInfo } from './Options';
9
15
  import type {
16
+ BeforeRemoveListener,
17
+ BeforeRemoveOptions,
10
18
  CloseSelfOptions,
11
19
  DispatchResult,
12
- Layout,
13
20
  NavigationResult,
14
21
  RouteName,
15
22
  RouteResultOf,
@@ -39,7 +46,11 @@ export class Navigator<CurrentRoute extends RouteName = RouteName> {
39
46
  ): Promise<Navigator<Name> | undefined> {
40
47
  const sceneId = await NativeNavigation.findSceneIdByModuleName(moduleName);
41
48
  if (sceneId) {
42
- return Navigator.of<Name>(sceneId);
49
+ const navigator = Navigator.of<Name>(sceneId);
50
+ if (!navigator.moduleName) {
51
+ navigator.moduleName = moduleName;
52
+ }
53
+ return navigator;
43
54
  }
44
55
  }
45
56
 
@@ -48,7 +59,11 @@ export class Navigator<CurrentRoute extends RouteName = RouteName> {
48
59
  if (!route) {
49
60
  return undefined;
50
61
  }
51
- return Navigator.of(route.sceneId);
62
+ const navigator = Navigator.of(route.sceneId);
63
+ if (!navigator.moduleName && route.moduleName) {
64
+ navigator.moduleName = route.moduleName;
65
+ }
66
+ return navigator;
52
67
  }
53
68
 
54
69
  constructor(public sceneId: string, public moduleName?: string) {}
@@ -79,7 +94,7 @@ export class Navigator<CurrentRoute extends RouteName = RouteName> {
79
94
  if (warnOnFailure) {
80
95
  console.warn(warnOnFailure(result.code));
81
96
  }
82
- return { status: 'blocked', code: RESULT_BLOCK, reason: result.code };
97
+ return { status: 'blocked', reason: result.code };
83
98
  }
84
99
  return promise;
85
100
  };
@@ -98,15 +113,6 @@ export class Navigator<CurrentRoute extends RouteName = RouteName> {
98
113
  });
99
114
  };
100
115
 
101
- pushLayout = async <T = unknown>(
102
- layout: Layout,
103
- ): Promise<NavigationResult<T>> => {
104
- return this.dispatchForResult<T>('pushLayout', {
105
- from: this.moduleName,
106
- layout,
107
- });
108
- };
109
-
110
116
  pop = (): Promise<DispatchResult> =>
111
117
  dispatchHandler.dispatch(this.sceneId, 'pop', { from: this.moduleName });
112
118
 
@@ -156,19 +162,6 @@ export class Navigator<CurrentRoute extends RouteName = RouteName> {
156
162
  );
157
163
  };
158
164
 
159
- presentLayout = async <T = unknown>(
160
- layout: Layout,
161
- ): Promise<NavigationResult<T>> => {
162
- return this.dispatchForResult<T>(
163
- 'presentLayout',
164
- {
165
- layout,
166
- from: this.moduleName,
167
- },
168
- code => `presentLayout from:${this.moduleName} failed (${code}).`,
169
- );
170
- };
171
-
172
165
  dismiss = (): Promise<DispatchResult> =>
173
166
  dispatchHandler.dispatch(this.sceneId, 'dismiss', { from: this.moduleName });
174
167
 
@@ -197,39 +190,20 @@ export class Navigator<CurrentRoute extends RouteName = RouteName> {
197
190
  );
198
191
  };
199
192
 
200
- showModalLayout = async <T = unknown>(
201
- layout: Layout,
202
- ): Promise<NavigationResult<T>> => {
203
- return this.dispatchForResult<T>(
204
- 'showModalLayout',
205
- {
206
- from: this.moduleName,
207
- layout,
208
- },
209
- code => `showModalLayout from:${this.moduleName} failed (${code}).`,
210
- );
211
- };
212
-
213
- hideModal = (): Promise<DispatchResult> =>
214
- dispatchHandler.dispatch(this.sceneId, 'hideModal', { from: this.moduleName });
215
-
216
193
  setResult = (
217
194
  resultCode: number,
218
195
  data: SetResultData<CurrentRoute> | null = null,
219
196
  ): void => resultHandler.setResult(this.sceneId, resultCode, data);
220
197
 
221
- switchTab = async (
198
+ switchTab = (
222
199
  target: number | string,
223
200
  popToRoot: boolean = false,
224
- ): Promise<DispatchResult> => {
225
- const from = await NativeNavigation.currentTab(this.sceneId);
226
- return dispatchHandler.dispatch(this.sceneId, 'switchTab', {
227
- from,
201
+ ): Promise<DispatchResult> =>
202
+ dispatchHandler.dispatch(this.sceneId, 'switchTab', {
203
+ from: this.moduleName,
228
204
  to: target,
229
- ...(typeof target === 'string' && { tabKey: target }),
230
205
  popToRoot,
231
206
  });
232
- };
233
207
 
234
208
  toggleMenu = (): Promise<DispatchResult> =>
235
209
  dispatchHandler.dispatch(this.sceneId, 'toggleMenu', {
@@ -259,5 +233,29 @@ export class Navigator<CurrentRoute extends RouteName = RouteName> {
259
233
  NativeNavigation.setTabItem(this.sceneId, items);
260
234
  };
261
235
 
262
- isStackRoot = () => NativeNavigation.isStackRoot(this.sceneId);
236
+ isStackRoot = (): Promise<boolean> => NativeNavigation.isStackRoot(this.sceneId);
237
+
238
+ currentTab = (): Promise<number> => NativeNavigation.currentTab(this.sceneId);
239
+
240
+ isCovered = async (): Promise<boolean> => {
241
+ try {
242
+ const { layers } = await NativeNavigation.navigationSnapshot();
243
+ return isSceneCoveredInLayers(layers, this.sceneId);
244
+ } catch {
245
+ return false;
246
+ }
247
+ };
248
+
249
+ addLifecycleListener = (listener: SceneLifecycleListener): NavigationSubscription => {
250
+ const remove = lifecycleHandler.addLifecycleListener(this.sceneId, listener);
251
+ return { remove };
252
+ };
253
+
254
+ addBeforeRemoveListener = (
255
+ listener: BeforeRemoveListener,
256
+ options?: BeforeRemoveOptions,
257
+ ): NavigationSubscription => {
258
+ const remove = leaveGuardHandler.addListener(this.sceneId, listener, options);
259
+ return { remove };
260
+ };
263
261
  }
package/src/Options.ts CHANGED
@@ -5,17 +5,13 @@ export type ImageSource = {
5
5
  height?: number;
6
6
  width?: number;
7
7
  };
8
- export const BarStyleLightContent = 'light-content';
9
- export type BarStyleLightContent = typeof BarStyleLightContent;
10
- export const BarStyleDarkContent = 'dark-content';
11
- export type BarStyleDarkContent = typeof BarStyleDarkContent;
12
- export type BarStyle = BarStyleLightContent | BarStyleDarkContent;
8
+ export type BarStyle = 'light-content' | 'dark-content';
13
9
  export type ScreenOrientation = 'portrait' | 'landscape' | 'auto';
14
10
 
15
11
  export interface NavigationOption {
16
12
  screenBackgroundColor?: Color; // 页面背景,默认是白色
17
13
  statusBarHidden?: boolean; // 是否隐藏状态栏
18
- statusBarStyle?: BarStyle; // 状态栏样式,可选项有 `BarStyleLightContent` 和 `BarStyleDarkContent`
14
+ statusBarStyle?: BarStyle; // 状态栏样式,可选项有 'light-content' 和 'dark-content'
19
15
  navigationBarColorAndroid?: Color; // Android 底部虚拟按钮背景颜色
20
16
  navigationBarHiddenAndroid?: boolean; // 是否隐藏 Android 底部的虚拟导航栏
21
17
  displayCutoutWhenLandscapeAndroid?: boolean; // 横屏时,是否将界面延伸至刘海区域,默认 true
@@ -45,13 +41,12 @@ export interface ShadowImage {
45
41
  export interface DefaultOptions {
46
42
  screenBackgroundColor?: Color; // 页面背景,默认是白色
47
43
  injectInitialMetrics?: boolean; // 同向全屏场景的首帧安全区,默认关闭
48
- prewarmPush?: boolean; // 是否对有动画的同向全屏主栈 push 启用离屏 Fabric 首帧预热(默认 false)
49
- statusBarStyle?: BarStyle; // 状态栏样式,可选项有 `BarStyleLightContent` 和 `BarStyleDarkContent`
44
+ statusBarStyle?: BarStyle; // 状态栏样式,可选项有 'light-content' 和 'dark-content'
50
45
  navigationBarColorAndroid?: Color; // 底部虚拟键背景颜色,仅对 Android 8.0 以上版本生效
51
46
  displayCutoutWhenLandscapeAndroid?: boolean; // 横屏时,是否将界面延伸至刘海区域,默认 true
52
47
  orientation?: ScreenOrientation; // 默认全局方向策略,默认为 portrait
53
48
 
54
- tabBarBackgroundColor?: Color; // 底部 TabBar 背景颜色,请勿使用带透明度的颜色。
49
+ tabBarBackgroundColor?: Color; // 底部 TabBar 背景颜色(请勿使用带透明度的颜色;iOS 26+ 系统 Liquid Glass TabBar 会忽略该项)
55
50
  tabBarShadowImage?: ShadowImage; // 底部 TabBar 阴影图片。对于 iOS, 只有同时设置了 tabBarBackgroundColor 才会生效
56
51
  tabBarItemSelectedColor?: Color; // 底部 TabBarItem icon 选中颜色
57
52
  tabBarItemNormalColor?: Color; // 底部 TabBarItem icon 未选中颜色,默认为 #666666
package/src/Route.ts CHANGED
@@ -41,7 +41,6 @@ export type LeaveAction =
41
41
  | 'popTo'
42
42
  | 'popToRoot'
43
43
  | 'dismiss'
44
- | 'hideModal'
45
44
  | 'close'
46
45
  | 'redirectTo';
47
46
 
@@ -58,6 +57,12 @@ export interface BeforeRemoveOptions {
58
57
  actions?: LeaveAction[];
59
58
  }
60
59
 
60
+ /**
61
+ * Before-remove guard listener.
62
+ * Call `await event.proceed()` before returning to allow leaving.
63
+ * Async confirmations must be awaited inside the listener; calling `event.proceed()` after
64
+ * the listener has settled without proceeding is ignored and resolves to `intercepted`.
65
+ */
61
66
  export type BeforeRemoveListener = (event: BeforeRemoveEvent) => void | Promise<void>;
62
67
 
63
68
  export interface InitialMetrics {
@@ -82,9 +87,9 @@ export interface SetRootOptions {
82
87
  export type CancelReason = 'dismissed' | 'unmounted' | 'root_reset';
83
88
 
84
89
  export type NavigationResult<T = unknown> =
85
- | { status: 'ok'; code: number; data: T }
86
- | { status: 'cancel'; code: number; reason: CancelReason }
87
- | { status: 'blocked'; code: number; reason: DispatchResultCode };
90
+ | { status: 'ok'; code: number; data: T | null }
91
+ | { status: 'cancel'; code: 0; reason: CancelReason }
92
+ | { status: 'blocked'; reason: DispatchResultCode };
88
93
 
89
94
  export type ScreenRoute<
90
95
  Props extends Record<string, any> = Record<never, never>,
@@ -149,13 +154,21 @@ export type ScreenPropsArgs<Name extends string> = HasTypedRoutes extends true
149
154
 
150
155
  export type Screen<Name extends RouteName = RouteName> = HasTypedRoutes extends true
151
156
  ? Name extends RouteName
152
- ? {
153
- screen: {
154
- moduleName: Name;
155
- props?: RoutePropsOf<Name>;
156
- options?: NavigationItem;
157
- };
158
- }
157
+ ? IsPropsRequired<RoutePropsOf<Name>> extends true
158
+ ? {
159
+ screen: {
160
+ moduleName: Name;
161
+ props: RoutePropsOf<Name>;
162
+ options?: NavigationItem;
163
+ };
164
+ }
165
+ : {
166
+ screen: {
167
+ moduleName: Name;
168
+ props?: RoutePropsOf<Name>;
169
+ options?: NavigationItem;
170
+ };
171
+ }
159
172
  : never
160
173
  : {
161
174
  screen: {
@@ -165,8 +178,6 @@ export type Screen<Name extends RouteName = RouteName> = HasTypedRoutes extends
165
178
  };
166
179
  };
167
180
 
168
- export type TypedScreen = Screen<RouteName>;
169
-
170
181
  export interface Stack {
171
182
  stack: {
172
183
  children: Array<Layout>;
@@ -202,7 +213,7 @@ export type CustomLayout = HasCustomLayouts extends true
202
213
  }[Extract<keyof CustomLayoutMap, string>]
203
214
  : never;
204
215
 
205
- export type BuiltInLayout = TypedScreen | Stack | Tabs | Drawer;
216
+ export type BuiltInLayout = Screen | Stack | Tabs | Drawer;
206
217
  export type Layout = BuiltInLayout | CustomLayout;
207
218
 
208
219
  export type RouteMode = 'modal' | 'present' | 'push';
@@ -213,7 +224,6 @@ export interface Route {
213
224
  moduleName: string;
214
225
  mode: LayoutMode;
215
226
  presentingId: string | null;
216
- requestCode: number;
217
227
  }
218
228
 
219
229
  export interface NavigationSnapshot {
@@ -234,12 +244,10 @@ export interface RouteConfig {
234
244
  dependency?: RouteName;
235
245
  mode?: RouteMode;
236
246
  options?: NavigationItem;
237
- lazy?: boolean;
238
247
  }
239
248
 
240
249
  export interface RouteData {
241
250
  moduleName: string;
242
- regexp?: RegExp;
243
251
  path?: string;
244
252
  dependency?: string;
245
253
  mode: RouteMode;
@@ -250,7 +258,12 @@ export interface RouteInfo {
250
258
  mode: RouteMode;
251
259
  dependencies: string[];
252
260
  props: object;
253
- options: object;
261
+ options: NavigationItem;
262
+ }
263
+
264
+ export interface RouteProcessContext {
265
+ rootGeneration: number;
266
+ isSuperseded: () => boolean;
254
267
  }
255
268
 
256
269
  export type RouteHandleResult = [boolean, RouteGraph | null, DispatchResult?];
@@ -259,9 +272,14 @@ export interface RouteHandler {
259
272
  /**
260
273
  * @param graph - current RouteGraph to process
261
274
  * @param target - route may add to the graph
275
+ * @param context - active navigation session context
262
276
  * @returns [boolean, RouteGraph | null, DispatchResult?] - if the route is handled, return true and childGraph for next Handler to process, [false, graph] otherwise
263
277
  */
264
- process: (graph: RouteGraph, target: RouteInfo) => Promise<RouteHandleResult>;
278
+ process: (
279
+ graph: RouteGraph,
280
+ target: RouteInfo,
281
+ context?: RouteProcessContext,
282
+ ) => Promise<RouteHandleResult>;
265
283
  }
266
284
 
267
285
  export type RouteInterceptor = (path: string) => boolean | Promise<boolean>;