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.
- package/HybridNavigation.podspec +1 -0
- package/android/proguard-rules.pro +5 -0
- package/android/src/main/java/com/navigation/androidx/AppUtils.java +8 -1
- package/android/src/main/java/com/navigation/androidx/AwesomeActivity.java +115 -36
- package/android/src/main/java/com/navigation/androidx/AwesomeFragment.java +153 -100
- package/android/src/main/java/com/navigation/androidx/DefaultTabBarProvider.java +1 -1
- package/android/src/main/java/com/navigation/androidx/DrawableUtils.java +5 -1
- package/android/src/main/java/com/navigation/androidx/DrawerFragment.java +95 -39
- package/android/src/main/java/com/navigation/androidx/FragmentHelper.java +195 -29
- package/android/src/main/java/com/navigation/androidx/HybridDrawerLayout.java +225 -27
- package/android/src/main/java/com/navigation/androidx/LifecycleDelegate.java +33 -9
- package/android/src/main/java/com/navigation/androidx/PresentationDelegate.java +5 -107
- package/android/src/main/java/com/navigation/androidx/StackDelegate.java +37 -10
- package/android/src/main/java/com/navigation/androidx/StackFragment.java +82 -19
- package/android/src/main/java/com/navigation/androidx/Style.java +8 -4
- package/android/src/main/java/com/navigation/androidx/SystemUI.java +17 -5
- package/android/src/main/java/com/navigation/androidx/TabBar.java +69 -29
- package/android/src/main/java/com/navigation/androidx/TabBarFragment.java +48 -11
- package/android/src/main/java/com/navigation/androidx/TabBarItem.java +1 -2
- package/android/src/main/java/com/navigation/androidx/TabView.java +20 -10
- package/android/src/main/java/com/reactnative/hybridnavigation/Constants.java +1 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/Garden.java +19 -15
- package/android/src/main/java/com/reactnative/hybridnavigation/GlobalStyle.java +10 -48
- package/android/src/main/java/com/reactnative/hybridnavigation/HBDRootView.java +22 -23
- package/android/src/main/java/com/reactnative/hybridnavigation/HybridFragment.java +54 -22
- package/android/src/main/java/com/reactnative/hybridnavigation/NativeEvent.java +4 -2
- package/android/src/main/java/com/reactnative/hybridnavigation/NativeNavigation.java +35 -64
- package/android/src/main/java/com/reactnative/hybridnavigation/NavigationCommandQueue.java +185 -121
- package/android/src/main/java/com/reactnative/hybridnavigation/Navigator.java +21 -5
- package/android/src/main/java/com/reactnative/hybridnavigation/NavigatorRegistry.java +27 -30
- package/android/src/main/java/com/reactnative/hybridnavigation/OrientationCoordinator.java +41 -4
- package/android/src/main/java/com/reactnative/hybridnavigation/Parameters.java +55 -154
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactAppCompatActivity.java +30 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactAppCompatActivityDelegate.java +12 -37
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactFragment.java +31 -181
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactManager.java +115 -71
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactStackFragment.java +27 -16
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactSurfaceCleanup.java +50 -8
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarFragment.java +34 -4
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarProvider.java +39 -10
- package/android/src/main/java/com/reactnative/hybridnavigation/RemovalPlan.java +76 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/SceneLifecycleStateMachine.java +72 -6
- package/android/src/main/java/com/reactnative/hybridnavigation/Utils.java +19 -3
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/DrawerNavigator.java +11 -5
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/ScreenNavigator.java +217 -99
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/StackNavigator.java +122 -59
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/TabNavigator.java +87 -24
- package/dist/DeepLink.d.ts +3 -1
- package/dist/DeepLink.js +39 -19
- package/dist/NativeNavigation.d.ts +8 -5
- package/dist/Navigation.d.ts +9 -24
- package/dist/Navigation.js +32 -97
- package/dist/NavigationComponentWrap.d.ts +1 -2
- package/dist/NavigationComponentWrap.js +0 -15
- package/dist/Navigator.d.ts +7 -5
- package/dist/Navigator.js +38 -33
- package/dist/Options.d.ts +1 -6
- package/dist/Options.js +1 -2
- package/dist/Route.d.ts +24 -12
- package/dist/handler/DispatchCommandHandler.d.ts +4 -5
- package/dist/handler/DispatchCommandHandler.js +37 -16
- package/dist/handler/LayoutCommandHandler.js +18 -3
- package/dist/handler/LeaveGuardHandler.d.ts +12 -8
- package/dist/handler/LeaveGuardHandler.js +174 -281
- package/dist/handler/LifecycleEventHandler.d.ts +7 -4
- package/dist/handler/LifecycleEventHandler.js +119 -32
- package/dist/handler/ResultEventHandler.d.ts +2 -2
- package/dist/handler/ResultEventHandler.js +72 -36
- package/dist/handler/SceneExitHandler.d.ts +6 -0
- package/dist/handler/SceneExitHandler.js +48 -8
- package/dist/hooks.d.ts +1 -0
- package/dist/hooks.js +39 -23
- package/dist/index.d.ts +9 -8
- package/dist/index.js +5 -8
- package/dist/routeGraph.d.ts +5 -0
- package/dist/routeGraph.js +47 -0
- package/dist/router/drawer.d.ts +2 -2
- package/dist/router/drawer.js +19 -9
- package/dist/router/helpers.d.ts +17 -0
- package/dist/router/helpers.js +90 -0
- package/dist/router/index.d.ts +2 -2
- package/dist/router/index.js +169 -97
- package/dist/router/screen.d.ts +2 -2
- package/dist/router/screen.js +16 -7
- package/dist/router/stack.d.ts +2 -2
- package/dist/router/stack.js +24 -49
- package/dist/router/tabs.js +5 -1
- package/dist/store.d.ts +2 -0
- package/dist/store.js +4 -0
- package/ios/HBDGlobalStyle.h +0 -1
- package/ios/HBDGlobalStyle.mm +27 -39
- package/ios/HBDUtils.h +0 -2
- package/ios/HBDUtils.mm +81 -41
- package/ios/Navigator/HBDDrawerNavigator.mm +31 -26
- package/ios/Navigator/HBDNavigatorRegistry.mm +23 -26
- package/ios/Navigator/HBDScreenNavigator.mm +240 -137
- package/ios/Navigator/HBDStackNavigator.mm +147 -97
- package/ios/Navigator/HBDTabNavigator.mm +99 -46
- package/ios/React/HBDNativeEvent.mm +38 -5
- package/ios/React/HBDNativeNavigation.mm +49 -51
- package/ios/React/HBDNavigationCommandQueue.h +55 -0
- package/ios/React/HBDNavigationCommandQueue.mm +341 -0
- package/ios/React/HBDNavigator.h +20 -0
- package/ios/React/HBDOrientationCoordinator.mm +26 -3
- package/ios/React/HBDReactBridgeManager.h +18 -6
- package/ios/React/HBDReactBridgeManager.mm +536 -315
- package/ios/React/HBDSceneLifecycleStateMachine.h +2 -0
- package/ios/React/HBDSceneLifecycleStateMachine.mm +18 -0
- package/ios/View/HBDRootView.h +1 -0
- package/ios/View/HBDRootView.mm +112 -4
- package/ios/View/UIImage+WithBadge.mm +9 -7
- package/ios/ViewController/HBDDrawerController.h +10 -0
- package/ios/ViewController/HBDDrawerController.mm +103 -71
- package/ios/ViewController/HBDNavigationController.mm +166 -58
- package/ios/ViewController/HBDReactViewController.h +0 -2
- package/ios/ViewController/HBDReactViewController.mm +13 -102
- package/ios/ViewController/HBDTabBarController.mm +67 -33
- package/ios/ViewController/HBDViewController.h +6 -0
- package/ios/ViewController/HBDViewController.mm +94 -37
- package/ios/ViewController/UINavigationController+HBD.h +2 -2
- package/ios/ViewController/UINavigationController+HBD.mm +13 -13
- package/ios/ViewController/UIViewController+HBD.h +23 -1
- package/ios/ViewController/UIViewController+HBD.mm +298 -40
- package/package.json +1 -1
- package/src/DeepLink.ts +39 -19
- package/src/NativeNavigation.ts +17 -5
- package/src/Navigation.ts +49 -170
- package/src/NavigationComponentWrap.tsx +1 -16
- package/src/Navigator.ts +50 -52
- package/src/Options.ts +4 -9
- package/src/Route.ts +37 -19
- package/src/handler/DispatchCommandHandler.ts +42 -20
- package/src/handler/LayoutCommandHandler.ts +15 -3
- package/src/handler/LeaveGuardHandler.ts +224 -329
- package/src/handler/LifecycleEventHandler.ts +131 -37
- package/src/handler/ResultEventHandler.ts +71 -37
- package/src/handler/SceneExitHandler.ts +60 -9
- package/src/hooks.ts +54 -26
- package/src/index.ts +77 -8
- package/src/routeGraph.ts +50 -0
- package/src/router/drawer.ts +21 -10
- package/src/router/helpers.ts +113 -0
- package/src/router/index.ts +187 -112
- package/src/router/screen.ts +35 -8
- package/src/router/stack.ts +40 -53
- package/src/router/tabs.ts +5 -1
- package/src/store.ts +5 -0
- package/dist/sceneCoverage.d.ts +0 -2
- package/dist/sceneCoverage.js +0 -25
- package/src/sceneCoverage.ts +0 -30
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export function containsScene(graph, sceneId) {
|
|
2
|
+
return graph.sceneId === sceneId || Boolean(graph.children?.some(child => containsScene(child, sceneId)));
|
|
3
|
+
}
|
|
4
|
+
export function findNodeBySceneId(graph, sceneId) {
|
|
5
|
+
if (graph.sceneId === sceneId) {
|
|
6
|
+
return graph;
|
|
7
|
+
}
|
|
8
|
+
for (const child of graph.children ?? []) {
|
|
9
|
+
const found = findNodeBySceneId(child, sceneId);
|
|
10
|
+
if (found) {
|
|
11
|
+
return found;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
export function hasLayoutInGraph(graph, layout) {
|
|
17
|
+
return graph.layout === layout || Boolean(graph.children?.some(child => hasLayoutInGraph(child, layout)));
|
|
18
|
+
}
|
|
19
|
+
export function isSceneCoveredInLayers(layers, sceneId) {
|
|
20
|
+
function find(nodes, frontIndex) {
|
|
21
|
+
for (const [index, node] of nodes.entries()) {
|
|
22
|
+
const coveredBySibling = frontIndex !== undefined && index !== frontIndex;
|
|
23
|
+
if (node.sceneId === sceneId)
|
|
24
|
+
return coveredBySibling;
|
|
25
|
+
if (!node.children?.length)
|
|
26
|
+
continue;
|
|
27
|
+
let frontChild;
|
|
28
|
+
if (node.layout === 'stack') {
|
|
29
|
+
frontChild = node.children.length - 1;
|
|
30
|
+
}
|
|
31
|
+
else if (node.layout === 'tabs') {
|
|
32
|
+
if ('selectedIndex' in node && typeof node.selectedIndex === 'number') {
|
|
33
|
+
frontChild = node.selectedIndex;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
else if (node.layout === 'drawer') {
|
|
37
|
+
if ('menuOpened' in node && typeof node.menuOpened === 'boolean') {
|
|
38
|
+
frontChild = node.menuOpened ? 1 : 0;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const nested = find(node.children, frontChild);
|
|
42
|
+
if (nested !== undefined)
|
|
43
|
+
return coveredBySibling || nested;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return find(layers, layers.length - 1) === true;
|
|
47
|
+
}
|
package/dist/router/drawer.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { ScreenGraph } from './screen';
|
|
2
1
|
import { LayoutMode, RouteGraph, RouteHandler, RouteHandleResult, RouteInfo } from '../Route';
|
|
3
2
|
export interface DrawerGraph extends RouteGraph {
|
|
4
3
|
layout: 'drawer';
|
|
5
4
|
sceneId: string;
|
|
6
5
|
mode: LayoutMode;
|
|
7
|
-
|
|
6
|
+
menuOpened?: boolean;
|
|
7
|
+
children: [RouteGraph, RouteGraph];
|
|
8
8
|
}
|
|
9
9
|
export declare function isDrawerGraph(graph: RouteGraph): graph is DrawerGraph;
|
|
10
10
|
export declare class DrawerRouteHandler implements RouteHandler {
|
package/dist/router/drawer.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isTargetLocateIn } from './screen';
|
|
1
|
+
import { isScreenGraph, isTargetLocateIn } from './screen';
|
|
2
2
|
import Navigation from '../Navigation';
|
|
3
3
|
export function isDrawerGraph(graph) {
|
|
4
4
|
return graph.layout === 'drawer';
|
|
@@ -9,17 +9,27 @@ export class DrawerRouteHandler {
|
|
|
9
9
|
throw new Error(`${graph} is Not a DrawerGraph`);
|
|
10
10
|
}
|
|
11
11
|
const { children } = graph;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const res = await Navigation.dispatch(sceneId, 'openMenu');
|
|
15
|
-
return [true, null, res];
|
|
12
|
+
if (!Array.isArray(children)) {
|
|
13
|
+
return [false, graph];
|
|
16
14
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
const [content, menu] = children;
|
|
16
|
+
if (menu && isTargetLocateIn(menu, target)) {
|
|
17
|
+
const res = await Navigation.dispatch(graph.sceneId, 'openMenu');
|
|
18
|
+
if (!res.ok) {
|
|
19
|
+
return [true, null, res];
|
|
20
|
+
}
|
|
21
|
+
if (isScreenGraph(menu) && menu.moduleName === target.moduleName) {
|
|
22
|
+
return [true, null, res];
|
|
23
|
+
}
|
|
24
|
+
return [true, menu];
|
|
25
|
+
}
|
|
26
|
+
if (content && isTargetLocateIn(content, target)) {
|
|
27
|
+
const from = isScreenGraph(menu) ? menu.moduleName : undefined;
|
|
28
|
+
const result = await Navigation.dispatch(graph.sceneId, 'closeMenu', { from });
|
|
29
|
+
if (!result.ok) {
|
|
20
30
|
return [true, null, result];
|
|
21
31
|
}
|
|
22
|
-
return [true,
|
|
32
|
+
return [true, content];
|
|
23
33
|
}
|
|
24
34
|
return [false, graph];
|
|
25
35
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { DispatchResult, NavigationSnapshot, RouteInfo, RouteProcessContext } from '../Route';
|
|
2
|
+
export type RootSnapshotCheck = {
|
|
3
|
+
ok: true;
|
|
4
|
+
snapshot: NavigationSnapshot;
|
|
5
|
+
} | {
|
|
6
|
+
ok: false;
|
|
7
|
+
result: DispatchResult;
|
|
8
|
+
};
|
|
9
|
+
export declare function checkRootSnapshot(generation: number, isSuperseded?: () => boolean): Promise<RootSnapshotCheck>;
|
|
10
|
+
export declare function resolveProcessContext(context?: RouteProcessContext): Promise<{
|
|
11
|
+
ok: true;
|
|
12
|
+
context: RouteProcessContext;
|
|
13
|
+
} | {
|
|
14
|
+
ok: false;
|
|
15
|
+
result: DispatchResult;
|
|
16
|
+
}>;
|
|
17
|
+
export declare function pushRouteChain(startSceneId: string, startModuleName: string, intermediateModules: string[], target: RouteInfo, context: RouteProcessContext): Promise<DispatchResult>;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import Navigation from '../Navigation';
|
|
2
|
+
export async function checkRootSnapshot(generation, isSuperseded) {
|
|
3
|
+
const snapshot = await Navigation.navigationSnapshot();
|
|
4
|
+
if (isSuperseded?.()) {
|
|
5
|
+
return {
|
|
6
|
+
ok: false,
|
|
7
|
+
result: {
|
|
8
|
+
ok: false,
|
|
9
|
+
code: 'superseded',
|
|
10
|
+
message: 'Superseded by a newer router.open call.',
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
if (snapshot.rootGeneration !== generation) {
|
|
15
|
+
return {
|
|
16
|
+
ok: false,
|
|
17
|
+
result: {
|
|
18
|
+
ok: false,
|
|
19
|
+
code: 'superseded',
|
|
20
|
+
message: 'Root layout changed during navigation.',
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
if (snapshot.layers.length > 1) {
|
|
25
|
+
return {
|
|
26
|
+
ok: false,
|
|
27
|
+
result: {
|
|
28
|
+
ok: false,
|
|
29
|
+
code: 'covered',
|
|
30
|
+
message: 'A new layer was presented during navigation.',
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
return { ok: true, snapshot };
|
|
35
|
+
}
|
|
36
|
+
export async function resolveProcessContext(context) {
|
|
37
|
+
if (context) {
|
|
38
|
+
const check = await checkRootSnapshot(context.rootGeneration, context.isSuperseded);
|
|
39
|
+
if (!check.ok) {
|
|
40
|
+
return check;
|
|
41
|
+
}
|
|
42
|
+
return { ok: true, context };
|
|
43
|
+
}
|
|
44
|
+
const snapshot = await Navigation.navigationSnapshot();
|
|
45
|
+
if (snapshot.layers.length > 1) {
|
|
46
|
+
return {
|
|
47
|
+
ok: false,
|
|
48
|
+
result: {
|
|
49
|
+
ok: false,
|
|
50
|
+
code: 'covered',
|
|
51
|
+
message: 'A new layer was presented during navigation.',
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
ok: true,
|
|
57
|
+
context: {
|
|
58
|
+
rootGeneration: snapshot.rootGeneration,
|
|
59
|
+
isSuperseded: () => false,
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
export async function pushRouteChain(startSceneId, startModuleName, intermediateModules, target, context) {
|
|
64
|
+
const finalAction = target.mode === 'present' ? 'present' : target.mode === 'modal' ? 'showModal' : 'push';
|
|
65
|
+
let currentSceneId = startSceneId;
|
|
66
|
+
let from = startModuleName;
|
|
67
|
+
for (const dependency of intermediateModules) {
|
|
68
|
+
const stepResult = await Navigation.dispatch(currentSceneId, 'push', {
|
|
69
|
+
moduleName: dependency,
|
|
70
|
+
from,
|
|
71
|
+
to: dependency,
|
|
72
|
+
});
|
|
73
|
+
if (!stepResult.ok) {
|
|
74
|
+
return stepResult;
|
|
75
|
+
}
|
|
76
|
+
const check = await checkRootSnapshot(context.rootGeneration, context.isSuperseded);
|
|
77
|
+
if (!check.ok) {
|
|
78
|
+
return check.result;
|
|
79
|
+
}
|
|
80
|
+
currentSceneId = stepResult.sceneId ?? check.snapshot.currentRoute?.sceneId ?? currentSceneId;
|
|
81
|
+
from = dependency;
|
|
82
|
+
}
|
|
83
|
+
return await Navigation.dispatch(currentSceneId, finalAction, {
|
|
84
|
+
moduleName: target.moduleName,
|
|
85
|
+
props: target.props,
|
|
86
|
+
options: target.options,
|
|
87
|
+
from,
|
|
88
|
+
to: target.moduleName,
|
|
89
|
+
});
|
|
90
|
+
}
|
package/dist/router/index.d.ts
CHANGED
|
@@ -7,7 +7,8 @@ interface IndexType {
|
|
|
7
7
|
declare class Router {
|
|
8
8
|
constructor();
|
|
9
9
|
private handlers;
|
|
10
|
-
private
|
|
10
|
+
private requestSeq;
|
|
11
|
+
private openGeneration;
|
|
11
12
|
registerRouteHandler(layout: string, handler: RouteHandler): void;
|
|
12
13
|
private convertConfigToData;
|
|
13
14
|
private inflatedRouteConfigVersion;
|
|
@@ -20,7 +21,6 @@ declare class Router {
|
|
|
20
21
|
private routeDependencies;
|
|
21
22
|
private processRoute;
|
|
22
23
|
open(path: string, props?: IndexType, options?: NavigationItem): Promise<DispatchResult>;
|
|
23
|
-
private hasDrawerLayout;
|
|
24
24
|
private performOpen;
|
|
25
25
|
}
|
|
26
26
|
export declare const router: Router;
|
package/dist/router/index.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { match } from 'path-to-regexp';
|
|
2
2
|
import { StackRouteHandler } from './stack';
|
|
3
3
|
import { ScreenRouteHandler } from './screen';
|
|
4
4
|
import { TabsRouteHandler } from './tabs';
|
|
5
5
|
import { DrawerRouteHandler } from './drawer';
|
|
6
|
+
import { checkRootSnapshot, pushRouteChain } from './helpers';
|
|
6
7
|
import Navigation from '../Navigation';
|
|
8
|
+
import { containsScene, findNodeBySceneId, hasLayoutInGraph } from '../routeGraph';
|
|
7
9
|
import { getRouteConfigs, getRouteConfigVersion } from '../routeConfigRegistry';
|
|
10
|
+
const FORBIDDEN_QUERY_KEYS = new Set(['__proto__', 'constructor', 'prototype']);
|
|
8
11
|
function safeDecodeURIComponent(value) {
|
|
9
12
|
try {
|
|
10
13
|
return decodeURIComponent(value);
|
|
@@ -13,25 +16,23 @@ function safeDecodeURIComponent(value) {
|
|
|
13
16
|
return value;
|
|
14
17
|
}
|
|
15
18
|
}
|
|
19
|
+
function safeDecodeQueryComponent(value) {
|
|
20
|
+
return safeDecodeURIComponent(value.replace(/\+/g, ' '));
|
|
21
|
+
}
|
|
16
22
|
function queryParams(queryString) {
|
|
17
23
|
return (queryString || '').split('&').reduce((result, item) => {
|
|
18
24
|
if (item !== '') {
|
|
19
|
-
const nextResult = result || {};
|
|
20
25
|
const separatorIndex = item.indexOf('=');
|
|
21
26
|
const rawKey = separatorIndex >= 0 ? item.slice(0, separatorIndex) : item;
|
|
22
27
|
const rawValue = separatorIndex >= 0 ? item.slice(separatorIndex + 1) : '';
|
|
23
|
-
const key =
|
|
24
|
-
if (key) {
|
|
25
|
-
|
|
28
|
+
const key = safeDecodeQueryComponent(rawKey);
|
|
29
|
+
if (key && !FORBIDDEN_QUERY_KEYS.has(key)) {
|
|
30
|
+
result[key] = safeDecodeQueryComponent(rawValue);
|
|
26
31
|
}
|
|
27
|
-
return nextResult;
|
|
28
32
|
}
|
|
29
33
|
return result;
|
|
30
34
|
}, {});
|
|
31
35
|
}
|
|
32
|
-
function containsScene(node, sceneId) {
|
|
33
|
-
return node.sceneId === sceneId || !!node.children?.some(child => containsScene(child, sceneId));
|
|
34
|
-
}
|
|
35
36
|
class Router {
|
|
36
37
|
constructor() {
|
|
37
38
|
this.registerRouteHandler('screen', new ScreenRouteHandler());
|
|
@@ -40,26 +41,31 @@ class Router {
|
|
|
40
41
|
this.registerRouteHandler('drawer', new DrawerRouteHandler());
|
|
41
42
|
}
|
|
42
43
|
handlers = new Map();
|
|
43
|
-
|
|
44
|
+
requestSeq = 0;
|
|
45
|
+
openGeneration = 0;
|
|
44
46
|
registerRouteHandler(layout, handler) {
|
|
45
47
|
this.handlers.set(layout, handler);
|
|
46
48
|
}
|
|
47
49
|
convertConfigToData(moduleName, route) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
+
const { dependency } = route;
|
|
51
|
+
const normalizedPath = route.path
|
|
52
|
+
? route.path.startsWith('/')
|
|
53
|
+
? route.path
|
|
54
|
+
: '/' + route.path
|
|
55
|
+
: undefined;
|
|
50
56
|
let matcher;
|
|
51
|
-
if (
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
57
|
+
if (normalizedPath) {
|
|
58
|
+
try {
|
|
59
|
+
matcher = match(normalizedPath, {
|
|
60
|
+
decode: safeDecodeURIComponent,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
console.error(`[hybrid-navigation] Invalid route path "${route.path}" for module "${moduleName}".`, error);
|
|
55
65
|
}
|
|
56
|
-
regexp = pathToRegexp(path).regexp;
|
|
57
|
-
matcher = match(path, {
|
|
58
|
-
decode: safeDecodeURIComponent,
|
|
59
|
-
});
|
|
60
66
|
}
|
|
61
|
-
mode = mode || 'push';
|
|
62
|
-
return { moduleName, mode, path
|
|
67
|
+
const mode = route.mode || 'push';
|
|
68
|
+
return { moduleName, mode, path: normalizedPath, matcher, dependency };
|
|
63
69
|
}
|
|
64
70
|
inflatedRouteConfigVersion = -1;
|
|
65
71
|
routeDataSet = new Map();
|
|
@@ -68,26 +74,29 @@ class Router {
|
|
|
68
74
|
if (this.inflatedRouteConfigVersion === currentVersion) {
|
|
69
75
|
return;
|
|
70
76
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
for (const [moduleName, config] of routeConfigs) {
|
|
75
|
-
const data = this.convertConfigToData(moduleName, config);
|
|
76
|
-
this.routeDataSet.set(moduleName, data);
|
|
77
|
+
const nextRouteDataSet = new Map();
|
|
78
|
+
for (const [moduleName, config] of getRouteConfigs()) {
|
|
79
|
+
nextRouteDataSet.set(moduleName, this.convertConfigToData(moduleName, config));
|
|
77
80
|
}
|
|
81
|
+
this.routeDataSet = nextRouteDataSet;
|
|
82
|
+
this.inflatedRouteConfigVersion = currentVersion;
|
|
78
83
|
}
|
|
79
84
|
interceptors = [];
|
|
80
85
|
addInterceptor(interceptor) {
|
|
81
|
-
|
|
86
|
+
const entry = { fn: interceptor };
|
|
87
|
+
this.interceptors.push(entry);
|
|
82
88
|
return {
|
|
83
89
|
remove: () => {
|
|
84
|
-
|
|
90
|
+
const index = this.interceptors.indexOf(entry);
|
|
91
|
+
if (index >= 0) {
|
|
92
|
+
this.interceptors.splice(index, 1);
|
|
93
|
+
}
|
|
85
94
|
},
|
|
86
95
|
};
|
|
87
96
|
}
|
|
88
97
|
async intercept(path) {
|
|
89
|
-
for (const
|
|
90
|
-
const result =
|
|
98
|
+
for (const { fn } of this.interceptors.slice()) {
|
|
99
|
+
const result = fn(path);
|
|
91
100
|
const intercepted = result instanceof Promise ? await result : result;
|
|
92
101
|
if (intercepted) {
|
|
93
102
|
return true;
|
|
@@ -107,13 +116,15 @@ class Router {
|
|
|
107
116
|
}
|
|
108
117
|
const matched = data.matcher(pathName);
|
|
109
118
|
if (matched) {
|
|
110
|
-
const moduleName = data.moduleName;
|
|
111
119
|
const params = matched.params || {};
|
|
112
120
|
const query = queryParams(queryString);
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
121
|
+
return {
|
|
122
|
+
moduleName: data.moduleName,
|
|
123
|
+
props: { ...query, ...params, ...props },
|
|
124
|
+
dependencies: this.routeDependencies(data),
|
|
125
|
+
mode: data.mode,
|
|
126
|
+
options,
|
|
127
|
+
};
|
|
117
128
|
}
|
|
118
129
|
}
|
|
119
130
|
}
|
|
@@ -121,7 +132,7 @@ class Router {
|
|
|
121
132
|
const dependencies = [];
|
|
122
133
|
const visited = new Set([routeData.moduleName]);
|
|
123
134
|
let data = routeData;
|
|
124
|
-
while (data
|
|
135
|
+
while (data?.dependency) {
|
|
125
136
|
if (visited.has(data.dependency)) {
|
|
126
137
|
break;
|
|
127
138
|
}
|
|
@@ -131,36 +142,49 @@ class Router {
|
|
|
131
142
|
}
|
|
132
143
|
return dependencies.reverse();
|
|
133
144
|
}
|
|
134
|
-
async processRoute(graph, target) {
|
|
145
|
+
async processRoute(graph, target, context) {
|
|
135
146
|
const handler = this.handlers.get(graph.layout);
|
|
136
147
|
if (!handler) {
|
|
137
148
|
return [false, { ok: false, code: 'invalid_action' }];
|
|
138
149
|
}
|
|
139
|
-
const [consumed, childGraph, result] = await handler.process(graph, target);
|
|
150
|
+
const [consumed, childGraph, result] = await handler.process(graph, target, context);
|
|
140
151
|
if (consumed && childGraph) {
|
|
141
|
-
|
|
152
|
+
const check = await checkRootSnapshot(context.rootGeneration, context.isSuperseded);
|
|
153
|
+
if (!check.ok) {
|
|
154
|
+
return [true, check.result];
|
|
155
|
+
}
|
|
156
|
+
const rootLayer = check.snapshot.layers[0];
|
|
157
|
+
const freshChildGraph = rootLayer ? findNodeBySceneId(rootLayer, childGraph.sceneId) : null;
|
|
158
|
+
if (!freshChildGraph) {
|
|
159
|
+
return [
|
|
160
|
+
true,
|
|
161
|
+
{
|
|
162
|
+
ok: false,
|
|
163
|
+
code: 'scene_not_found',
|
|
164
|
+
message: 'Target container disappeared during navigation.',
|
|
165
|
+
},
|
|
166
|
+
];
|
|
167
|
+
}
|
|
168
|
+
return await this.processRoute(freshChildGraph, target, context);
|
|
142
169
|
}
|
|
143
170
|
return [consumed, result ?? { ok: true, code: 'ok' }];
|
|
144
171
|
}
|
|
145
|
-
open(path, props = {}, options = {}) {
|
|
146
|
-
const task = this.openQueue.then(() => this.performOpen(path, props, options), () => this.performOpen(path, props, options));
|
|
147
|
-
this.openQueue = task.then(() => undefined, () => undefined);
|
|
148
|
-
return task;
|
|
149
|
-
}
|
|
150
|
-
hasDrawerLayout(graph) {
|
|
151
|
-
if (graph.layout === 'drawer') {
|
|
152
|
-
return true;
|
|
153
|
-
}
|
|
154
|
-
if (!graph.children) {
|
|
155
|
-
return false;
|
|
156
|
-
}
|
|
157
|
-
return graph.children.some(child => this.hasDrawerLayout(child));
|
|
158
|
-
}
|
|
159
|
-
async performOpen(path, props, options) {
|
|
172
|
+
async open(path, props = {}, options = {}) {
|
|
160
173
|
this.inflateRouteData();
|
|
161
|
-
const
|
|
162
|
-
if (
|
|
163
|
-
|
|
174
|
+
const requestId = ++this.requestSeq;
|
|
175
|
+
if (this.interceptors.length > 0) {
|
|
176
|
+
const intercepted = await this.intercept(path);
|
|
177
|
+
if (intercepted) {
|
|
178
|
+
return { ok: false, code: 'intercepted' };
|
|
179
|
+
}
|
|
180
|
+
if (requestId < this.openGeneration) {
|
|
181
|
+
return {
|
|
182
|
+
ok: false,
|
|
183
|
+
code: 'superseded',
|
|
184
|
+
message: 'Superseded by a newer router.open call.',
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
this.inflateRouteData();
|
|
164
188
|
}
|
|
165
189
|
const route = this.pathToRoute(path, props, options);
|
|
166
190
|
if (!route) {
|
|
@@ -170,7 +194,19 @@ class Router {
|
|
|
170
194
|
message: `No route matched path: ${path}`,
|
|
171
195
|
};
|
|
172
196
|
}
|
|
197
|
+
this.openGeneration = requestId;
|
|
198
|
+
return this.performOpen(route, requestId);
|
|
199
|
+
}
|
|
200
|
+
async performOpen(route, openToken) {
|
|
201
|
+
const isSuperseded = () => openToken !== this.openGeneration;
|
|
173
202
|
let snapshot = await Navigation.navigationSnapshot();
|
|
203
|
+
if (isSuperseded()) {
|
|
204
|
+
return {
|
|
205
|
+
ok: false,
|
|
206
|
+
code: 'superseded',
|
|
207
|
+
message: 'Superseded by a newer router.open call.',
|
|
208
|
+
};
|
|
209
|
+
}
|
|
174
210
|
const generation = snapshot.rootGeneration;
|
|
175
211
|
const dismissed = new Set();
|
|
176
212
|
const maxSteps = Math.max(snapshot.layers.length, 12);
|
|
@@ -178,26 +214,62 @@ class Router {
|
|
|
178
214
|
const layer = snapshot.layers[snapshot.layers.length - 1];
|
|
179
215
|
const current = snapshot.currentRoute;
|
|
180
216
|
if (!current || !containsScene(layer, current.sceneId)) {
|
|
181
|
-
return {
|
|
217
|
+
return {
|
|
218
|
+
ok: false,
|
|
219
|
+
code: 'scene_not_found',
|
|
220
|
+
message: 'Current scene is not in the top layer.',
|
|
221
|
+
};
|
|
182
222
|
}
|
|
183
|
-
|
|
184
|
-
|
|
223
|
+
const dismissKey = `${layer.sceneId}:${current.sceneId}`;
|
|
224
|
+
if (dismissed.has(dismissKey) || dismissed.size >= maxSteps) {
|
|
225
|
+
return {
|
|
226
|
+
ok: false,
|
|
227
|
+
code: 'invalid_action',
|
|
228
|
+
message: 'Unable to finish dismissing presented layers.',
|
|
229
|
+
};
|
|
185
230
|
}
|
|
186
231
|
if (layer.mode !== 'modal' && layer.mode !== 'present') {
|
|
187
|
-
return {
|
|
232
|
+
return {
|
|
233
|
+
ok: false,
|
|
234
|
+
code: 'invalid_action',
|
|
235
|
+
message: `Unexpected layer mode: ${layer.mode}`,
|
|
236
|
+
};
|
|
188
237
|
}
|
|
189
|
-
dismissed.add(
|
|
190
|
-
const
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
238
|
+
dismissed.add(dismissKey);
|
|
239
|
+
const result = layer.mode === 'modal'
|
|
240
|
+
? await Navigation.dispatch(current.sceneId, 'close', {
|
|
241
|
+
from: current.moduleName,
|
|
242
|
+
})
|
|
243
|
+
: await Navigation.dispatch(current.sceneId, 'dismiss', {
|
|
244
|
+
from: current.moduleName,
|
|
245
|
+
target: 'self',
|
|
246
|
+
});
|
|
195
247
|
snapshot = await Navigation.navigationSnapshot();
|
|
248
|
+
if (isSuperseded()) {
|
|
249
|
+
return {
|
|
250
|
+
ok: false,
|
|
251
|
+
code: 'superseded',
|
|
252
|
+
message: 'Superseded by a newer router.open call.',
|
|
253
|
+
};
|
|
254
|
+
}
|
|
196
255
|
if (snapshot.rootGeneration !== generation) {
|
|
197
|
-
return {
|
|
256
|
+
return {
|
|
257
|
+
ok: false,
|
|
258
|
+
code: 'superseded',
|
|
259
|
+
message: 'Root layout changed during navigation.',
|
|
260
|
+
};
|
|
198
261
|
}
|
|
199
|
-
if (!result.ok)
|
|
262
|
+
if (!result.ok) {
|
|
263
|
+
if (result.code === 'scene_not_found') {
|
|
264
|
+
const topLayer = snapshot.layers[snapshot.layers.length - 1];
|
|
265
|
+
if (!topLayer ||
|
|
266
|
+
topLayer.sceneId !== layer.sceneId ||
|
|
267
|
+
snapshot.currentRoute?.sceneId !== current.sceneId) {
|
|
268
|
+
continue;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
200
271
|
return result;
|
|
272
|
+
}
|
|
201
273
|
}
|
|
202
274
|
const routeGraph = snapshot.layers[0];
|
|
203
275
|
if (!routeGraph) {
|
|
@@ -207,18 +279,19 @@ class Router {
|
|
|
207
279
|
message: 'Root route graph is missing.',
|
|
208
280
|
};
|
|
209
281
|
}
|
|
210
|
-
const
|
|
282
|
+
const context = {
|
|
283
|
+
rootGeneration: generation,
|
|
284
|
+
isSuperseded,
|
|
285
|
+
};
|
|
286
|
+
const [consumed, routeResult] = await this.processRoute(routeGraph, route, context);
|
|
211
287
|
if (consumed) {
|
|
212
288
|
return routeResult;
|
|
213
289
|
}
|
|
214
|
-
|
|
215
|
-
if (
|
|
216
|
-
return
|
|
217
|
-
}
|
|
218
|
-
if (snapshot.layers.length > 1) {
|
|
219
|
-
return { ok: false, code: 'covered', message: 'A new layer was presented during navigation.' };
|
|
290
|
+
let check = await checkRootSnapshot(generation, isSuperseded);
|
|
291
|
+
if (!check.ok) {
|
|
292
|
+
return check.result;
|
|
220
293
|
}
|
|
221
|
-
|
|
294
|
+
let currentRoute = check.snapshot.currentRoute;
|
|
222
295
|
if (!currentRoute) {
|
|
223
296
|
return {
|
|
224
297
|
ok: false,
|
|
@@ -226,28 +299,27 @@ class Router {
|
|
|
226
299
|
message: 'Unable to resolve current route.',
|
|
227
300
|
};
|
|
228
301
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
302
|
+
if (hasLayoutInGraph(routeGraph, 'drawer')) {
|
|
303
|
+
const closeMenuResult = await Navigation.dispatch(currentRoute.sceneId, 'closeMenu', {
|
|
304
|
+
from: currentRoute.moduleName,
|
|
305
|
+
});
|
|
232
306
|
if (closeMenuResult.code === 'intercepted') {
|
|
233
307
|
return closeMenuResult;
|
|
234
308
|
}
|
|
309
|
+
check = await checkRootSnapshot(generation, isSuperseded);
|
|
310
|
+
if (!check.ok) {
|
|
311
|
+
return check.result;
|
|
312
|
+
}
|
|
313
|
+
currentRoute = check.snapshot.currentRoute;
|
|
314
|
+
if (!currentRoute) {
|
|
315
|
+
return {
|
|
316
|
+
ok: false,
|
|
317
|
+
code: 'scene_not_found',
|
|
318
|
+
message: 'Unable to resolve current route.',
|
|
319
|
+
};
|
|
320
|
+
}
|
|
235
321
|
}
|
|
236
|
-
|
|
237
|
-
let action = 'push';
|
|
238
|
-
if (routeMode === 'present') {
|
|
239
|
-
action = 'present';
|
|
240
|
-
}
|
|
241
|
-
else if (routeMode === 'modal') {
|
|
242
|
-
action = 'showModal';
|
|
243
|
-
}
|
|
244
|
-
return await Navigation.dispatch(sceneId, action, {
|
|
245
|
-
moduleName,
|
|
246
|
-
props: initialProps,
|
|
247
|
-
options: route.options,
|
|
248
|
-
from,
|
|
249
|
-
to: moduleName,
|
|
250
|
-
});
|
|
322
|
+
return await pushRouteChain(currentRoute.sceneId, currentRoute.moduleName, route.dependencies, route, context);
|
|
251
323
|
}
|
|
252
324
|
}
|
|
253
325
|
export const router = new Router();
|
package/dist/router/screen.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LayoutMode, RouteGraph, RouteHandler, RouteHandleResult, RouteInfo } from '../Route';
|
|
1
|
+
import { LayoutMode, RouteGraph, RouteHandler, RouteHandleResult, RouteInfo, RouteProcessContext } from '../Route';
|
|
2
2
|
export interface ScreenGraph extends RouteGraph {
|
|
3
3
|
layout: 'screen';
|
|
4
4
|
sceneId: string;
|
|
@@ -8,5 +8,5 @@ export interface ScreenGraph extends RouteGraph {
|
|
|
8
8
|
export declare function isScreenGraph(graph: RouteGraph): graph is ScreenGraph;
|
|
9
9
|
export declare function isTargetLocateIn(graph: RouteGraph, target: RouteInfo): boolean;
|
|
10
10
|
export declare class ScreenRouteHandler implements RouteHandler {
|
|
11
|
-
process(graph: RouteGraph, target: RouteInfo): Promise<RouteHandleResult>;
|
|
11
|
+
process(graph: RouteGraph, target: RouteInfo, context?: RouteProcessContext): Promise<RouteHandleResult>;
|
|
12
12
|
}
|