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
@@ -1,15 +1,15 @@
1
1
  import type React from 'react';
2
2
  import { ComponentProvider } from 'react-native';
3
- import type { DefaultOptions, NavigationOption, TabBarStyle, TabItemInfo } from './Options';
4
- import type { BeforeRemoveListener, BeforeRemoveOptions, DispatchResult, Layout, NavigationResult, NavigationSnapshot, ResultMap, Route, RouteConfig, RouteGraph, RouteName, SceneLifecycleState, SetRootOptions } from './Route';
3
+ import type { DefaultOptions } from './Options';
4
+ import type { DispatchResult, Layout, NavigationSnapshot, Route, RouteConfig, RouteName, SetRootOptions } from './Route';
5
5
  import { RootLayoutListener } from './handler/LayoutCommandHandler';
6
- import { RESULT_BLOCK, RESULT_CANCEL, RESULT_OK } from './handler/ResultEventHandler';
7
- import { GlobalSceneLifecycleListener, SceneLifecycleListener } from './handler/LifecycleEventHandler';
6
+ import { RESULT_CANCEL, RESULT_OK } from './handler/ResultEventHandler';
7
+ import { GlobalSceneLifecycleListener } from './handler/LifecycleEventHandler';
8
8
  import type { DispatchParams, NavigationInterceptor } from './handler/DispatchCommandHandler';
9
9
  export type { DispatchParams, InterceptParams, NavigationInterceptor, } from './handler/DispatchCommandHandler';
10
10
  export type { GlobalSceneLifecycleListener, SceneLifecycleListener, } from './handler/LifecycleEventHandler';
11
11
  export type { RootLayoutListener } from './handler/LayoutCommandHandler';
12
- export { RESULT_CANCEL, RESULT_OK, RESULT_BLOCK };
12
+ export { RESULT_CANCEL, RESULT_OK };
13
13
  export type NavigationSubscription = {
14
14
  remove: () => void;
15
15
  };
@@ -18,29 +18,14 @@ export interface Navigation {
18
18
  startRegisterComponent(hoc?: HOC): void;
19
19
  endRegisterComponent(): void;
20
20
  registerComponent<Name extends RouteName = RouteName>(appKey: Name, getComponentFunc: ComponentProvider, routeConfig?: RouteConfig): void;
21
- addLifecycleListener(sceneId: string, listener: SceneLifecycleListener): NavigationSubscription;
22
- addGlobalLifecycleListener(listener: GlobalSceneLifecycleListener): NavigationSubscription;
23
- getSceneState(sceneId: string): SceneLifecycleState;
24
- dispatch(sceneId: string, action: string, params?: DispatchParams): Promise<DispatchResult>;
25
- addInterceptor(interceptor: NavigationInterceptor): NavigationSubscription;
26
- setResult<T extends ResultMap = ResultMap>(sceneId: string, resultCode: number, data?: T | null): void;
27
- result<T = unknown>(sceneId: string, requestCode: number): Promise<NavigationResult<T>>;
21
+ setDefaultOptions(options: DefaultOptions): void;
28
22
  setRoot(layout: Layout, options?: SetRootOptions): Promise<DispatchResult>;
29
23
  addRootLayoutUpdateListener(willSetRoot?: RootLayoutListener, didSetRoot?: RootLayoutListener): NavigationSubscription;
30
- currentTab(sceneId: string): Promise<number>;
31
- findSceneIdByModuleName(moduleName: RouteName): Promise<string | null>;
32
- isStackRoot(sceneId: string): Promise<boolean>;
24
+ dispatch(sceneId: string, action: string, params?: DispatchParams): Promise<DispatchResult>;
25
+ addInterceptor(interceptor: NavigationInterceptor): NavigationSubscription;
33
26
  currentRoute(): Promise<Route | null>;
34
27
  navigationSnapshot(): Promise<NavigationSnapshot>;
35
- addBeforeRemoveListener(sceneId: string, listener: BeforeRemoveListener, options?: BeforeRemoveOptions): NavigationSubscription;
36
- isSceneCovered(sceneId: string): Promise<boolean>;
37
- /** @deprecated Use (await navigationSnapshot()).layers instead. */
38
- routeGraph(): Promise<RouteGraph[]>;
39
- setDefaultOptions(options: DefaultOptions): void;
40
- updateOptions(sceneId: string, options: NavigationOption): void;
41
- updateTabBar(sceneId: string, options: TabBarStyle): void;
42
- setTabItem(sceneId: string, item: TabItemInfo | TabItemInfo[]): void;
43
- setMenuInteractive(sceneId: string, enabled: boolean): Promise<DispatchResult>;
28
+ addGlobalLifecycleListener(listener: GlobalSceneLifecycleListener): NavigationSubscription;
44
29
  }
45
30
  declare const _default: Navigation;
46
31
  export default _default;
@@ -1,26 +1,32 @@
1
1
  import { AppRegistry } from 'react-native';
2
2
  import { layoutHandler } from './handler/LayoutCommandHandler';
3
3
  import { dispatchHandler } from './handler/DispatchCommandHandler';
4
- import { RESULT_BLOCK, RESULT_CANCEL, RESULT_OK, resultHandler, } from './handler/ResultEventHandler';
4
+ import { RESULT_CANCEL, RESULT_OK, resultHandler } from './handler/ResultEventHandler';
5
5
  import { lifecycleHandler, } from './handler/LifecycleEventHandler';
6
- import { leaveGuardHandler, BEFORE_REMOVE_SOURCE_PROP } from './handler/LeaveGuardHandler';
6
+ import { leaveGuardHandler } from './handler/LeaveGuardHandler';
7
+ import { cleanupSceneExitHandler, clearExitHandlers, setExitHandlerPresenceListener, } from './handler/SceneExitHandler';
7
8
  import NativeNavigation from './NativeNavigation';
8
- import { isSceneCoveredInLayers } from './sceneCoverage';
9
9
  import store from './store';
10
10
  import { withNavigation } from './NavigationComponentWrap';
11
11
  import { bumpRouteConfigVersion, clearRouteConfigs, setRouteConfig, } from './routeConfigRegistry';
12
- export { RESULT_CANCEL, RESULT_OK, RESULT_BLOCK };
12
+ export { RESULT_CANCEL, RESULT_OK };
13
13
  class NavigationImpl {
14
14
  constructor() {
15
- leaveGuardHandler.setDispatcher((sceneId, action, params) => dispatchHandler.dispatch(sceneId, action, params));
16
- leaveGuardHandler.handleNativeBeforeRemoveRequests();
15
+ setExitHandlerPresenceListener((sceneId, active) => {
16
+ leaveGuardHandler.setExitHandlerActive(sceneId, active);
17
+ });
18
+ leaveGuardHandler.handleNativeBeforeRemoveRequests(sceneId => dispatchHandler.dispatch(sceneId, 'close', { from: store.getNavigator(sceneId)?.moduleName }, { source: 'back' }));
17
19
  layoutHandler.handleRootLayoutChange(() => {
18
20
  leaveGuardHandler.onRootReset();
21
+ lifecycleHandler.clearVisibleHolds();
19
22
  resultHandler.invalidateAll('root_reset');
23
+ clearExitHandlers();
24
+ store.clearNavigators();
20
25
  });
21
26
  lifecycleHandler.handleSceneLifecycle(sceneId => {
22
27
  leaveGuardHandler.onSceneDestroyed(sceneId);
23
28
  resultHandler.invalidateResultEventListener(sceneId, 'unmounted');
29
+ cleanupSceneExitHandler(sceneId);
24
30
  store.removeNavigator(sceneId);
25
31
  });
26
32
  resultHandler.handleComponentResult();
@@ -47,62 +53,21 @@ class NavigationImpl {
47
53
  setRouteConfig(appKey, routeConfig);
48
54
  }
49
55
  const hoc = this.hoc;
50
- if (routeConfig?.options !== undefined || routeConfig?.lazy === true) {
51
- NativeNavigation.registerReactComponent(appKey, routeConfig.options ?? {});
52
- let CachedRootComponent;
53
- AppRegistry.registerComponent(appKey, () => {
54
- if (!CachedRootComponent) {
55
- let WrappedComponent = getComponentFunc();
56
- if (__DEV__ && WrappedComponent?.navigationItem) {
57
- console.warn(`[hybrid-navigation] "${appKey}" enabled lazy registration via registerComponent(), so withNavigationItem() on the component is ignored.`);
58
- }
59
- if (hoc) {
60
- WrappedComponent = hoc(WrappedComponent);
61
- }
62
- CachedRootComponent = withNavigation(appKey)(WrappedComponent);
56
+ NativeNavigation.registerReactComponent(appKey, routeConfig?.options ?? {});
57
+ let CachedRootComponent;
58
+ AppRegistry.registerComponent(appKey, () => {
59
+ if (!CachedRootComponent) {
60
+ let WrappedComponent = getComponentFunc();
61
+ if (hoc) {
62
+ WrappedComponent = hoc(WrappedComponent);
63
63
  }
64
- return CachedRootComponent;
65
- });
66
- return;
67
- }
68
- let WrappedComponent = getComponentFunc();
69
- if (hoc) {
70
- WrappedComponent = hoc(WrappedComponent);
71
- }
72
- const options = WrappedComponent.navigationItem || {};
73
- NativeNavigation.registerReactComponent(appKey, options);
74
- const RootComponent = withNavigation(appKey)(WrappedComponent);
75
- AppRegistry.registerComponent(appKey, () => RootComponent);
76
- }
77
- addLifecycleListener(sceneId, listener) {
78
- lifecycleHandler.addLifecycleListener(sceneId, listener);
79
- return {
80
- remove: () => lifecycleHandler.removeLifecycleListener(sceneId, listener),
81
- };
82
- }
83
- addGlobalLifecycleListener(listener) {
84
- lifecycleHandler.addGlobalLifecycleListener(listener);
85
- return {
86
- remove: () => lifecycleHandler.removeGlobalLifecycleListener(listener),
87
- };
88
- }
89
- getSceneState(sceneId) {
90
- return lifecycleHandler.getSceneState(sceneId);
91
- }
92
- dispatch(sceneId, action, params = {}) {
93
- return dispatchHandler.dispatch(sceneId, action, { ...params, [BEFORE_REMOVE_SOURCE_PROP]: 'external' });
94
- }
95
- addInterceptor(interceptor) {
96
- dispatchHandler.addInterceptor(interceptor);
97
- return {
98
- remove: () => dispatchHandler.removeInterceptor(interceptor),
99
- };
64
+ CachedRootComponent = withNavigation(appKey)(WrappedComponent);
65
+ }
66
+ return CachedRootComponent;
67
+ });
100
68
  }
101
- setResult = (sceneId, resultCode, data = null) => {
102
- resultHandler.setResult(sceneId, resultCode, data);
103
- };
104
- result(sceneId, requestCode) {
105
- return resultHandler.waitResult(sceneId, requestCode);
69
+ setDefaultOptions(options) {
70
+ NativeNavigation.setDefaultOptions(options);
106
71
  }
107
72
  setRoot(layout, options) {
108
73
  return layoutHandler.setRoot(layout, options);
@@ -111,14 +76,12 @@ class NavigationImpl {
111
76
  const remove = layoutHandler.addRootLayoutUpdateListener(willSetRoot, didSetRoot);
112
77
  return { remove };
113
78
  }
114
- currentTab(sceneId) {
115
- return NativeNavigation.currentTab(sceneId);
116
- }
117
- findSceneIdByModuleName(moduleName) {
118
- return NativeNavigation.findSceneIdByModuleName(moduleName);
79
+ dispatch(sceneId, action, params = {}) {
80
+ return dispatchHandler.dispatch(sceneId, action, params, { source: 'external' });
119
81
  }
120
- isStackRoot(sceneId) {
121
- return NativeNavigation.isStackRoot(sceneId);
82
+ addInterceptor(interceptor) {
83
+ const remove = dispatchHandler.addInterceptor(interceptor);
84
+ return { remove };
122
85
  }
123
86
  currentRoute() {
124
87
  return NativeNavigation.currentRoute();
@@ -126,37 +89,9 @@ class NavigationImpl {
126
89
  navigationSnapshot() {
127
90
  return NativeNavigation.navigationSnapshot();
128
91
  }
129
- addBeforeRemoveListener(sceneId, listener, options) {
130
- const remove = leaveGuardHandler.addListener(sceneId, listener, options);
92
+ addGlobalLifecycleListener(listener) {
93
+ const remove = lifecycleHandler.addGlobalLifecycleListener(listener);
131
94
  return { remove };
132
95
  }
133
- async isSceneCovered(sceneId) {
134
- try {
135
- const { layers } = await NativeNavigation.navigationSnapshot();
136
- return isSceneCoveredInLayers(layers, sceneId, 'visual');
137
- }
138
- catch {
139
- return false;
140
- }
141
- }
142
- async routeGraph() {
143
- return (await NativeNavigation.navigationSnapshot()).layers;
144
- }
145
- setDefaultOptions(options) {
146
- NativeNavigation.setDefaultOptions(options);
147
- }
148
- updateOptions(sceneId, options) {
149
- NativeNavigation.updateOptions(sceneId, options);
150
- }
151
- updateTabBar(sceneId, options) {
152
- NativeNavigation.updateTabBar(sceneId, options);
153
- }
154
- setTabItem(sceneId, item) {
155
- const items = Array.isArray(item) ? item : [item];
156
- NativeNavigation.setTabItem(sceneId, items);
157
- }
158
- setMenuInteractive(sceneId, enabled) {
159
- return this.dispatch(sceneId, 'setMenuInteractive', { enabled });
160
- }
161
96
  }
162
97
  export default new NavigationImpl();
@@ -1,15 +1,14 @@
1
1
  import React from 'react';
2
- import type { NavigationItem } from './Options';
3
2
  import type { HasTypedRoutes, InitialMetrics, RouteName, RoutePropsOf } from './Route';
4
3
  import { Navigator } from './Navigator';
5
4
  export type NavigationProps<Name extends RouteName = RouteName> = (HasTypedRoutes extends true ? RoutePropsOf<Name> : Record<string, any>) & {
6
5
  navigator: Navigator<Name>;
7
6
  initialMetrics?: InitialMetrics;
7
+ tabBarInset?: number;
8
8
  sceneId: string;
9
9
  };
10
10
  interface NativeProps {
11
11
  sceneId: string;
12
12
  }
13
13
  export declare function withNavigation(moduleName: string): (WrappedComponent: React.ComponentType<any>) => React.ForwardRefExoticComponent<NativeProps & React.RefAttributes<React.ComponentClass<any, any> | React.FunctionComponent<any>>>;
14
- export declare function withNavigationItem(item: NavigationItem): (WrappedComponent: React.ComponentType<any>) => React.ComponentType<any>;
15
14
  export {};
@@ -26,18 +26,3 @@ export function withNavigation(moduleName) {
26
26
  return FC;
27
27
  };
28
28
  }
29
- export function withNavigationItem(item) {
30
- return function (WrappedComponent) {
31
- const navigationItem = WrappedComponent.navigationItem;
32
- if (navigationItem) {
33
- WrappedComponent.navigationItem = {
34
- ...navigationItem,
35
- ...item,
36
- };
37
- }
38
- else {
39
- WrappedComponent.navigationItem = item;
40
- }
41
- return WrappedComponent;
42
- };
43
- }
@@ -1,5 +1,7 @@
1
+ import { type SceneLifecycleListener } from './handler/LifecycleEventHandler';
2
+ import type { NavigationSubscription } from './Navigation';
1
3
  import type { NavigationOption, TabBarStyle, TabItemInfo } from './Options';
2
- import type { CloseSelfOptions, DispatchResult, Layout, NavigationResult, RouteName, RouteResultOf, SceneLifecycleState, ScreenPropsArgs, SetResultData } from './Route';
4
+ import type { BeforeRemoveListener, BeforeRemoveOptions, CloseSelfOptions, DispatchResult, NavigationResult, RouteName, RouteResultOf, SceneLifecycleState, ScreenPropsArgs, SetResultData } from './Route';
3
5
  export declare const NavigationContext: import("react").Context<Navigator<any> | null>;
4
6
  export declare class Navigator<CurrentRoute extends RouteName = RouteName> {
5
7
  sceneId: string;
@@ -11,18 +13,14 @@ export declare class Navigator<CurrentRoute extends RouteName = RouteName> {
11
13
  get lifecycleState(): SceneLifecycleState;
12
14
  private dispatchForResult;
13
15
  push: <Name extends RouteName = RouteName, T = RouteResultOf<Name>>(moduleName: Name, ...args: ScreenPropsArgs<Name>) => Promise<NavigationResult<T>>;
14
- pushLayout: <T = unknown>(layout: Layout) => Promise<NavigationResult<T>>;
15
16
  pop: () => Promise<DispatchResult>;
16
17
  popTo: (moduleName: RouteName | (string & {}), inclusive?: boolean) => Promise<DispatchResult>;
17
18
  popToRoot: () => Promise<DispatchResult>;
18
19
  redirectTo: <Name extends RouteName = RouteName>(moduleName: Name, ...args: ScreenPropsArgs<Name>) => Promise<DispatchResult>;
19
20
  present: <Name extends RouteName = RouteName, T = RouteResultOf<Name>>(moduleName: Name, ...args: ScreenPropsArgs<Name>) => Promise<NavigationResult<T>>;
20
- presentLayout: <T = unknown>(layout: Layout) => Promise<NavigationResult<T>>;
21
21
  dismiss: () => Promise<DispatchResult>;
22
22
  closeSelf: (options?: CloseSelfOptions<SetResultData<CurrentRoute>>) => Promise<DispatchResult>;
23
23
  showModal: <Name extends RouteName = RouteName, T = RouteResultOf<Name>>(moduleName: Name, ...args: ScreenPropsArgs<Name>) => Promise<NavigationResult<T>>;
24
- showModalLayout: <T = unknown>(layout: Layout) => Promise<NavigationResult<T>>;
25
- hideModal: () => Promise<DispatchResult>;
26
24
  setResult: (resultCode: number, data?: SetResultData<CurrentRoute> | null) => void;
27
25
  switchTab: (target: number | string, popToRoot?: boolean) => Promise<DispatchResult>;
28
26
  toggleMenu: () => Promise<DispatchResult>;
@@ -33,4 +31,8 @@ export declare class Navigator<CurrentRoute extends RouteName = RouteName> {
33
31
  updateTabBar: (options: TabBarStyle) => void;
34
32
  setTabItem: (item: TabItemInfo | TabItemInfo[]) => void;
35
33
  isStackRoot: () => Promise<boolean>;
34
+ currentTab: () => Promise<number>;
35
+ isCovered: () => Promise<boolean>;
36
+ addLifecycleListener: (listener: SceneLifecycleListener) => NavigationSubscription;
37
+ addBeforeRemoveListener: (listener: BeforeRemoveListener, options?: BeforeRemoveOptions) => NavigationSubscription;
36
38
  }
package/dist/Navigator.js CHANGED
@@ -2,8 +2,10 @@ import { createContext } from 'react';
2
2
  import store from './store';
3
3
  import NativeNavigation from './NativeNavigation';
4
4
  import { dispatchHandler } from './handler/DispatchCommandHandler';
5
- import { lifecycleHandler } from './handler/LifecycleEventHandler';
6
- import { RESULT_BLOCK, resultHandler } from './handler/ResultEventHandler';
5
+ import { leaveGuardHandler } from './handler/LeaveGuardHandler';
6
+ import { lifecycleHandler, } from './handler/LifecycleEventHandler';
7
+ import { resultHandler } from './handler/ResultEventHandler';
8
+ import { isSceneCoveredInLayers } from './routeGraph';
7
9
  export const NavigationContext = createContext(null);
8
10
  let tagGenerator = 0;
9
11
  export class Navigator {
@@ -22,7 +24,11 @@ export class Navigator {
22
24
  static async find(moduleName) {
23
25
  const sceneId = await NativeNavigation.findSceneIdByModuleName(moduleName);
24
26
  if (sceneId) {
25
- return Navigator.of(sceneId);
27
+ const navigator = Navigator.of(sceneId);
28
+ if (!navigator.moduleName) {
29
+ navigator.moduleName = moduleName;
30
+ }
31
+ return navigator;
26
32
  }
27
33
  }
28
34
  static async current() {
@@ -30,7 +36,11 @@ export class Navigator {
30
36
  if (!route) {
31
37
  return undefined;
32
38
  }
33
- return Navigator.of(route.sceneId);
39
+ const navigator = Navigator.of(route.sceneId);
40
+ if (!navigator.moduleName && route.moduleName) {
41
+ navigator.moduleName = route.moduleName;
42
+ }
43
+ return navigator;
34
44
  }
35
45
  constructor(sceneId, moduleName) {
36
46
  this.sceneId = sceneId;
@@ -58,7 +68,7 @@ export class Navigator {
58
68
  if (warnOnFailure) {
59
69
  console.warn(warnOnFailure(result.code));
60
70
  }
61
- return { status: 'blocked', code: RESULT_BLOCK, reason: result.code };
71
+ return { status: 'blocked', reason: result.code };
62
72
  }
63
73
  return promise;
64
74
  };
@@ -72,12 +82,6 @@ export class Navigator {
72
82
  options,
73
83
  });
74
84
  };
75
- pushLayout = async (layout) => {
76
- return this.dispatchForResult('pushLayout', {
77
- from: this.moduleName,
78
- layout,
79
- });
80
- };
81
85
  pop = () => dispatchHandler.dispatch(this.sceneId, 'pop', { from: this.moduleName });
82
86
  popTo = (moduleName, inclusive = false) => dispatchHandler.dispatch(this.sceneId, 'popTo', {
83
87
  moduleName,
@@ -106,12 +110,6 @@ export class Navigator {
106
110
  options,
107
111
  }, code => `present from:${this.moduleName} to:${moduleName} failed (${code}).`);
108
112
  };
109
- presentLayout = async (layout) => {
110
- return this.dispatchForResult('presentLayout', {
111
- layout,
112
- from: this.moduleName,
113
- }, code => `presentLayout from:${this.moduleName} failed (${code}).`);
114
- };
115
113
  dismiss = () => dispatchHandler.dispatch(this.sceneId, 'dismiss', { from: this.moduleName });
116
114
  closeSelf = (options) => dispatchHandler.dispatch(this.sceneId, 'close', {
117
115
  from: this.moduleName,
@@ -128,23 +126,12 @@ export class Navigator {
128
126
  options,
129
127
  }, code => `showModal from:${this.moduleName} to:${moduleName} failed (${code}).`);
130
128
  };
131
- showModalLayout = async (layout) => {
132
- return this.dispatchForResult('showModalLayout', {
133
- from: this.moduleName,
134
- layout,
135
- }, code => `showModalLayout from:${this.moduleName} failed (${code}).`);
136
- };
137
- hideModal = () => dispatchHandler.dispatch(this.sceneId, 'hideModal', { from: this.moduleName });
138
129
  setResult = (resultCode, data = null) => resultHandler.setResult(this.sceneId, resultCode, data);
139
- switchTab = async (target, popToRoot = false) => {
140
- const from = await NativeNavigation.currentTab(this.sceneId);
141
- return dispatchHandler.dispatch(this.sceneId, 'switchTab', {
142
- from,
143
- to: target,
144
- ...(typeof target === 'string' && { tabKey: target }),
145
- popToRoot,
146
- });
147
- };
130
+ switchTab = (target, popToRoot = false) => dispatchHandler.dispatch(this.sceneId, 'switchTab', {
131
+ from: this.moduleName,
132
+ to: target,
133
+ popToRoot,
134
+ });
148
135
  toggleMenu = () => dispatchHandler.dispatch(this.sceneId, 'toggleMenu', {
149
136
  from: this.moduleName,
150
137
  });
@@ -161,4 +148,22 @@ export class Navigator {
161
148
  NativeNavigation.setTabItem(this.sceneId, items);
162
149
  };
163
150
  isStackRoot = () => NativeNavigation.isStackRoot(this.sceneId);
151
+ currentTab = () => NativeNavigation.currentTab(this.sceneId);
152
+ isCovered = async () => {
153
+ try {
154
+ const { layers } = await NativeNavigation.navigationSnapshot();
155
+ return isSceneCoveredInLayers(layers, this.sceneId);
156
+ }
157
+ catch {
158
+ return false;
159
+ }
160
+ };
161
+ addLifecycleListener = (listener) => {
162
+ const remove = lifecycleHandler.addLifecycleListener(this.sceneId, listener);
163
+ return { remove };
164
+ };
165
+ addBeforeRemoveListener = (listener, options) => {
166
+ const remove = leaveGuardHandler.addListener(this.sceneId, listener, options);
167
+ return { remove };
168
+ };
164
169
  }
package/dist/Options.d.ts CHANGED
@@ -5,11 +5,7 @@ export type ImageSource = {
5
5
  height?: number;
6
6
  width?: number;
7
7
  };
8
- export declare const BarStyleLightContent = "light-content";
9
- export type BarStyleLightContent = typeof BarStyleLightContent;
10
- export declare 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
  export interface NavigationOption {
15
11
  screenBackgroundColor?: Color;
@@ -39,7 +35,6 @@ export interface ShadowImage {
39
35
  export interface DefaultOptions {
40
36
  screenBackgroundColor?: Color;
41
37
  injectInitialMetrics?: boolean;
42
- prewarmPush?: boolean;
43
38
  statusBarStyle?: BarStyle;
44
39
  navigationBarColorAndroid?: Color;
45
40
  displayCutoutWhenLandscapeAndroid?: boolean;
package/dist/Options.js CHANGED
@@ -1,2 +1 @@
1
- export const BarStyleLightContent = 'light-content';
2
- export const BarStyleDarkContent = 'dark-content';
1
+ export {};
package/dist/Route.d.ts CHANGED
@@ -22,7 +22,7 @@ export interface CloseSelfOptions<T extends ResultMap = ResultMap> {
22
22
  data?: T | null;
23
23
  };
24
24
  }
25
- export type LeaveAction = 'back' | 'pop' | 'popTo' | 'popToRoot' | 'dismiss' | 'hideModal' | 'close' | 'redirectTo';
25
+ export type LeaveAction = 'back' | 'pop' | 'popTo' | 'popToRoot' | 'dismiss' | 'close' | 'redirectTo';
26
26
  export type BeforeRemoveSource = 'back' | 'self' | 'external';
27
27
  export interface BeforeRemoveEvent {
28
28
  sceneId: string;
@@ -33,6 +33,12 @@ export interface BeforeRemoveEvent {
33
33
  export interface BeforeRemoveOptions {
34
34
  actions?: LeaveAction[];
35
35
  }
36
+ /**
37
+ * Before-remove guard listener.
38
+ * Call `await event.proceed()` before returning to allow leaving.
39
+ * Async confirmations must be awaited inside the listener; calling `event.proceed()` after
40
+ * the listener has settled without proceeding is ignored and resolves to `intercepted`.
41
+ */
36
42
  export type BeforeRemoveListener = (event: BeforeRemoveEvent) => void | Promise<void>;
37
43
  export interface InitialMetrics {
38
44
  insets: {
@@ -55,14 +61,13 @@ export type CancelReason = 'dismissed' | 'unmounted' | 'root_reset';
55
61
  export type NavigationResult<T = unknown> = {
56
62
  status: 'ok';
57
63
  code: number;
58
- data: T;
64
+ data: T | null;
59
65
  } | {
60
66
  status: 'cancel';
61
- code: number;
67
+ code: 0;
62
68
  reason: CancelReason;
63
69
  } | {
64
70
  status: 'blocked';
65
- code: number;
66
71
  reason: DispatchResultCode;
67
72
  };
68
73
  export type ScreenRoute<Props extends Record<string, any> = Record<never, never>, Result = unknown> = {
@@ -92,7 +97,13 @@ type RequiredKeysOf<T> = {
92
97
  }[keyof T];
93
98
  export type IsPropsRequired<P> = [RequiredKeysOf<P>] extends [never] ? false : true;
94
99
  export type ScreenPropsArgs<Name extends string> = HasTypedRoutes extends true ? IsPropsRequired<RoutePropsOf<Name>> extends true ? [props: RoutePropsOf<Name>, options?: NavigationItem] : [props?: RoutePropsOf<Name>, options?: NavigationItem] : [props?: Record<string, any>, options?: NavigationItem];
95
- export type Screen<Name extends RouteName = RouteName> = HasTypedRoutes extends true ? Name extends RouteName ? {
100
+ export type Screen<Name extends RouteName = RouteName> = HasTypedRoutes extends true ? Name extends RouteName ? IsPropsRequired<RoutePropsOf<Name>> extends true ? {
101
+ screen: {
102
+ moduleName: Name;
103
+ props: RoutePropsOf<Name>;
104
+ options?: NavigationItem;
105
+ };
106
+ } : {
96
107
  screen: {
97
108
  moduleName: Name;
98
109
  props?: RoutePropsOf<Name>;
@@ -105,7 +116,6 @@ export type Screen<Name extends RouteName = RouteName> = HasTypedRoutes extends
105
116
  options?: NavigationItem;
106
117
  };
107
118
  };
108
- export type TypedScreen = Screen<RouteName>;
109
119
  export interface Stack {
110
120
  stack: {
111
121
  children: Array<Layout>;
@@ -134,7 +144,7 @@ export type HasCustomLayouts = keyof CustomLayoutMap extends never ? false : tru
134
144
  export type CustomLayout = HasCustomLayouts extends true ? {
135
145
  [K in Extract<keyof CustomLayoutMap, string>]: Record<K, CustomLayoutMap[K]>;
136
146
  }[Extract<keyof CustomLayoutMap, string>] : never;
137
- export type BuiltInLayout = TypedScreen | Stack | Tabs | Drawer;
147
+ export type BuiltInLayout = Screen | Stack | Tabs | Drawer;
138
148
  export type Layout = BuiltInLayout | CustomLayout;
139
149
  export type RouteMode = 'modal' | 'present' | 'push';
140
150
  export type LayoutMode = 'modal' | 'present' | 'normal';
@@ -143,7 +153,6 @@ export interface Route {
143
153
  moduleName: string;
144
154
  mode: LayoutMode;
145
155
  presentingId: string | null;
146
- requestCode: number;
147
156
  }
148
157
  export interface NavigationSnapshot {
149
158
  rootGeneration: number;
@@ -161,11 +170,9 @@ export interface RouteConfig {
161
170
  dependency?: RouteName;
162
171
  mode?: RouteMode;
163
172
  options?: NavigationItem;
164
- lazy?: boolean;
165
173
  }
166
174
  export interface RouteData {
167
175
  moduleName: string;
168
- regexp?: RegExp;
169
176
  path?: string;
170
177
  dependency?: string;
171
178
  mode: RouteMode;
@@ -175,16 +182,21 @@ export interface RouteInfo {
175
182
  mode: RouteMode;
176
183
  dependencies: string[];
177
184
  props: object;
178
- options: object;
185
+ options: NavigationItem;
186
+ }
187
+ export interface RouteProcessContext {
188
+ rootGeneration: number;
189
+ isSuperseded: () => boolean;
179
190
  }
180
191
  export type RouteHandleResult = [boolean, RouteGraph | null, DispatchResult?];
181
192
  export interface RouteHandler {
182
193
  /**
183
194
  * @param graph - current RouteGraph to process
184
195
  * @param target - route may add to the graph
196
+ * @param context - active navigation session context
185
197
  * @returns [boolean, RouteGraph | null, DispatchResult?] - if the route is handled, return true and childGraph for next Handler to process, [false, graph] otherwise
186
198
  */
187
- process: (graph: RouteGraph, target: RouteInfo) => Promise<RouteHandleResult>;
199
+ process: (graph: RouteGraph, target: RouteInfo, context?: RouteProcessContext) => Promise<RouteHandleResult>;
188
200
  }
189
201
  export type RouteInterceptor = (path: string) => boolean | Promise<boolean>;
190
202
  export {};
@@ -1,6 +1,7 @@
1
1
  import { DispatchResultWire } from '../NativeNavigation';
2
2
  import { NavigationItem } from '../Options';
3
- import type { DispatchResult, Layout } from '../Route';
3
+ import type { DispatchResult } from '../Route';
4
+ import { type DispatchGuardOptions } from './LeaveGuardHandler';
4
5
  export declare function normalizeDispatchResult(wire: DispatchResultWire | null | undefined): DispatchResult;
5
6
  export interface DispatchParams {
6
7
  animated?: boolean;
@@ -8,7 +9,6 @@ export interface DispatchParams {
8
9
  moduleName?: string;
9
10
  from?: string | number;
10
11
  to?: string | number;
11
- layout?: Layout;
12
12
  popToRoot?: boolean;
13
13
  requestCode?: number;
14
14
  props?: object;
@@ -24,10 +24,9 @@ export interface InterceptParams {
24
24
  export type NavigationInterceptor = (action: string, params: InterceptParams) => boolean | Promise<boolean>;
25
25
  export default class DispatchCommandHandler {
26
26
  private interceptors;
27
- dispatch(sceneId: string, action: string, params: DispatchParams): Promise<DispatchResult>;
27
+ dispatch(sceneId: string, action: string, params: DispatchParams, options?: DispatchGuardOptions): Promise<DispatchResult>;
28
28
  private dispatchApproved;
29
29
  private intercept;
30
- addInterceptor(interceptor: NavigationInterceptor): void;
31
- removeInterceptor(interceptor: NavigationInterceptor): void;
30
+ addInterceptor(interceptor: NavigationInterceptor): () => void;
32
31
  }
33
32
  export declare const dispatchHandler: DispatchCommandHandler;