hybrid-navigation 4.0.8 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/HybridNavigation.podspec +9 -1
- package/README.md +12 -4
- package/android/build.gradle +5 -4
- package/android/proguard-rules.pro +3 -0
- package/android/src/main/java/com/navigation/androidx/AwesomeActivity.java +114 -23
- package/android/src/main/java/com/navigation/androidx/AwesomeFragment.java +116 -13
- package/android/src/main/java/com/navigation/androidx/DrawableUtils.java +83 -18
- package/android/src/main/java/com/navigation/androidx/DrawerFragment.java +192 -28
- package/android/src/main/java/com/navigation/androidx/FragmentHelper.java +11 -0
- package/android/src/main/java/com/navigation/androidx/HybridDrawerLayout.java +563 -143
- package/android/src/main/java/com/navigation/androidx/LifecycleDelegate.java +47 -15
- package/android/src/main/java/com/navigation/androidx/PresentableActivity.java +3 -0
- package/android/src/main/java/com/navigation/androidx/PresentationDelegate.java +8 -3
- package/android/src/main/java/com/navigation/androidx/StackDelegate.java +29 -9
- package/android/src/main/java/com/navigation/androidx/StackFragment.java +28 -3
- package/android/src/main/java/com/navigation/androidx/SystemUI.java +59 -90
- package/android/src/main/java/com/navigation/androidx/TabBar.java +21 -2
- package/android/src/main/java/com/navigation/androidx/TabBarFragment.java +24 -7
- package/android/src/main/java/com/navigation/androidx/TabView.java +11 -2
- package/android/src/main/java/com/reactnative/hybridnavigation/DispatchResult.java +59 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/Garden.java +18 -10
- package/android/src/main/java/com/reactnative/hybridnavigation/GlobalStyle.java +15 -2
- package/android/src/main/java/com/reactnative/hybridnavigation/HBDRootView.java +3 -8
- package/android/src/main/java/com/reactnative/hybridnavigation/HybridFragment.java +113 -6
- package/android/src/main/java/com/reactnative/hybridnavigation/HybridNavigationPackage.java +13 -24
- package/android/src/main/java/com/reactnative/hybridnavigation/NativeEvent.java +5 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/NativeNavigation.java +196 -194
- package/android/src/main/java/com/reactnative/hybridnavigation/NavigationCommandQueue.java +499 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/Navigator.java +4 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/OrientationCoordinator.java +162 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactAppCompatActivity.java +103 -66
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactFragment.java +50 -87
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactManager.java +156 -77
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactStackFragment.java +6 -6
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactSurfaceCleanup.java +3 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarProvider.java +8 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/SceneLifecycleState.java +21 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/SceneLifecycleStateMachine.java +116 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/ScreenOrientation.java +42 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/Utils.java +17 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/DrawerNavigator.java +14 -6
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/ScreenNavigator.java +62 -22
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/StackNavigator.java +35 -16
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/TabNavigator.java +16 -13
- package/dist/DeepLink.d.ts +3 -2
- package/dist/DeepLink.js +37 -14
- package/dist/NativeEvent.d.ts +4 -12
- package/dist/NativeNavigation.d.ts +17 -19
- package/dist/Navigation.d.ts +21 -19
- package/dist/Navigation.js +83 -89
- package/dist/NavigationComponentWrap.d.ts +4 -3
- package/dist/NavigationComponentWrap.js +3 -6
- package/dist/Navigator.d.ts +31 -42
- package/dist/Navigator.js +97 -90
- package/dist/Options.d.ts +3 -1
- package/dist/Route.d.ts +85 -18
- package/dist/handler/DispatchCommandHandler.d.ts +10 -6
- package/dist/handler/DispatchCommandHandler.js +41 -17
- package/dist/handler/LayoutCommandHandler.d.ts +7 -7
- package/dist/handler/LayoutCommandHandler.js +21 -15
- package/dist/handler/LifecycleEventHandler.d.ts +26 -0
- package/dist/handler/LifecycleEventHandler.js +136 -0
- package/dist/handler/ResultEventHandler.d.ts +14 -9
- package/dist/handler/ResultEventHandler.js +88 -13
- package/dist/hooks.d.ts +5 -2
- package/dist/hooks.js +26 -4
- package/dist/index.d.ts +13 -0
- package/dist/index.js +0 -2
- package/dist/routeConfigRegistry.d.ts +6 -0
- package/dist/routeConfigRegistry.js +19 -0
- package/dist/router/drawer.d.ts +2 -2
- package/dist/router/drawer.js +6 -3
- package/dist/router/index.d.ts +8 -5
- package/dist/router/index.js +127 -43
- package/dist/router/screen.d.ts +2 -2
- package/dist/router/screen.js +1 -1
- package/dist/router/stack.d.ts +2 -2
- package/dist/router/stack.js +59 -30
- package/dist/router/tabs.d.ts +2 -2
- package/dist/router/tabs.js +4 -1
- package/dist/store.d.ts +2 -2
- package/ios/HBDGlobalStyle.h +26 -0
- package/ios/{GlobalStyle.mm → HBDGlobalStyle.mm} +30 -27
- package/ios/HybridNavigation.h +4 -1
- package/ios/Navigator/HBDDrawerNavigator.mm +24 -8
- package/ios/Navigator/HBDNavigatorRegistry.mm +1 -0
- package/ios/Navigator/HBDScreenNavigator.mm +106 -52
- package/ios/Navigator/HBDStackNavigator.mm +109 -61
- package/ios/Navigator/HBDTabNavigator.mm +32 -14
- package/ios/React/HBDNativeNavigation.mm +109 -131
- package/ios/React/HBDNavigator.h +29 -5
- package/ios/React/HBDOrientationCoordinator.h +27 -0
- package/ios/React/HBDOrientationCoordinator.mm +282 -0
- package/ios/React/HBDReactBridgeManager.h +37 -19
- package/ios/React/HBDReactBridgeManager.mm +490 -96
- package/ios/React/HBDSceneLifecycleStateMachine.h +38 -0
- package/ios/React/HBDSceneLifecycleStateMachine.mm +180 -0
- package/ios/View/HBDRootView.h +2 -0
- package/ios/View/HBDRootView.mm +148 -0
- package/ios/View/UIImage+WithBadge.h +3 -3
- package/ios/View/UIImage+WithBadge.mm +10 -15
- package/ios/ViewController/HBDDrawerController.mm +127 -6
- package/ios/ViewController/HBDNavigationController.mm +17 -4
- package/ios/ViewController/HBDReactViewController.mm +59 -121
- package/ios/ViewController/HBDTabBarController.h +4 -0
- package/ios/ViewController/HBDTabBarController.mm +59 -44
- package/ios/ViewController/HBDViewController.h +10 -3
- package/ios/ViewController/HBDViewController.mm +161 -147
- package/ios/ViewController/UINavigationController+HBD.h +2 -2
- package/ios/ViewController/UINavigationController+HBD.mm +3 -3
- package/ios/ViewController/UIViewController+HBD.h +17 -10
- package/ios/ViewController/UIViewController+HBD.mm +85 -69
- package/package.json +1 -1
- package/src/DeepLink.ts +41 -14
- package/src/NativeEvent.ts +4 -14
- package/src/NativeNavigation.ts +22 -33
- package/src/Navigation.ts +162 -121
- package/src/NavigationComponentWrap.tsx +9 -9
- package/src/Navigator.ts +191 -153
- package/src/Options.ts +3 -1
- package/src/Route.ts +134 -19
- package/src/handler/DispatchCommandHandler.ts +55 -21
- package/src/handler/LayoutCommandHandler.ts +36 -17
- package/src/handler/LifecycleEventHandler.ts +172 -0
- package/src/handler/ResultEventHandler.ts +112 -19
- package/src/hooks.ts +39 -7
- package/src/index.ts +26 -2
- package/src/routeConfigRegistry.ts +26 -0
- package/src/router/drawer.ts +8 -5
- package/src/router/index.ts +161 -50
- package/src/router/screen.ts +3 -3
- package/src/router/stack.ts +80 -29
- package/src/router/tabs.ts +15 -7
- package/src/store.ts +1 -1
- package/android/src/main/java/androidx/fragment/app/InternalFragment.java +0 -22
- package/android/src/main/java/com/navigation/androidx/SystemUI30.java +0 -87
- package/android/src/main/java/com/reactnative/hybridnavigation/NativeGarden.java +0 -176
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBar.java +0 -130
- package/android/src/main/res/layout/nav_tab_bar_react.xml +0 -32
- package/android/src/main/res/layout/nav_tab_bar_react_indeterminate.xml +0 -32
- package/dist/NativeGarden.d.ts +0 -13
- package/dist/NativeGarden.js +0 -2
- package/dist/handler/VisibilityEventHandler.d.ts +0 -13
- package/dist/handler/VisibilityEventHandler.js +0 -39
- package/ios/GlobalStyle.h +0 -15
- package/ios/React/HBDNativeGarden.h +0 -10
- package/ios/React/HBDNativeGarden.mm +0 -111
- package/src/NativeGarden.ts +0 -16
- package/src/handler/VisibilityEventHandler.ts +0 -52
package/dist/hooks.js
CHANGED
|
@@ -1,8 +1,26 @@
|
|
|
1
|
-
import { useContext, useEffect, useEffectEvent } from 'react';
|
|
1
|
+
import { useContext, useEffect, useEffectEvent, useState } from 'react';
|
|
2
2
|
import Navigation from './Navigation';
|
|
3
3
|
import { NavigationContext } from './Navigator';
|
|
4
4
|
export function useNavigator() {
|
|
5
|
-
|
|
5
|
+
const navigator = useContext(NavigationContext);
|
|
6
|
+
if (!navigator) {
|
|
7
|
+
throw new Error('[hybrid-navigation] useNavigator() must be used inside a screen registered with Navigation.registerComponent().');
|
|
8
|
+
}
|
|
9
|
+
return navigator;
|
|
10
|
+
}
|
|
11
|
+
export function useSceneState() {
|
|
12
|
+
const navigator = useNavigator();
|
|
13
|
+
const [state, setState] = useState(() => Navigation.getSceneState(navigator.sceneId));
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
setState(Navigation.getSceneState(navigator.sceneId));
|
|
16
|
+
const subscription = Navigation.addLifecycleListener(navigator.sceneId, nextState => {
|
|
17
|
+
setState(nextState);
|
|
18
|
+
});
|
|
19
|
+
return () => {
|
|
20
|
+
subscription.remove();
|
|
21
|
+
};
|
|
22
|
+
}, [navigator.sceneId]);
|
|
23
|
+
return state;
|
|
6
24
|
}
|
|
7
25
|
export function useVisibleEffect(callback) {
|
|
8
26
|
const navigator = useNavigator();
|
|
@@ -17,13 +35,17 @@ export function useVisibleEffect(callback) {
|
|
|
17
35
|
destructor = event();
|
|
18
36
|
}
|
|
19
37
|
else {
|
|
20
|
-
destructor
|
|
38
|
+
if (typeof destructor === 'function') {
|
|
39
|
+
destructor();
|
|
40
|
+
}
|
|
21
41
|
destructor = undefined;
|
|
22
42
|
}
|
|
23
43
|
});
|
|
24
44
|
return () => {
|
|
25
45
|
subscription.remove();
|
|
26
|
-
destructor
|
|
46
|
+
if (typeof destructor === 'function') {
|
|
47
|
+
destructor();
|
|
48
|
+
}
|
|
27
49
|
};
|
|
28
50
|
}, [navigator]);
|
|
29
51
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Augment this interface via `declare module 'hybrid-navigation'` to enable
|
|
3
|
+
* strongly typed route names, props, and navigation results.
|
|
4
|
+
*/
|
|
5
|
+
export interface NavigationParamList {
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Augment this interface via `declare module 'hybrid-navigation'` to register
|
|
9
|
+
* strongly typed custom container layouts alongside built-in layouts.
|
|
10
|
+
*/
|
|
11
|
+
export interface CustomLayoutMap {
|
|
12
|
+
}
|
|
1
13
|
declare const Navigation: import("./Navigation").Navigation;
|
|
2
14
|
export default Navigation;
|
|
3
15
|
export { RESULT_OK, RESULT_CANCEL, RESULT_BLOCK } from './Navigation';
|
|
16
|
+
export type { DispatchParams, GlobalSceneLifecycleListener, GlobalVisibilityEventListener, HOC, InterceptParams, Navigation, NavigationInterceptor, NavigationSubscription, ResultType, RootLayoutListener, SceneLifecycleListener, VisibilityEventListener, } from './Navigation';
|
|
4
17
|
export { withNavigationItem } from './NavigationComponentWrap';
|
|
5
18
|
export type { NavigationProps } from './NavigationComponentWrap';
|
|
6
19
|
export * from './Navigator';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { withNavigation } from './NavigationComponentWrap';
|
|
2
1
|
import navigation from './Navigation';
|
|
3
|
-
navigation.setNavigationComponentWrap(withNavigation);
|
|
4
2
|
const Navigation = navigation;
|
|
5
3
|
export default Navigation;
|
|
6
4
|
export { RESULT_OK, RESULT_CANCEL, RESULT_BLOCK } from './Navigation';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { RouteConfig } from './Route';
|
|
2
|
+
export declare function clearRouteConfigs(): void;
|
|
3
|
+
export declare function setRouteConfig(moduleName: string, config: RouteConfig): void;
|
|
4
|
+
export declare function bumpRouteConfigVersion(): void;
|
|
5
|
+
export declare function getRouteConfigs(): ReadonlyMap<string, RouteConfig>;
|
|
6
|
+
export declare function getRouteConfigVersion(): number;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const routeConfigs = new Map();
|
|
2
|
+
let routeConfigVersion = 0;
|
|
3
|
+
export function clearRouteConfigs() {
|
|
4
|
+
routeConfigs.clear();
|
|
5
|
+
routeConfigVersion++;
|
|
6
|
+
}
|
|
7
|
+
export function setRouteConfig(moduleName, config) {
|
|
8
|
+
routeConfigs.set(moduleName, config);
|
|
9
|
+
routeConfigVersion++;
|
|
10
|
+
}
|
|
11
|
+
export function bumpRouteConfigVersion() {
|
|
12
|
+
routeConfigVersion++;
|
|
13
|
+
}
|
|
14
|
+
export function getRouteConfigs() {
|
|
15
|
+
return routeConfigs;
|
|
16
|
+
}
|
|
17
|
+
export function getRouteConfigVersion() {
|
|
18
|
+
return routeConfigVersion;
|
|
19
|
+
}
|
package/dist/router/drawer.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ScreenGraph } from './screen';
|
|
2
|
-
import { LayoutMode, RouteGraph, RouteHandler, RouteInfo } from '../Route';
|
|
2
|
+
import { LayoutMode, RouteGraph, RouteHandler, RouteHandleResult, RouteInfo } from '../Route';
|
|
3
3
|
export interface DrawerGraph extends RouteGraph {
|
|
4
4
|
layout: 'drawer';
|
|
5
5
|
sceneId: string;
|
|
@@ -8,5 +8,5 @@ export interface DrawerGraph extends RouteGraph {
|
|
|
8
8
|
}
|
|
9
9
|
export declare function isDrawerGraph(graph: RouteGraph): graph is DrawerGraph;
|
|
10
10
|
export declare class DrawerRouteHandler implements RouteHandler {
|
|
11
|
-
process(graph: RouteGraph, target: RouteInfo): Promise<
|
|
11
|
+
process(graph: RouteGraph, target: RouteInfo): Promise<RouteHandleResult>;
|
|
12
12
|
}
|
package/dist/router/drawer.js
CHANGED
|
@@ -11,11 +11,14 @@ export class DrawerRouteHandler {
|
|
|
11
11
|
const { children } = graph;
|
|
12
12
|
const { moduleName, sceneId } = children[1];
|
|
13
13
|
if (moduleName === target.moduleName) {
|
|
14
|
-
await Navigation.dispatch(sceneId, 'openMenu');
|
|
15
|
-
return [true, null];
|
|
14
|
+
const res = await Navigation.dispatch(sceneId, 'openMenu');
|
|
15
|
+
return [true, null, res];
|
|
16
16
|
}
|
|
17
17
|
if (isTargetLocateIn(children[0], target)) {
|
|
18
|
-
Navigation.dispatch(sceneId, 'closeMenu', { from: moduleName });
|
|
18
|
+
const result = await Navigation.dispatch(sceneId, 'closeMenu', { from: moduleName });
|
|
19
|
+
if (result.code === 'intercepted') {
|
|
20
|
+
return [true, null, result];
|
|
21
|
+
}
|
|
19
22
|
return [true, children[0]];
|
|
20
23
|
}
|
|
21
24
|
return [false, graph];
|
package/dist/router/index.d.ts
CHANGED
|
@@ -1,25 +1,28 @@
|
|
|
1
|
-
import { RouteHandler, RouteInterceptor } from '../Route';
|
|
1
|
+
import { DispatchResult, RouteHandler, RouteInterceptor } from '../Route';
|
|
2
2
|
import { NavigationItem } from '../Options';
|
|
3
|
+
import type { NavigationSubscription } from '../Navigation';
|
|
3
4
|
interface IndexType {
|
|
4
5
|
[index: string]: any;
|
|
5
6
|
}
|
|
6
7
|
declare class Router {
|
|
7
8
|
constructor();
|
|
8
9
|
private handlers;
|
|
10
|
+
private openQueue;
|
|
9
11
|
registerRouteHandler(layout: string, handler: RouteHandler): void;
|
|
10
12
|
private convertConfigToData;
|
|
11
|
-
private
|
|
13
|
+
private inflatedRouteConfigVersion;
|
|
12
14
|
private routeDataSet;
|
|
13
15
|
private inflateRouteData;
|
|
14
16
|
private interceptors;
|
|
15
|
-
addInterceptor(interceptor: RouteInterceptor):
|
|
17
|
+
addInterceptor(interceptor: RouteInterceptor): NavigationSubscription;
|
|
16
18
|
removeInterceptor(interceptor: RouteInterceptor): void;
|
|
17
19
|
private intercept;
|
|
18
|
-
private resolveInterceptResult;
|
|
19
20
|
private pathToRoute;
|
|
20
21
|
private routeDependencies;
|
|
21
22
|
private processRoute;
|
|
22
|
-
open(path: string, props?: IndexType, options?: NavigationItem): Promise<
|
|
23
|
+
open(path: string, props?: IndexType, options?: NavigationItem): Promise<DispatchResult>;
|
|
24
|
+
private hasDrawerLayout;
|
|
25
|
+
private performOpen;
|
|
23
26
|
}
|
|
24
27
|
export declare const router: Router;
|
|
25
28
|
export * from './drawer';
|
package/dist/router/index.js
CHANGED
|
@@ -4,18 +4,26 @@ import { ScreenRouteHandler } from './screen';
|
|
|
4
4
|
import { TabsRouteHandler } from './tabs';
|
|
5
5
|
import { DrawerRouteHandler } from './drawer';
|
|
6
6
|
import Navigation from '../Navigation';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
import { getRouteConfigs, getRouteConfigVersion } from '../routeConfigRegistry';
|
|
8
|
+
function safeDecodeURIComponent(value) {
|
|
9
|
+
try {
|
|
10
|
+
return decodeURIComponent(value);
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
12
15
|
}
|
|
13
16
|
function queryParams(queryString) {
|
|
14
17
|
return (queryString || '').split('&').reduce((result, item) => {
|
|
15
18
|
if (item !== '') {
|
|
16
19
|
const nextResult = result || {};
|
|
17
|
-
const
|
|
18
|
-
|
|
20
|
+
const separatorIndex = item.indexOf('=');
|
|
21
|
+
const rawKey = separatorIndex >= 0 ? item.slice(0, separatorIndex) : item;
|
|
22
|
+
const rawValue = separatorIndex >= 0 ? item.slice(separatorIndex + 1) : '';
|
|
23
|
+
const key = safeDecodeURIComponent(rawKey);
|
|
24
|
+
if (key) {
|
|
25
|
+
nextResult[key] = safeDecodeURIComponent(rawValue);
|
|
26
|
+
}
|
|
19
27
|
return nextResult;
|
|
20
28
|
}
|
|
21
29
|
return result;
|
|
@@ -29,29 +37,37 @@ class Router {
|
|
|
29
37
|
this.registerRouteHandler('drawer', new DrawerRouteHandler());
|
|
30
38
|
}
|
|
31
39
|
handlers = new Map();
|
|
40
|
+
openQueue = Promise.resolve();
|
|
32
41
|
registerRouteHandler(layout, handler) {
|
|
33
42
|
this.handlers.set(layout, handler);
|
|
34
43
|
}
|
|
35
44
|
convertConfigToData(moduleName, route) {
|
|
36
45
|
let { path, dependency, mode } = route;
|
|
37
46
|
let regexp;
|
|
47
|
+
let matcher;
|
|
38
48
|
if (path) {
|
|
39
49
|
if (!path.startsWith('/')) {
|
|
40
|
-
|
|
50
|
+
path = '/' + path;
|
|
51
|
+
route.path = path;
|
|
41
52
|
}
|
|
42
53
|
regexp = pathToRegexp(path).regexp;
|
|
54
|
+
matcher = match(path, {
|
|
55
|
+
decode: safeDecodeURIComponent,
|
|
56
|
+
});
|
|
43
57
|
}
|
|
44
58
|
mode = mode || 'push';
|
|
45
|
-
return { moduleName, mode, path, regexp, dependency };
|
|
59
|
+
return { moduleName, mode, path, regexp, matcher, dependency };
|
|
46
60
|
}
|
|
47
|
-
|
|
61
|
+
inflatedRouteConfigVersion = -1;
|
|
48
62
|
routeDataSet = new Map();
|
|
49
63
|
inflateRouteData() {
|
|
50
|
-
|
|
64
|
+
const currentVersion = getRouteConfigVersion();
|
|
65
|
+
if (this.inflatedRouteConfigVersion === currentVersion) {
|
|
51
66
|
return;
|
|
52
67
|
}
|
|
53
|
-
this.
|
|
54
|
-
|
|
68
|
+
this.inflatedRouteConfigVersion = currentVersion;
|
|
69
|
+
this.routeDataSet.clear();
|
|
70
|
+
const routeConfigs = getRouteConfigs();
|
|
55
71
|
for (const [moduleName, config] of routeConfigs) {
|
|
56
72
|
const data = this.convertConfigToData(moduleName, config);
|
|
57
73
|
this.routeDataSet.set(moduleName, data);
|
|
@@ -60,47 +76,54 @@ class Router {
|
|
|
60
76
|
interceptors = [];
|
|
61
77
|
addInterceptor(interceptor) {
|
|
62
78
|
this.interceptors.push(interceptor);
|
|
79
|
+
return {
|
|
80
|
+
remove: () => this.removeInterceptor(interceptor),
|
|
81
|
+
};
|
|
63
82
|
}
|
|
64
83
|
removeInterceptor(interceptor) {
|
|
65
84
|
this.interceptors = this.interceptors.filter(item => item !== interceptor);
|
|
66
85
|
}
|
|
67
86
|
async intercept(path) {
|
|
68
|
-
for (
|
|
87
|
+
for (const interceptor of this.interceptors.slice()) {
|
|
69
88
|
const result = interceptor(path);
|
|
70
|
-
const intercepted = await
|
|
89
|
+
const intercepted = result instanceof Promise ? await result : result;
|
|
71
90
|
if (intercepted) {
|
|
72
91
|
return true;
|
|
73
92
|
}
|
|
74
93
|
}
|
|
75
94
|
return false;
|
|
76
95
|
}
|
|
77
|
-
resolveInterceptResult(result) {
|
|
78
|
-
if (result instanceof Promise) {
|
|
79
|
-
return result;
|
|
80
|
-
}
|
|
81
|
-
return Promise.resolve(result);
|
|
82
|
-
}
|
|
83
96
|
pathToRoute(path, props, options) {
|
|
97
|
+
const withoutHash = path.split('#')[0];
|
|
98
|
+
const queryIndex = withoutHash.indexOf('?');
|
|
99
|
+
const rawPathName = queryIndex >= 0 ? withoutHash.slice(0, queryIndex) : withoutHash;
|
|
100
|
+
const queryString = queryIndex >= 0 ? withoutHash.slice(queryIndex + 1) : '';
|
|
101
|
+
const pathName = rawPathName.startsWith('/') ? rawPathName : '/' + rawPathName;
|
|
84
102
|
for (const data of this.routeDataSet.values()) {
|
|
85
|
-
if (!data.
|
|
103
|
+
if (!data.matcher) {
|
|
86
104
|
continue;
|
|
87
105
|
}
|
|
88
|
-
const
|
|
89
|
-
if (
|
|
106
|
+
const matched = data.matcher(pathName);
|
|
107
|
+
if (matched) {
|
|
90
108
|
const moduleName = data.moduleName;
|
|
91
|
-
const params =
|
|
109
|
+
const params = matched.params || {};
|
|
92
110
|
const query = queryParams(queryString);
|
|
93
|
-
|
|
111
|
+
const mergedProps = { ...query, ...params, ...props };
|
|
94
112
|
const dependencies = this.routeDependencies(data);
|
|
95
113
|
const mode = data.mode;
|
|
96
|
-
return { moduleName, props, dependencies, mode, options };
|
|
114
|
+
return { moduleName, props: mergedProps, dependencies, mode, options };
|
|
97
115
|
}
|
|
98
116
|
}
|
|
99
117
|
}
|
|
100
118
|
routeDependencies(routeData) {
|
|
101
|
-
|
|
119
|
+
const dependencies = [];
|
|
120
|
+
const visited = new Set([routeData.moduleName]);
|
|
102
121
|
let data = routeData;
|
|
103
122
|
while (data && data.dependency) {
|
|
123
|
+
if (visited.has(data.dependency)) {
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
126
|
+
visited.add(data.dependency);
|
|
104
127
|
dependencies.push(data.dependency);
|
|
105
128
|
data = this.routeDataSet.get(data.dependency);
|
|
106
129
|
}
|
|
@@ -109,51 +132,111 @@ class Router {
|
|
|
109
132
|
async processRoute(graph, target) {
|
|
110
133
|
const handler = this.handlers.get(graph.layout);
|
|
111
134
|
if (!handler) {
|
|
112
|
-
return false;
|
|
135
|
+
return [false, { ok: false, code: 'invalid_action' }];
|
|
113
136
|
}
|
|
114
|
-
const [consumed, childGraph] = await handler.process(graph, target);
|
|
137
|
+
const [consumed, childGraph, result] = await handler.process(graph, target);
|
|
115
138
|
if (consumed && childGraph) {
|
|
116
139
|
return await this.processRoute(childGraph, target);
|
|
117
140
|
}
|
|
118
|
-
return consumed;
|
|
141
|
+
return [consumed, result ?? { ok: true, code: 'ok' }];
|
|
142
|
+
}
|
|
143
|
+
open(path, props = {}, options = {}) {
|
|
144
|
+
const task = this.openQueue.then(() => this.performOpen(path, props, options), () => this.performOpen(path, props, options));
|
|
145
|
+
this.openQueue = task.then(() => undefined, () => undefined);
|
|
146
|
+
return task;
|
|
119
147
|
}
|
|
120
|
-
|
|
148
|
+
hasDrawerLayout(graph) {
|
|
149
|
+
if (graph.layout === 'drawer') {
|
|
150
|
+
return true;
|
|
151
|
+
}
|
|
152
|
+
if (!graph.children) {
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
return graph.children.some(child => this.hasDrawerLayout(child));
|
|
156
|
+
}
|
|
157
|
+
async performOpen(path, props, options) {
|
|
121
158
|
this.inflateRouteData();
|
|
122
159
|
const intercepted = await this.intercept(path);
|
|
123
160
|
if (intercepted) {
|
|
124
|
-
return;
|
|
161
|
+
return { ok: false, code: 'intercepted' };
|
|
125
162
|
}
|
|
126
163
|
const route = this.pathToRoute(path, props, options);
|
|
127
164
|
if (!route) {
|
|
128
|
-
return
|
|
165
|
+
return {
|
|
166
|
+
ok: false,
|
|
167
|
+
code: 'scene_not_found',
|
|
168
|
+
message: `No route matched path: ${path}`,
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
let graphArray = await Navigation.routeGraph();
|
|
172
|
+
if (!graphArray || graphArray.length === 0) {
|
|
173
|
+
return {
|
|
174
|
+
ok: false,
|
|
175
|
+
code: 'not_ready',
|
|
176
|
+
message: 'Route graph is empty.',
|
|
177
|
+
};
|
|
129
178
|
}
|
|
130
|
-
const graphArray = await Navigation.routeGraph();
|
|
131
179
|
if (graphArray.length > 1) {
|
|
132
180
|
for (let index = graphArray.length - 1; index > 0; index--) {
|
|
133
181
|
const { mode: layoutMode } = graphArray[index];
|
|
134
|
-
const
|
|
182
|
+
const currentRoute = await Navigation.currentRoute();
|
|
183
|
+
if (!currentRoute) {
|
|
184
|
+
return {
|
|
185
|
+
ok: false,
|
|
186
|
+
code: 'scene_not_found',
|
|
187
|
+
message: 'Unable to resolve current route while dismissing presented scenes.',
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
const { sceneId, moduleName } = currentRoute;
|
|
135
191
|
if (layoutMode === 'present') {
|
|
136
|
-
await Navigation.dispatch(sceneId, 'dismiss', {
|
|
192
|
+
const res = await Navigation.dispatch(sceneId, 'dismiss', {
|
|
137
193
|
from: moduleName,
|
|
138
194
|
});
|
|
195
|
+
if (!res.ok) {
|
|
196
|
+
return res;
|
|
197
|
+
}
|
|
139
198
|
}
|
|
140
199
|
else if (layoutMode === 'modal') {
|
|
141
|
-
await Navigation.dispatch(sceneId, 'hideModal', {
|
|
200
|
+
const res = await Navigation.dispatch(sceneId, 'hideModal', {
|
|
142
201
|
from: moduleName,
|
|
143
202
|
});
|
|
203
|
+
if (!res.ok) {
|
|
204
|
+
return res;
|
|
205
|
+
}
|
|
144
206
|
}
|
|
145
207
|
else {
|
|
146
208
|
console.warn('尚未处理的 layout mode:' + layoutMode);
|
|
147
209
|
}
|
|
148
210
|
}
|
|
211
|
+
graphArray = await Navigation.routeGraph();
|
|
149
212
|
}
|
|
150
213
|
const routeGraph = graphArray[0];
|
|
151
|
-
|
|
214
|
+
if (!routeGraph) {
|
|
215
|
+
return {
|
|
216
|
+
ok: false,
|
|
217
|
+
code: 'not_ready',
|
|
218
|
+
message: 'Root route graph is missing.',
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
const [consumed, routeResult] = await this.processRoute(routeGraph, route);
|
|
152
222
|
if (consumed) {
|
|
153
|
-
return;
|
|
223
|
+
return routeResult;
|
|
224
|
+
}
|
|
225
|
+
const currentRoute = await Navigation.currentRoute();
|
|
226
|
+
if (!currentRoute) {
|
|
227
|
+
return {
|
|
228
|
+
ok: false,
|
|
229
|
+
code: 'scene_not_found',
|
|
230
|
+
message: 'Unable to resolve current route.',
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
const { sceneId, moduleName: from } = currentRoute;
|
|
234
|
+
if (this.hasDrawerLayout(routeGraph)) {
|
|
235
|
+
const closeMenuResult = await Navigation.dispatch(sceneId, 'closeMenu', { from });
|
|
236
|
+
if (closeMenuResult.code === 'intercepted') {
|
|
237
|
+
return closeMenuResult;
|
|
238
|
+
}
|
|
154
239
|
}
|
|
155
|
-
const { sceneId, moduleName: from } = await Navigation.currentRoute();
|
|
156
|
-
Navigation.dispatch(sceneId, 'closeMenu', { from });
|
|
157
240
|
const { moduleName, mode: routeMode, props: initialProps } = route;
|
|
158
241
|
let action = 'push';
|
|
159
242
|
if (routeMode === 'present') {
|
|
@@ -162,9 +245,10 @@ class Router {
|
|
|
162
245
|
else if (routeMode === 'modal') {
|
|
163
246
|
action = 'showModal';
|
|
164
247
|
}
|
|
165
|
-
Navigation.dispatch(sceneId, action, {
|
|
248
|
+
return await Navigation.dispatch(sceneId, action, {
|
|
166
249
|
moduleName,
|
|
167
250
|
props: initialProps,
|
|
251
|
+
options: route.options,
|
|
168
252
|
from,
|
|
169
253
|
to: moduleName,
|
|
170
254
|
});
|
package/dist/router/screen.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LayoutMode, RouteGraph, RouteHandler, RouteInfo } from '../Route';
|
|
1
|
+
import { LayoutMode, RouteGraph, RouteHandler, RouteHandleResult, RouteInfo } 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<
|
|
11
|
+
process(graph: RouteGraph, target: RouteInfo): Promise<RouteHandleResult>;
|
|
12
12
|
}
|
package/dist/router/screen.js
CHANGED
|
@@ -25,7 +25,7 @@ export class ScreenRouteHandler {
|
|
|
25
25
|
throw new Error(`${graph} is Not a ScreenGraph`);
|
|
26
26
|
}
|
|
27
27
|
if (graph.moduleName === target.moduleName) {
|
|
28
|
-
return Promise.resolve([true, null]);
|
|
28
|
+
return Promise.resolve([true, null, { ok: true, code: 'ok' }]);
|
|
29
29
|
}
|
|
30
30
|
return Promise.resolve([false, graph]);
|
|
31
31
|
}
|
package/dist/router/stack.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LayoutMode, RouteGraph, RouteHandler, RouteInfo } from '../Route';
|
|
1
|
+
import { LayoutMode, RouteGraph, RouteHandler, RouteHandleResult, RouteInfo } from '../Route';
|
|
2
2
|
export interface StackGraph extends RouteGraph {
|
|
3
3
|
layout: 'stack';
|
|
4
4
|
sceneId: string;
|
|
@@ -7,7 +7,7 @@ export interface StackGraph extends RouteGraph {
|
|
|
7
7
|
}
|
|
8
8
|
export declare function isStackGraph(graph: RouteGraph): graph is StackGraph;
|
|
9
9
|
export declare class StackRouteHandler implements RouteHandler {
|
|
10
|
-
process(graph: RouteGraph, target: RouteInfo): Promise<
|
|
10
|
+
process(graph: RouteGraph, target: RouteInfo): Promise<RouteHandleResult>;
|
|
11
11
|
private popToIfNeeded;
|
|
12
12
|
private navigateTo;
|
|
13
13
|
}
|
package/dist/router/stack.js
CHANGED
|
@@ -13,10 +13,13 @@ export class StackRouteHandler {
|
|
|
13
13
|
const childGraph = children[i];
|
|
14
14
|
if (isTargetLocateIn(childGraph, target)) {
|
|
15
15
|
if (isScreenGraph(childGraph)) {
|
|
16
|
-
this.navigateTo(childGraph, target);
|
|
17
|
-
return [true, null];
|
|
16
|
+
const result = await this.navigateTo(childGraph, target, i === children.length - 1);
|
|
17
|
+
return [true, null, result];
|
|
18
|
+
}
|
|
19
|
+
const popResult = await this.popToIfNeeded(childGraph, i === children.length - 1);
|
|
20
|
+
if (!popResult.ok) {
|
|
21
|
+
return [true, null, popResult];
|
|
18
22
|
}
|
|
19
|
-
await this.popToIfNeeded(childGraph, i === children.length - 1);
|
|
20
23
|
return [true, childGraph];
|
|
21
24
|
}
|
|
22
25
|
}
|
|
@@ -24,55 +27,81 @@ export class StackRouteHandler {
|
|
|
24
27
|
}
|
|
25
28
|
async popToIfNeeded(childGraph, isLastChildAtStack) {
|
|
26
29
|
if (!isLastChildAtStack) {
|
|
27
|
-
await Navigation.dispatch(childGraph.sceneId, 'popTo', {
|
|
30
|
+
return await Navigation.dispatch(childGraph.sceneId, 'popTo', {
|
|
28
31
|
moduleName: childGraph.sceneId,
|
|
29
32
|
});
|
|
30
33
|
}
|
|
34
|
+
return { ok: true, code: 'ok' };
|
|
31
35
|
}
|
|
32
|
-
navigateTo(childGraph, target) {
|
|
33
|
-
const { moduleName, dependencies, props } = target;
|
|
36
|
+
async navigateTo(childGraph, target, isLastChildAtStack) {
|
|
37
|
+
const { moduleName, dependencies, props, options } = target;
|
|
34
38
|
const expectations = [...dependencies, moduleName];
|
|
35
39
|
const index = expectations.findIndex(name => name === childGraph.moduleName);
|
|
36
40
|
const pendings = expectations.slice(index + 1);
|
|
37
|
-
console.log('pendings', pendings, 'moduleName', childGraph.moduleName);
|
|
38
41
|
const sceneId = childGraph.sceneId;
|
|
39
42
|
const moduleExisting = pendings.length === 0;
|
|
40
43
|
if (moduleExisting) {
|
|
41
|
-
|
|
42
|
-
|
|
44
|
+
const hasProps = props && Object.keys(props).length > 0;
|
|
45
|
+
const hasOptions = options && Object.keys(options).length > 0;
|
|
46
|
+
if (!hasProps && !hasOptions) {
|
|
47
|
+
if (!isLastChildAtStack) {
|
|
48
|
+
return await Navigation.dispatch(sceneId, 'popTo', {
|
|
49
|
+
moduleName,
|
|
50
|
+
from: childGraph.moduleName,
|
|
51
|
+
to: moduleName,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
return { ok: true, code: 'ok' };
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
return await Navigation.dispatch(sceneId, 'redirectTo', {
|
|
43
58
|
moduleName,
|
|
44
59
|
from: childGraph.moduleName,
|
|
45
60
|
to: moduleName,
|
|
61
|
+
props,
|
|
62
|
+
options,
|
|
46
63
|
});
|
|
47
64
|
}
|
|
48
|
-
|
|
49
|
-
|
|
65
|
+
}
|
|
66
|
+
const popResult = await this.popToIfNeeded(childGraph, isLastChildAtStack);
|
|
67
|
+
if (!popResult.ok) {
|
|
68
|
+
return popResult;
|
|
69
|
+
}
|
|
70
|
+
const finalAction = target.mode === 'present'
|
|
71
|
+
? 'present'
|
|
72
|
+
: target.mode === 'modal'
|
|
73
|
+
? 'showModal'
|
|
74
|
+
: 'push';
|
|
75
|
+
let currentSceneId = sceneId;
|
|
76
|
+
let fromModule = childGraph.moduleName;
|
|
77
|
+
let lastResult = { ok: true, code: 'ok' };
|
|
78
|
+
for (let i = 0; i < pendings.length; i++) {
|
|
79
|
+
const isLast = i === pendings.length - 1;
|
|
80
|
+
const targetModule = isLast ? moduleName : pendings[i];
|
|
81
|
+
lastResult = isLast
|
|
82
|
+
? await Navigation.dispatch(currentSceneId, finalAction, {
|
|
50
83
|
moduleName,
|
|
51
|
-
from:
|
|
84
|
+
from: fromModule,
|
|
52
85
|
to: moduleName,
|
|
53
86
|
props,
|
|
87
|
+
options,
|
|
88
|
+
})
|
|
89
|
+
: await Navigation.dispatch(currentSceneId, 'push', {
|
|
90
|
+
moduleName: targetModule,
|
|
91
|
+
from: fromModule,
|
|
92
|
+
to: targetModule,
|
|
54
93
|
});
|
|
94
|
+
if (!lastResult.ok) {
|
|
95
|
+
return lastResult;
|
|
55
96
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
Navigation.dispatch(sceneId, 'push', {
|
|
62
|
-
moduleName,
|
|
63
|
-
from: childGraph.moduleName,
|
|
64
|
-
to: moduleName,
|
|
65
|
-
props,
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
Navigation.dispatch(sceneId, 'push', {
|
|
70
|
-
moduleName: pendings[i],
|
|
71
|
-
from: childGraph.moduleName,
|
|
72
|
-
to: pendings[i],
|
|
73
|
-
});
|
|
97
|
+
fromModule = targetModule;
|
|
98
|
+
if (!isLast) {
|
|
99
|
+
const current = await Navigation.currentRoute();
|
|
100
|
+
if (current?.sceneId) {
|
|
101
|
+
currentSceneId = current.sceneId;
|
|
74
102
|
}
|
|
75
103
|
}
|
|
76
104
|
}
|
|
105
|
+
return lastResult;
|
|
77
106
|
}
|
|
78
107
|
}
|
package/dist/router/tabs.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LayoutMode, RouteGraph, RouteHandler, RouteInfo } from '../Route';
|
|
1
|
+
import { LayoutMode, RouteGraph, RouteHandler, RouteHandleResult, RouteInfo } from '../Route';
|
|
2
2
|
export interface TabsGraph extends RouteGraph {
|
|
3
3
|
layout: 'tabs';
|
|
4
4
|
sceneId: string;
|
|
@@ -8,5 +8,5 @@ export interface TabsGraph extends RouteGraph {
|
|
|
8
8
|
}
|
|
9
9
|
export declare function isTabsGraph(graph: RouteGraph): graph is TabsGraph;
|
|
10
10
|
export declare class TabsRouteHandler implements RouteHandler {
|
|
11
|
-
process(graph: RouteGraph, target: RouteInfo): Promise<
|
|
11
|
+
process(graph: RouteGraph, target: RouteInfo): Promise<RouteHandleResult>;
|
|
12
12
|
}
|
package/dist/router/tabs.js
CHANGED
|
@@ -12,11 +12,14 @@ export class TabsRouteHandler {
|
|
|
12
12
|
for (let i = 0; i < children.length; i++) {
|
|
13
13
|
if (isTargetLocateIn(children[i], target)) {
|
|
14
14
|
if (selectedIndex !== i) {
|
|
15
|
-
await Navigation.dispatch(children[selectedIndex].sceneId, 'switchTab', {
|
|
15
|
+
const result = await Navigation.dispatch(children[selectedIndex].sceneId, 'switchTab', {
|
|
16
16
|
from: selectedIndex,
|
|
17
17
|
to: i,
|
|
18
18
|
popToRoot: true,
|
|
19
19
|
});
|
|
20
|
+
if (!result.ok) {
|
|
21
|
+
return [true, null, result];
|
|
22
|
+
}
|
|
20
23
|
}
|
|
21
24
|
return [true, children[i]];
|
|
22
25
|
}
|
package/dist/store.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Navigator } from './Navigator';
|
|
1
|
+
import type { Navigator } from './Navigator';
|
|
2
2
|
declare function addNavigator(sceneId: string, navigator: Navigator): void;
|
|
3
3
|
declare function removeNavigator(sceneId: string): void;
|
|
4
|
-
declare function getNavigator(sceneId: string): Navigator | undefined;
|
|
4
|
+
declare function getNavigator(sceneId: string): Navigator<string> | undefined;
|
|
5
5
|
declare const _default: {
|
|
6
6
|
addNavigator: typeof addNavigator;
|
|
7
7
|
removeNavigator: typeof removeNavigator;
|