hybrid-navigation 5.2.0 → 5.3.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.
- package/README.md +9 -20
- package/android/src/main/java/com/navigation/androidx/AwesomeFragment.java +5 -13
- package/android/src/main/java/com/navigation/androidx/DefaultTabBarProvider.java +2 -2
- package/android/src/main/java/com/navigation/androidx/TabBarFragment.java +0 -50
- package/android/src/main/java/com/navigation/androidx/TabBarItem.java +0 -4
- package/android/src/main/java/com/reactnative/hybridnavigation/GlobalStyle.java +0 -7
- package/android/src/main/java/com/reactnative/hybridnavigation/HybridFragment.java +7 -43
- package/android/src/main/java/com/reactnative/hybridnavigation/NativeNavigation.java +5 -39
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactFragment.java +62 -135
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactManager.java +0 -20
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarFragment.java +10 -21
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/ScreenNavigator.java +39 -87
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/TabNavigator.java +2 -16
- package/dist/NativeEvent.d.ts +1 -11
- package/dist/NativeNavigation.d.ts +7 -6
- package/dist/Navigation.d.ts +8 -22
- package/dist/Navigation.js +33 -175
- package/dist/NavigationComponentWrap.d.ts +3 -3
- package/dist/Navigator.d.ts +4 -5
- package/dist/Navigator.js +13 -37
- package/dist/Options.d.ts +2 -2
- package/dist/Route.d.ts +10 -35
- package/dist/handler/DispatchCommandHandler.d.ts +3 -18
- package/dist/handler/DispatchCommandHandler.js +17 -64
- package/dist/handler/LayoutCommandHandler.d.ts +2 -3
- package/dist/handler/LayoutCommandHandler.js +0 -3
- package/dist/handler/LeaveGuardHandler.d.ts +3 -3
- package/dist/handler/LeaveGuardHandler.js +57 -32
- package/dist/handler/LifecycleEventHandler.d.ts +2 -14
- package/dist/handler/LifecycleEventHandler.js +2 -79
- package/dist/handler/ResultEventHandler.d.ts +0 -1
- package/dist/handler/ResultEventHandler.js +0 -3
- package/dist/handler/SceneExitHandler.d.ts +3 -0
- package/dist/handler/SceneExitHandler.js +76 -0
- package/dist/hooks.d.ts +0 -3
- package/dist/hooks.js +21 -46
- package/dist/index.d.ts +1 -12
- package/dist/index.js +0 -3
- package/dist/router/index.d.ts +0 -1
- package/dist/router/index.js +43 -11
- package/dist/router/stack.d.ts +1 -1
- package/dist/sceneCoverage.d.ts +2 -0
- package/dist/sceneCoverage.js +25 -0
- package/dist/store.d.ts +0 -2
- package/dist/store.js +0 -4
- package/ios/HBDGlobalStyle.h +0 -1
- package/ios/HBDGlobalStyle.mm +0 -7
- package/ios/HybridNavigation.h +0 -1
- package/ios/Navigator/HBDScreenNavigator.mm +89 -237
- package/ios/Navigator/HBDStackNavigator.mm +1 -1
- package/ios/Navigator/HBDTabNavigator.mm +15 -30
- package/ios/React/HBDNativeNavigation.mm +4 -31
- package/ios/React/HBDReactBridgeManager.h +0 -5
- package/ios/React/HBDReactBridgeManager.mm +0 -17
- package/ios/ViewController/HBDReactViewController.h +1 -1
- package/ios/ViewController/HBDReactViewController.mm +34 -9
- package/ios/ViewController/HBDTabBarController.h +2 -11
- package/ios/ViewController/HBDTabBarController.mm +14 -170
- package/ios/ViewController/HBDViewController.h +0 -1
- package/ios/ViewController/HBDViewController.mm +9 -57
- package/ios/ViewController/UIViewController+HBD.h +2 -0
- package/ios/ViewController/UIViewController+HBD.mm +5 -0
- package/package.json +1 -3
- package/src/NativeEvent.ts +1 -12
- package/src/NativeNavigation.ts +8 -7
- package/src/Navigation.ts +50 -281
- package/src/NavigationComponentWrap.tsx +3 -11
- package/src/Navigator.ts +15 -46
- package/src/Options.ts +2 -3
- package/src/Route.ts +13 -56
- package/src/handler/DispatchCommandHandler.ts +29 -111
- package/src/handler/LayoutCommandHandler.ts +2 -6
- package/src/handler/LeaveGuardHandler.ts +65 -32
- package/src/handler/LifecycleEventHandler.ts +22 -122
- package/src/handler/ResultEventHandler.ts +0 -6
- package/src/handler/SceneExitHandler.ts +86 -0
- package/src/hooks.ts +18 -53
- package/src/index.ts +0 -14
- package/src/router/index.ts +45 -12
- package/src/router/stack.ts +1 -1
- package/src/sceneCoverage.ts +30 -0
- package/src/store.ts +0 -5
- package/dist/defineRoutes.d.ts +0 -19
- package/dist/defineRoutes.js +0 -6
- package/dist/handler/PresentationCoordinator.d.ts +0 -39
- package/dist/handler/PresentationCoordinator.js +0 -673
- package/dist/handler/TabEventHandler.d.ts +0 -8
- package/dist/handler/TabEventHandler.js +0 -25
- package/dist/reveal.d.ts +0 -46
- package/dist/reveal.js +0 -431
- package/dist/routeGraph.d.ts +0 -12
- package/dist/routeGraph.js +0 -68
- package/dist/testing.d.ts +0 -82
- package/dist/testing.js +0 -253
- package/ios/ViewController/HBDTabBarRenderer.h +0 -28
- package/src/defineRoutes.ts +0 -46
- package/src/handler/PresentationCoordinator.ts +0 -806
- package/src/handler/TabEventHandler.ts +0 -31
- package/src/reveal.ts +0 -565
- package/src/routeGraph.ts +0 -87
- package/src/testing.ts +0 -402
- package/testing.d.ts +0 -1
- package/testing.js +0 -3
package/src/Route.ts
CHANGED
|
@@ -1,33 +1,8 @@
|
|
|
1
1
|
import type { NavigationItem } from './Options';
|
|
2
|
-
import type { CustomLayoutMap, NavigationParamList
|
|
3
|
-
|
|
4
|
-
export type Visibility = 'visible' | 'invisible' | 'pending';
|
|
2
|
+
import type { CustomLayoutMap, NavigationParamList } from './index';
|
|
5
3
|
|
|
6
4
|
export type SceneLifecycleState = 'created' | 'visible' | 'invisible' | 'destroyed';
|
|
7
5
|
|
|
8
|
-
export interface SceneInfo {
|
|
9
|
-
sceneId: string;
|
|
10
|
-
moduleName?: string;
|
|
11
|
-
mode: LayoutMode;
|
|
12
|
-
presentingId: string | null;
|
|
13
|
-
state: SceneLifecycleState;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export interface TabPressEvent {
|
|
17
|
-
index: number;
|
|
18
|
-
tabKey?: string;
|
|
19
|
-
previousIndex: number;
|
|
20
|
-
reselected: boolean;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export type TabPressListener = (event: TabPressEvent) => void;
|
|
24
|
-
|
|
25
|
-
export interface NavigationSnapshot {
|
|
26
|
-
rootGeneration: number;
|
|
27
|
-
currentRoute: Route | null;
|
|
28
|
-
layers: RouteGraph[];
|
|
29
|
-
}
|
|
30
|
-
|
|
31
6
|
export type DispatchResultCode =
|
|
32
7
|
| 'ok'
|
|
33
8
|
| 'intercepted'
|
|
@@ -46,12 +21,6 @@ export interface DispatchResult {
|
|
|
46
21
|
sceneId?: string;
|
|
47
22
|
}
|
|
48
23
|
|
|
49
|
-
export type CloseTarget = 'self' | 'presented';
|
|
50
|
-
|
|
51
|
-
export type CoveredPolicy = 'fail' | 'defer';
|
|
52
|
-
|
|
53
|
-
export type SceneCoverageListener = (covered: boolean) => void;
|
|
54
|
-
|
|
55
24
|
export type SceneExitRestoreReason = DispatchResultCode | 'exit_error';
|
|
56
25
|
|
|
57
26
|
export interface SceneExitHandler {
|
|
@@ -62,12 +31,8 @@ export interface SceneExitHandler {
|
|
|
62
31
|
}
|
|
63
32
|
|
|
64
33
|
export interface CloseSelfOptions<T extends ResultMap = ResultMap> {
|
|
65
|
-
result?: {
|
|
66
|
-
code: number;
|
|
67
|
-
data?: T | null;
|
|
68
|
-
};
|
|
69
|
-
onCovered?: CoveredPolicy;
|
|
70
34
|
bypassBeforeRemove?: boolean;
|
|
35
|
+
result?: { code: number; data?: T | null };
|
|
71
36
|
}
|
|
72
37
|
|
|
73
38
|
export type LeaveAction =
|
|
@@ -131,18 +96,8 @@ export type ScreenRoute<
|
|
|
131
96
|
|
|
132
97
|
export type HasTypedRoutes = keyof NavigationParamList extends never ? false : true;
|
|
133
98
|
|
|
134
|
-
export type AllowUnregisteredRoutes = NavigationTypeConfig extends {
|
|
135
|
-
allowUnregisteredRoutes: true;
|
|
136
|
-
}
|
|
137
|
-
? true
|
|
138
|
-
: false;
|
|
139
|
-
|
|
140
|
-
export type RegisteredRouteName = Extract<keyof NavigationParamList, string>;
|
|
141
|
-
|
|
142
99
|
export type RouteName = HasTypedRoutes extends true
|
|
143
|
-
?
|
|
144
|
-
? RegisteredRouteName | (string & {})
|
|
145
|
-
: RegisteredRouteName
|
|
100
|
+
? Extract<keyof NavigationParamList, string>
|
|
146
101
|
: string;
|
|
147
102
|
|
|
148
103
|
type RawRouteEntry<Name extends string> = Name extends keyof NavigationParamList
|
|
@@ -187,11 +142,9 @@ type RequiredKeysOf<T> = {
|
|
|
187
142
|
export type IsPropsRequired<P> = [RequiredKeysOf<P>] extends [never] ? false : true;
|
|
188
143
|
|
|
189
144
|
export type ScreenPropsArgs<Name extends string> = HasTypedRoutes extends true
|
|
190
|
-
?
|
|
191
|
-
?
|
|
192
|
-
|
|
193
|
-
: [props?: RoutePropsOf<Name>, options?: NavigationItem]
|
|
194
|
-
: [props?: Record<string, any>, options?: NavigationItem]
|
|
145
|
+
? IsPropsRequired<RoutePropsOf<Name>> extends true
|
|
146
|
+
? [props: RoutePropsOf<Name>, options?: NavigationItem]
|
|
147
|
+
: [props?: RoutePropsOf<Name>, options?: NavigationItem]
|
|
195
148
|
: [props?: Record<string, any>, options?: NavigationItem];
|
|
196
149
|
|
|
197
150
|
export type Screen<Name extends RouteName = RouteName> = HasTypedRoutes extends true
|
|
@@ -226,7 +179,6 @@ export interface Tabs {
|
|
|
226
179
|
children: Array<Layout>;
|
|
227
180
|
options?: {
|
|
228
181
|
selectedIndex?: number;
|
|
229
|
-
renderer?: string;
|
|
230
182
|
};
|
|
231
183
|
};
|
|
232
184
|
}
|
|
@@ -251,7 +203,6 @@ export type CustomLayout = HasCustomLayouts extends true
|
|
|
251
203
|
: never;
|
|
252
204
|
|
|
253
205
|
export type BuiltInLayout = TypedScreen | Stack | Tabs | Drawer;
|
|
254
|
-
export type BuildInLayout = BuiltInLayout;
|
|
255
206
|
export type Layout = BuiltInLayout | CustomLayout;
|
|
256
207
|
|
|
257
208
|
export type RouteMode = 'modal' | 'present' | 'push';
|
|
@@ -265,6 +216,12 @@ export interface Route {
|
|
|
265
216
|
requestCode: number;
|
|
266
217
|
}
|
|
267
218
|
|
|
219
|
+
export interface NavigationSnapshot {
|
|
220
|
+
rootGeneration: number;
|
|
221
|
+
currentRoute: Route | null;
|
|
222
|
+
layers: RouteGraph[];
|
|
223
|
+
}
|
|
224
|
+
|
|
268
225
|
export interface RouteGraph {
|
|
269
226
|
layout: string;
|
|
270
227
|
sceneId: string;
|
|
@@ -274,7 +231,7 @@ export interface RouteGraph {
|
|
|
274
231
|
|
|
275
232
|
export interface RouteConfig {
|
|
276
233
|
path?: string;
|
|
277
|
-
dependency?:
|
|
234
|
+
dependency?: RouteName;
|
|
278
235
|
mode?: RouteMode;
|
|
279
236
|
options?: NavigationItem;
|
|
280
237
|
lazy?: boolean;
|
|
@@ -1,25 +1,8 @@
|
|
|
1
1
|
import NativeNavigation, { DispatchResultWire } from '../NativeNavigation';
|
|
2
2
|
import { NavigationItem } from '../Options';
|
|
3
|
-
import type {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
CoveredPolicy,
|
|
7
|
-
DispatchResult,
|
|
8
|
-
DispatchResultCode,
|
|
9
|
-
Layout,
|
|
10
|
-
} from '../Route';
|
|
11
|
-
import { resultHandler } from './ResultEventHandler';
|
|
12
|
-
|
|
13
|
-
const INTERCEPT_CHECKED_PROP = '__hbdInterceptChecked';
|
|
14
|
-
export const BEFORE_REMOVE_SOURCE_PROP = '__hbdBeforeRemoveSource';
|
|
15
|
-
const INTERNAL_DISPATCH_PROPS = [
|
|
16
|
-
INTERCEPT_CHECKED_PROP,
|
|
17
|
-
BEFORE_REMOVE_SOURCE_PROP,
|
|
18
|
-
'onCovered',
|
|
19
|
-
'bypassBeforeRemove',
|
|
20
|
-
'__hbdBypassBeforeRemove',
|
|
21
|
-
'__hbdApprovedBeforeRemoveScenes',
|
|
22
|
-
] as const;
|
|
3
|
+
import type { DispatchResult, DispatchResultCode, Layout } from '../Route';
|
|
4
|
+
import { leaveGuardHandler, BEFORE_REMOVE_SOURCE_PROP } from './LeaveGuardHandler';
|
|
5
|
+
import { closeWithExitHandler } from './SceneExitHandler';
|
|
23
6
|
|
|
24
7
|
const VALID_DISPATCH_CODES = new Set<DispatchResultCode>([
|
|
25
8
|
'ok',
|
|
@@ -44,14 +27,12 @@ export function normalizeDispatchResult(
|
|
|
44
27
|
: wire.ok
|
|
45
28
|
? 'ok'
|
|
46
29
|
: 'invalid_action';
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
return result;
|
|
30
|
+
return {
|
|
31
|
+
ok: Boolean(wire.ok),
|
|
32
|
+
code,
|
|
33
|
+
...(wire.message && { message: wire.message }),
|
|
34
|
+
...(wire.sceneId && { sceneId: wire.sceneId }),
|
|
35
|
+
};
|
|
55
36
|
}
|
|
56
37
|
|
|
57
38
|
export interface DispatchParams {
|
|
@@ -60,17 +41,9 @@ export interface DispatchParams {
|
|
|
60
41
|
moduleName?: string;
|
|
61
42
|
from?: string | number;
|
|
62
43
|
to?: string | number;
|
|
63
|
-
layout?:
|
|
44
|
+
layout?: Layout;
|
|
64
45
|
popToRoot?: boolean;
|
|
65
|
-
tabKey?: string;
|
|
66
46
|
requestCode?: number;
|
|
67
|
-
target?: CloseTarget;
|
|
68
|
-
onCovered?: CoveredPolicy;
|
|
69
|
-
result?: {
|
|
70
|
-
code: number;
|
|
71
|
-
data?: any;
|
|
72
|
-
};
|
|
73
|
-
bypassBeforeRemove?: boolean;
|
|
74
47
|
props?: object;
|
|
75
48
|
options?: NavigationItem;
|
|
76
49
|
[index: string]: any;
|
|
@@ -88,26 +61,23 @@ export type NavigationInterceptor = (
|
|
|
88
61
|
params: InterceptParams,
|
|
89
62
|
) => boolean | Promise<boolean>;
|
|
90
63
|
|
|
91
|
-
export type DispatchMiddleware = (
|
|
92
|
-
sceneId: string,
|
|
93
|
-
action: string,
|
|
94
|
-
params: DispatchParams,
|
|
95
|
-
next: (sceneId: string, action: string, params: DispatchParams) => Promise<DispatchResult>,
|
|
96
|
-
) => Promise<DispatchResult>;
|
|
97
|
-
|
|
98
64
|
export default class DispatchCommandHandler {
|
|
99
65
|
private interceptors: NavigationInterceptor[] = [];
|
|
100
|
-
private systemMiddlewares: DispatchMiddleware[] = [];
|
|
101
|
-
|
|
102
|
-
addMiddleware(middleware: DispatchMiddleware) {
|
|
103
|
-
this.systemMiddlewares.push(middleware);
|
|
104
|
-
}
|
|
105
66
|
|
|
106
|
-
|
|
107
|
-
|
|
67
|
+
async dispatch(
|
|
68
|
+
sceneId: string,
|
|
69
|
+
action: string,
|
|
70
|
+
params: DispatchParams,
|
|
71
|
+
): Promise<DispatchResult> {
|
|
72
|
+
return leaveGuardHandler.middleware(sceneId, action, params, this.dispatchApproved);
|
|
108
73
|
}
|
|
109
74
|
|
|
110
|
-
|
|
75
|
+
private dispatchApproved = async (
|
|
76
|
+
sceneId: string,
|
|
77
|
+
action: string,
|
|
78
|
+
params: DispatchParams,
|
|
79
|
+
): Promise<DispatchResult> => {
|
|
80
|
+
const { [BEFORE_REMOVE_SOURCE_PROP]: _source, ...nativeParams } = params;
|
|
111
81
|
const { from, to, props } = params;
|
|
112
82
|
const intercepted = await this.intercept(action, {
|
|
113
83
|
sceneId,
|
|
@@ -115,66 +85,18 @@ export default class DispatchCommandHandler {
|
|
|
115
85
|
to,
|
|
116
86
|
props,
|
|
117
87
|
});
|
|
88
|
+
|
|
118
89
|
if (intercepted) {
|
|
119
90
|
return { ok: false, code: 'intercepted' };
|
|
120
91
|
}
|
|
121
|
-
|
|
92
|
+
const dispatchNative = async () =>
|
|
93
|
+
normalizeDispatchResult(await NativeNavigation.dispatch(sceneId, action, nativeParams));
|
|
94
|
+
const closingOwnLayer = params.target === 'self' && (action === 'dismiss' || action === 'hideModal');
|
|
95
|
+
return action === 'close' || closingOwnLayer
|
|
96
|
+
? closeWithExitHandler(sceneId, dispatchNative)
|
|
97
|
+
: dispatchNative();
|
|
122
98
|
};
|
|
123
99
|
|
|
124
|
-
async dispatchRaw(
|
|
125
|
-
sceneId: string,
|
|
126
|
-
action: string,
|
|
127
|
-
params: DispatchParams,
|
|
128
|
-
): Promise<DispatchResult> {
|
|
129
|
-
if (!params[INTERCEPT_CHECKED_PROP]) {
|
|
130
|
-
const { from, to, props } = params;
|
|
131
|
-
const intercepted = await this.intercept(action, {
|
|
132
|
-
sceneId,
|
|
133
|
-
from,
|
|
134
|
-
to,
|
|
135
|
-
props,
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
if (intercepted) {
|
|
139
|
-
return { ok: false, code: 'intercepted' };
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
const nativeParams: DispatchParams = { ...params };
|
|
144
|
-
for (const key of INTERNAL_DISPATCH_PROPS) {
|
|
145
|
-
delete nativeParams[key];
|
|
146
|
-
}
|
|
147
|
-
if (nativeParams.result !== undefined) {
|
|
148
|
-
nativeParams.result = resultHandler.normalizePendingResult(nativeParams.result);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
const wire = await NativeNavigation.dispatch(sceneId, action, nativeParams);
|
|
152
|
-
return normalizeDispatchResult(wire);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
async dispatch(
|
|
156
|
-
sceneId: string,
|
|
157
|
-
action: string,
|
|
158
|
-
params: DispatchParams,
|
|
159
|
-
): Promise<DispatchResult> {
|
|
160
|
-
const chain = this.systemMiddlewares.slice();
|
|
161
|
-
const invoke = (
|
|
162
|
-
cursor: number,
|
|
163
|
-
currentSceneId: string,
|
|
164
|
-
currentAction: string,
|
|
165
|
-
currentParams: DispatchParams,
|
|
166
|
-
): Promise<DispatchResult> => {
|
|
167
|
-
if (cursor < chain.length) {
|
|
168
|
-
const middleware = chain[cursor];
|
|
169
|
-
return middleware(currentSceneId, currentAction, currentParams, (s, a, p) =>
|
|
170
|
-
invoke(cursor + 1, s, a, p),
|
|
171
|
-
);
|
|
172
|
-
}
|
|
173
|
-
return this.dispatchRaw(currentSceneId, currentAction, currentParams);
|
|
174
|
-
};
|
|
175
|
-
return invoke(0, sceneId, action, params);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
100
|
private async intercept(action: string, params: InterceptParams): Promise<boolean> {
|
|
179
101
|
for (const interceptor of this.interceptors.slice()) {
|
|
180
102
|
const result = interceptor(action, params);
|
|
@@ -193,10 +115,6 @@ export default class DispatchCommandHandler {
|
|
|
193
115
|
removeInterceptor(interceptor: NavigationInterceptor) {
|
|
194
116
|
this.interceptors = this.interceptors.filter(item => item !== interceptor);
|
|
195
117
|
}
|
|
196
|
-
|
|
197
|
-
clearInterceptors() {
|
|
198
|
-
this.interceptors = [];
|
|
199
|
-
}
|
|
200
118
|
}
|
|
201
119
|
|
|
202
120
|
export const dispatchHandler = new DispatchCommandHandler();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { DispatchResult, Layout, SetRootOptions } from '../Route';
|
|
2
2
|
import NativeEvent from '../NativeEvent';
|
|
3
3
|
import NativeNavigation from '../NativeNavigation';
|
|
4
4
|
import { normalizeDispatchResult } from './DispatchCommandHandler';
|
|
@@ -28,7 +28,7 @@ export default class LayoutCommandHandler {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
async setRoot(
|
|
31
|
-
layout:
|
|
31
|
+
layout: Layout,
|
|
32
32
|
options?: SetRootOptions,
|
|
33
33
|
): Promise<DispatchResult> {
|
|
34
34
|
const sticky = Boolean(options?.stickyAndroid);
|
|
@@ -46,10 +46,6 @@ export default class LayoutCommandHandler {
|
|
|
46
46
|
this.listeners = this.listeners.filter(item => item !== record);
|
|
47
47
|
};
|
|
48
48
|
}
|
|
49
|
-
|
|
50
|
-
clearListeners() {
|
|
51
|
-
this.listeners = [];
|
|
52
|
-
}
|
|
53
49
|
}
|
|
54
50
|
|
|
55
51
|
export const layoutHandler = new LayoutCommandHandler();
|
|
@@ -9,10 +9,38 @@ import type {
|
|
|
9
9
|
LeaveAction,
|
|
10
10
|
RouteGraph,
|
|
11
11
|
} from '../Route';
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
12
|
+
import { isScreenGraph, type ScreenGraph } from '../router/screen';
|
|
13
|
+
import type { DispatchParams } from './DispatchCommandHandler';
|
|
14
14
|
import { lifecycleHandler } from './LifecycleEventHandler';
|
|
15
15
|
|
|
16
|
+
function containsScene(graph: RouteGraph, sceneId: string): boolean {
|
|
17
|
+
if (graph.sceneId === sceneId) {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
return Boolean(graph.children?.some(child => containsScene(child, sceneId)));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function findSceneInGraph(
|
|
24
|
+
graph: RouteGraph,
|
|
25
|
+
predicate: (node: ScreenGraph) => boolean,
|
|
26
|
+
): ScreenGraph | null {
|
|
27
|
+
if (isScreenGraph(graph)) {
|
|
28
|
+
return predicate(graph) ? graph : null;
|
|
29
|
+
}
|
|
30
|
+
if (!graph.children) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
for (const child of graph.children) {
|
|
34
|
+
const found = findSceneInGraph(child, predicate);
|
|
35
|
+
if (found) {
|
|
36
|
+
return found;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export const BEFORE_REMOVE_SOURCE_PROP = '__hbdBeforeRemoveSource';
|
|
43
|
+
|
|
16
44
|
const GUARDED_ACTIONS = new Set<LeaveAction>([
|
|
17
45
|
'pop',
|
|
18
46
|
'popTo',
|
|
@@ -44,30 +72,14 @@ function collectScreenIds(graph: RouteGraph, out: string[]): void {
|
|
|
44
72
|
}
|
|
45
73
|
|
|
46
74
|
function findContainingStack(graph: RouteGraph, sceneId: string): RouteGraph | null {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
if (nested) {
|
|
51
|
-
return nested;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
if (graph.children.some(child => containsScene(child, sceneId))) {
|
|
55
|
-
return graph;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
if (!graph.children) {
|
|
59
|
-
return null;
|
|
60
|
-
}
|
|
61
|
-
for (const child of graph.children) {
|
|
62
|
-
const found = findContainingStack(child, sceneId);
|
|
63
|
-
if (found) {
|
|
64
|
-
return found;
|
|
65
|
-
}
|
|
75
|
+
for (const child of graph.children ?? []) {
|
|
76
|
+
if (!containsScene(child, sceneId)) continue;
|
|
77
|
+
return findContainingStack(child, sceneId) ?? (graph.layout === 'stack' ? graph : null);
|
|
66
78
|
}
|
|
67
79
|
return null;
|
|
68
80
|
}
|
|
69
81
|
|
|
70
|
-
|
|
82
|
+
function collectRemovedStackScenes(
|
|
71
83
|
layers: RouteGraph[],
|
|
72
84
|
sceneId: string,
|
|
73
85
|
action: 'popTo' | 'popToRoot',
|
|
@@ -137,15 +149,14 @@ interface BeforeRemoveEntry {
|
|
|
137
149
|
actions?: Set<LeaveAction>;
|
|
138
150
|
}
|
|
139
151
|
|
|
140
|
-
function matchesAction(entry: BeforeRemoveEntry, action: LeaveAction,
|
|
152
|
+
function matchesAction(entry: BeforeRemoveEntry, action: LeaveAction, mode?: string): boolean {
|
|
141
153
|
if (!entry.actions) {
|
|
142
154
|
return true;
|
|
143
155
|
}
|
|
144
156
|
if (entry.actions.has(action)) {
|
|
145
157
|
return true;
|
|
146
158
|
}
|
|
147
|
-
if (action === 'close'
|
|
148
|
-
const mode = lifecycleHandler.getSceneInfo(sceneId)?.mode;
|
|
159
|
+
if (action === 'close') {
|
|
149
160
|
if (mode === 'modal' && entry.actions.has('hideModal')) {
|
|
150
161
|
return true;
|
|
151
162
|
}
|
|
@@ -259,10 +270,14 @@ export default class LeaveGuardHandler {
|
|
|
259
270
|
if (!this.nativeEnabledScenes.has(sceneId)) {
|
|
260
271
|
NativeNavigation.setBeforeRemoveEnabled(sceneId, false);
|
|
261
272
|
}
|
|
262
|
-
void proceedClose()
|
|
273
|
+
void proceedClose().catch(error => {
|
|
274
|
+
console.warn('[hybrid-navigation] Native back dispatch failed.', error);
|
|
275
|
+
});
|
|
263
276
|
return;
|
|
264
277
|
}
|
|
265
|
-
runGuardedChain(sceneId, leaveAction, 'back', matching, proceedClose)
|
|
278
|
+
void runGuardedChain(sceneId, leaveAction, 'back', matching, proceedClose).catch(error => {
|
|
279
|
+
console.warn('[hybrid-navigation] Native back guard failed.', error);
|
|
280
|
+
});
|
|
266
281
|
});
|
|
267
282
|
}
|
|
268
283
|
|
|
@@ -329,10 +344,11 @@ export default class LeaveGuardHandler {
|
|
|
329
344
|
return next(sceneId, action, cleanParams);
|
|
330
345
|
}
|
|
331
346
|
|
|
332
|
-
if (!GUARDED_ACTIONS.has(action as LeaveAction) || this.listeners.size === 0) {
|
|
347
|
+
if (!GUARDED_ACTIONS.has(action as LeaveAction) || (this.listeners.size === 0 && !params[APPROVED_SCENES_PROP])) {
|
|
333
348
|
return next(sceneId, action, params);
|
|
334
349
|
}
|
|
335
350
|
|
|
351
|
+
const generation = this.rootGeneration;
|
|
336
352
|
const leaveAction = action as LeaveAction;
|
|
337
353
|
const approved: Set<string> =
|
|
338
354
|
params[APPROVED_SCENES_PROP] instanceof Set ? params[APPROVED_SCENES_PROP] : new Set();
|
|
@@ -340,7 +356,7 @@ export default class LeaveGuardHandler {
|
|
|
340
356
|
let candidateSceneIds: string[] = [sceneId];
|
|
341
357
|
if (leaveAction === 'popTo' || leaveAction === 'popToRoot') {
|
|
342
358
|
try {
|
|
343
|
-
const layers = await NativeNavigation.
|
|
359
|
+
const layers = (await NativeNavigation.navigationSnapshot()).layers;
|
|
344
360
|
if (Array.isArray(layers) && layers.length > 0) {
|
|
345
361
|
candidateSceneIds = collectRemovedStackScenes(
|
|
346
362
|
layers,
|
|
@@ -362,7 +378,7 @@ export default class LeaveGuardHandler {
|
|
|
362
378
|
params.target !== 'self'
|
|
363
379
|
) {
|
|
364
380
|
try {
|
|
365
|
-
const layers = await NativeNavigation.
|
|
381
|
+
const layers = (await NativeNavigation.navigationSnapshot()).layers;
|
|
366
382
|
const presentedAbove = collectPresentedAboveScenes(layers, sceneId);
|
|
367
383
|
if (presentedAbove.length > 0) {
|
|
368
384
|
candidateSceneIds = presentedAbove;
|
|
@@ -384,8 +400,23 @@ export default class LeaveGuardHandler {
|
|
|
384
400
|
if (!set || set.size === 0) {
|
|
385
401
|
continue;
|
|
386
402
|
}
|
|
403
|
+
let mode: string | undefined;
|
|
404
|
+
const needsMode = leaveAction === 'close' && Array.from(set).some(({ actions }) =>
|
|
405
|
+
actions && !actions.has('close') &&
|
|
406
|
+
(actions.has('pop') || actions.has('dismiss') || actions.has('hideModal')),
|
|
407
|
+
);
|
|
408
|
+
if (needsMode) {
|
|
409
|
+
const { layers } = await NativeNavigation.navigationSnapshot();
|
|
410
|
+
for (const layer of layers) {
|
|
411
|
+
const scene = findSceneInGraph(layer, node => node.sceneId === candidateId);
|
|
412
|
+
if (scene) {
|
|
413
|
+
mode = scene.mode;
|
|
414
|
+
break;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
}
|
|
387
418
|
const hits = Array.from(set).filter(entry =>
|
|
388
|
-
matchesAction(entry, leaveAction,
|
|
419
|
+
matchesAction(entry, leaveAction, mode),
|
|
389
420
|
);
|
|
390
421
|
if (hits.length > 0) {
|
|
391
422
|
guardedSceneId = candidateId;
|
|
@@ -394,6 +425,9 @@ export default class LeaveGuardHandler {
|
|
|
394
425
|
}
|
|
395
426
|
}
|
|
396
427
|
|
|
428
|
+
if (generation !== this.rootGeneration) {
|
|
429
|
+
return { ok: false, code: 'superseded' };
|
|
430
|
+
}
|
|
397
431
|
if (!guardedSceneId || matching.length === 0) {
|
|
398
432
|
const cleanParams: DispatchParams = { ...params };
|
|
399
433
|
delete cleanParams[APPROVED_SCENES_PROP];
|
|
@@ -401,7 +435,6 @@ export default class LeaveGuardHandler {
|
|
|
401
435
|
}
|
|
402
436
|
|
|
403
437
|
const isMultiScene = candidateSceneIds.length > 1;
|
|
404
|
-
const generation = this.rootGeneration;
|
|
405
438
|
const targetGuardedSceneId = guardedSceneId;
|
|
406
439
|
const explicitSource = params[BEFORE_REMOVE_SOURCE_PROP];
|
|
407
440
|
const source: BeforeRemoveSource = isBeforeRemoveSource(explicitSource)
|