hybrid-navigation 2.13.0 → 2.13.3
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 +4 -4
- package/android/build.gradle +1 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/Garden.java +1 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/GardenModule.java +1 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/GlobalStyle.java +1 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/HBDReactRootView.java +1 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/NavigationModule.java +10 -11
- package/android/src/main/java/com/reactnative/hybridnavigation/NavigatorRegistry.java +0 -2
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactAppCompatActivity.java +32 -64
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactAppCompatActivityDelegate.java +1 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactBridgeManager.java +8 -8
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactFragment.java +1 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactFrameLayout.java +1 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarProvider.java +1 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/Utils.java +1 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/ScreenNavigator.java +1 -2
- package/ios/HybridNavigation/HBDUtils.m +3 -3
- package/ios/HybridNavigation/Navigator/HBDNavigatorRegistry.m +2 -2
- package/ios/HybridNavigation/ReactBridge/HBDGardenModule.m +8 -8
- package/ios/HybridNavigation/ReactBridge/HBDNavigationModule.m +22 -15
- package/ios/HybridNavigation/ReactBridge/HBDReactBridgeManager.h +2 -3
- package/ios/HybridNavigation/ReactBridge/HBDReactBridgeManager.m +35 -29
- package/ios/HybridNavigation/ViewController/HBDNavigationController.m +2 -2
- package/ios/HybridNavigation/ViewController/HBDViewController.m +1 -1
- package/ios/HybridNavigation/ViewController/UIViewController+HBD.m +1 -1
- package/lib/Event.d.ts +0 -2
- package/lib/Event.js +0 -9
- package/lib/Garden.d.ts +3 -0
- package/lib/Garden.js +3 -0
- package/lib/GardenModule.d.ts +4 -0
- package/lib/GardenModule.js +19 -1
- package/lib/Navigation.d.ts +4 -10
- package/lib/Navigation.js +8 -28
- package/lib/NavigationComponentWrap.d.ts +1 -1
- package/lib/NavigationModule.d.ts +1 -1
- package/lib/NavigationModule.js +6 -2
- package/lib/Navigator.d.ts +5 -2
- package/lib/Navigator.js +35 -15
- package/lib/ReactRegistry.d.ts +3 -0
- package/lib/ReactRegistry.js +3 -0
- package/lib/Route.d.ts +13 -8
- package/lib/handler/DispatchCommandHandler.d.ts +2 -0
- package/lib/handler/LayoutCommandHandler.d.ts +1 -3
- package/lib/handler/LayoutCommandHandler.js +2 -19
- package/lib/hooks.d.ts +4 -0
- package/lib/hooks.js +4 -0
- package/lib/index.d.ts +2 -5
- package/lib/index.js +3 -11
- package/lib/router/drawer.d.ts +3 -1
- package/lib/router/drawer.js +17 -17
- package/lib/router/index.d.ts +19 -15
- package/lib/router/index.js +137 -125
- package/lib/router/screen.d.ts +5 -1
- package/lib/router/screen.js +29 -0
- package/lib/router/stack.d.ts +5 -1
- package/lib/router/stack.js +59 -46
- package/lib/router/tabs.d.ts +3 -1
- package/lib/router/tabs.js +18 -28
- package/package.json +1 -1
- package/src/Event.ts +0 -11
- package/src/Garden.ts +4 -0
- package/src/GardenModule.ts +27 -1
- package/src/Navigation.ts +12 -37
- package/src/NavigationComponentWrap.tsx +1 -3
- package/src/NavigationModule.ts +7 -3
- package/src/Navigator.ts +36 -16
- package/src/ReactRegistry.tsx +3 -0
- package/src/Route.ts +14 -9
- package/src/handler/DispatchCommandHandler.ts +2 -0
- package/src/handler/LayoutCommandHandler.ts +2 -22
- package/src/hooks.ts +4 -1
- package/src/index.ts +3 -29
- package/src/router/drawer.ts +20 -17
- package/src/router/index.ts +145 -131
- package/src/router/screen.ts +34 -1
- package/src/router/stack.ts +61 -48
- package/src/router/tabs.ts +19 -29
|
@@ -2,10 +2,8 @@ import { BuildInLayout, Layout } from '../Route';
|
|
|
2
2
|
export default class LayoutCommandHandler {
|
|
3
3
|
private willSetRoot;
|
|
4
4
|
private didSetRoot;
|
|
5
|
-
private canInvokeWillSetRoot;
|
|
6
|
-
private tagGenerator;
|
|
7
5
|
constructor();
|
|
8
6
|
handleRootLayoutChange(): void;
|
|
9
|
-
setRoot(layout: BuildInLayout | Layout, sticky?: boolean): Promise<
|
|
7
|
+
setRoot(layout: BuildInLayout | Layout, sticky?: boolean): Promise<boolean>;
|
|
10
8
|
setRootLayoutUpdateListener(willSetRoot?: () => void, didSetRoot?: () => void): void;
|
|
11
9
|
}
|
|
@@ -3,34 +3,17 @@ import NavigationModule from '../NavigationModule';
|
|
|
3
3
|
export default class LayoutCommandHandler {
|
|
4
4
|
willSetRoot = () => { };
|
|
5
5
|
didSetRoot = () => { };
|
|
6
|
-
canInvokeWillSetRoot = true;
|
|
7
|
-
tagGenerator = 0;
|
|
8
6
|
constructor() { }
|
|
9
7
|
handleRootLayoutChange() {
|
|
10
8
|
Event.listenWillSetRoot(() => {
|
|
11
|
-
|
|
12
|
-
this.willSetRoot();
|
|
13
|
-
}
|
|
9
|
+
this.willSetRoot();
|
|
14
10
|
});
|
|
15
11
|
Event.listenDidSetRoot(() => {
|
|
16
12
|
this.didSetRoot();
|
|
17
|
-
this.canInvokeWillSetRoot = true;
|
|
18
13
|
});
|
|
19
14
|
}
|
|
20
15
|
setRoot(layout, sticky = false) {
|
|
21
|
-
|
|
22
|
-
this.canInvokeWillSetRoot = false;
|
|
23
|
-
const flag = this.tagGenerator++;
|
|
24
|
-
NavigationModule.setRoot(layout, sticky, flag);
|
|
25
|
-
return new Promise(resolve => {
|
|
26
|
-
const subscription = Event.listenDidSetRoot((tag) => {
|
|
27
|
-
// FIXME: 此处恐有内存泄漏
|
|
28
|
-
if (tag === flag) {
|
|
29
|
-
subscription.remove();
|
|
30
|
-
resolve();
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
});
|
|
16
|
+
return NavigationModule.setRoot(layout, sticky);
|
|
34
17
|
}
|
|
35
18
|
setRootLayoutUpdateListener(willSetRoot = () => { }, didSetRoot = () => { }) {
|
|
36
19
|
this.willSetRoot = willSetRoot;
|
package/lib/hooks.d.ts
CHANGED
|
@@ -4,4 +4,8 @@ export declare function useVisible(): boolean;
|
|
|
4
4
|
export declare function useVisibility(): "visible" | "invisible" | "pending";
|
|
5
5
|
export declare function useVisibleEffect(effect: React.EffectCallback): void;
|
|
6
6
|
export declare function useNavigator(): Navigator;
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated Use Navigation related methods instead.
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
7
11
|
export declare function useGarden(): import("./Garden").Garden;
|
package/lib/hooks.js
CHANGED
|
@@ -42,6 +42,10 @@ export function useVisibleEffect(effect) {
|
|
|
42
42
|
export function useNavigator() {
|
|
43
43
|
return useContext(NavigationContext);
|
|
44
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* @deprecated Use Navigation related methods instead.
|
|
47
|
+
* @returns
|
|
48
|
+
*/
|
|
45
49
|
export function useGarden() {
|
|
46
50
|
const ctx = useContext(NavigationContext);
|
|
47
51
|
return ctx.garden;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import { withNavigationItem, NavigationProps, InjectedProps } from './NavigationComponentWrap';
|
|
2
1
|
import Navigation from './Navigation';
|
|
3
|
-
declare function statusBarHeight(): number;
|
|
4
|
-
declare function toolbarHeight(): number;
|
|
5
|
-
declare function topBarHeight(): number;
|
|
6
2
|
export default Navigation;
|
|
7
3
|
export { RESULT_OK, RESULT_CANCEL } from './Navigation';
|
|
8
|
-
export {
|
|
4
|
+
export { statusBarHeight, toolbarHeight, topBarHeight } from './GardenModule';
|
|
5
|
+
export { withNavigationItem, NavigationProps, InjectedProps } from './NavigationComponentWrap';
|
|
9
6
|
export * from './Navigator';
|
|
10
7
|
export * from './Garden';
|
|
11
8
|
export * from './ReactRegistry';
|
package/lib/index.js
CHANGED
|
@@ -1,18 +1,10 @@
|
|
|
1
|
-
import { withNavigation
|
|
1
|
+
import { withNavigation } from './NavigationComponentWrap';
|
|
2
2
|
import Navigation from './Navigation';
|
|
3
3
|
Navigation.setNavigationComponentWrap(withNavigation);
|
|
4
|
-
function statusBarHeight() {
|
|
5
|
-
return Navigation.statusBarHeight();
|
|
6
|
-
}
|
|
7
|
-
function toolbarHeight() {
|
|
8
|
-
return Navigation.toolbarHeight();
|
|
9
|
-
}
|
|
10
|
-
function topBarHeight() {
|
|
11
|
-
return Navigation.topBarHeight();
|
|
12
|
-
}
|
|
13
4
|
export default Navigation;
|
|
14
5
|
export { RESULT_OK, RESULT_CANCEL } from './Navigation';
|
|
15
|
-
export {
|
|
6
|
+
export { statusBarHeight, toolbarHeight, topBarHeight } from './GardenModule';
|
|
7
|
+
export { withNavigationItem } from './NavigationComponentWrap';
|
|
16
8
|
export * from './Navigator';
|
|
17
9
|
export * from './Garden';
|
|
18
10
|
export * from './ReactRegistry';
|
package/lib/router/drawer.d.ts
CHANGED
|
@@ -7,4 +7,6 @@ export interface DrawerGraph extends RouteGraph {
|
|
|
7
7
|
children: [RouteGraph, ScreenGraph];
|
|
8
8
|
}
|
|
9
9
|
export declare function isDrawerGraph(graph: RouteGraph): graph is DrawerGraph;
|
|
10
|
-
export declare
|
|
10
|
+
export declare class DrawerRouteHandler implements RouteHandler {
|
|
11
|
+
process(graph: RouteGraph, target: RouteInfo): Promise<[boolean, RouteGraph | null]>;
|
|
12
|
+
}
|
package/lib/router/drawer.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isTargetLocateIn } from './screen';
|
|
2
|
+
import Navigation from '../Navigation';
|
|
2
3
|
export function isDrawerGraph(graph) {
|
|
3
4
|
return graph.layout === 'drawer';
|
|
4
5
|
}
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
navigator.closeMenu();
|
|
6
|
+
export class DrawerRouteHandler {
|
|
7
|
+
async process(graph, target) {
|
|
8
|
+
if (!isDrawerGraph(graph)) {
|
|
9
|
+
throw new Error(`${graph} is Not a DrawerGraph`);
|
|
10
|
+
}
|
|
11
|
+
const { children } = graph;
|
|
12
|
+
const { moduleName, sceneId } = children[1];
|
|
13
|
+
if (moduleName === target.moduleName) {
|
|
14
|
+
await Navigation.dispatch(sceneId, 'openMenu');
|
|
15
|
+
return [true, null];
|
|
16
|
+
}
|
|
17
|
+
if (isTargetLocateIn(children[0], target)) {
|
|
18
|
+
Navigation.dispatch(sceneId, 'closeMenu', { from: moduleName });
|
|
19
|
+
return [true, children[0]];
|
|
20
20
|
}
|
|
21
|
-
return
|
|
21
|
+
return [false, graph];
|
|
22
22
|
}
|
|
23
23
|
}
|
package/lib/router/index.d.ts
CHANGED
|
@@ -1,19 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RouteHandler, RouteInterceptor } from '../Route';
|
|
2
2
|
import { NavigationItem } from '../Options';
|
|
3
|
-
declare
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
3
|
+
declare class Router {
|
|
4
|
+
constructor();
|
|
5
|
+
private handlers;
|
|
6
|
+
registerRouteHandler(layout: string, handler: RouteHandler): void;
|
|
7
|
+
private convertConfigToData;
|
|
8
|
+
private isRouteConfigInflated;
|
|
9
|
+
private routeDatas;
|
|
10
|
+
private inflateRouteData;
|
|
11
|
+
private interceptors;
|
|
12
|
+
addInterceptor(interceptor: RouteInterceptor): void;
|
|
13
|
+
removeInterceptor(interceptor: RouteInterceptor): void;
|
|
14
|
+
private intercept;
|
|
15
|
+
private pathToRoute;
|
|
16
|
+
private routeDependencies;
|
|
17
|
+
private processRoute;
|
|
18
|
+
open(path: string, props?: object, options?: NavigationItem): Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
export declare const router: Router;
|
|
17
21
|
export * from './drawer';
|
|
18
22
|
export * from './screen';
|
|
19
23
|
export * from './stack';
|
package/lib/router/index.js
CHANGED
|
@@ -1,154 +1,166 @@
|
|
|
1
1
|
import { pathToRegexp, match } from 'path-to-regexp';
|
|
2
|
-
import { stackRouteHandler } from './stack';
|
|
3
|
-
import { tabsRouteHandler } from './tabs';
|
|
4
|
-
import { drawerRouteHandler } from './drawer';
|
|
5
|
-
import { Navigator } from '../Navigator';
|
|
6
2
|
import Navigation from '../Navigation';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
return
|
|
17
|
-
};
|
|
18
|
-
function addInterceptor(func) {
|
|
19
|
-
interceptors.add(func);
|
|
20
|
-
}
|
|
21
|
-
function removeInterceptor(func) {
|
|
22
|
-
interceptors.delete(func);
|
|
23
|
-
}
|
|
24
|
-
function use(handler) {
|
|
25
|
-
handlers.add(handler);
|
|
3
|
+
import { StackRouteHandler } from './stack';
|
|
4
|
+
import { ScreenRouteHandler } from './screen';
|
|
5
|
+
import { TabsRouteHandler } from './tabs';
|
|
6
|
+
import { DrawerRouteHandler } from './drawer';
|
|
7
|
+
function pathParams(path) {
|
|
8
|
+
const pathMatch = match(path, {
|
|
9
|
+
encode: encodeURI,
|
|
10
|
+
decode: decodeURIComponent,
|
|
11
|
+
})(path);
|
|
12
|
+
return pathMatch ? pathMatch.params : {};
|
|
26
13
|
}
|
|
27
|
-
function
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
14
|
+
function queryParams(queryString) {
|
|
15
|
+
return (queryString || '').split('&').reduce((result, item) => {
|
|
16
|
+
if (item !== '') {
|
|
17
|
+
const nextResult = result || {};
|
|
18
|
+
const [key, value] = item.split('=');
|
|
19
|
+
nextResult[key] = value;
|
|
20
|
+
return nextResult;
|
|
33
21
|
}
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
mode = mode || 'push';
|
|
37
|
-
routeDatas.set(moduleName, { moduleName, mode, path, regexp, dependency });
|
|
22
|
+
return result;
|
|
23
|
+
}, {});
|
|
38
24
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
25
|
+
class Router {
|
|
26
|
+
constructor() {
|
|
27
|
+
this.registerRouteHandler('screen', new ScreenRouteHandler());
|
|
28
|
+
this.registerRouteHandler('stack', new StackRouteHandler());
|
|
29
|
+
this.registerRouteHandler('tabs', new TabsRouteHandler());
|
|
30
|
+
this.registerRouteHandler('drawer', new DrawerRouteHandler());
|
|
44
31
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
inflateRouteConfigs();
|
|
49
|
-
isRouteConfigInflated = true;
|
|
32
|
+
handlers = new Map();
|
|
33
|
+
registerRouteHandler(layout, handler) {
|
|
34
|
+
this.handlers.set(layout, handler);
|
|
50
35
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
36
|
+
convertConfigToData(moduleName, route) {
|
|
37
|
+
let { path, dependency, mode } = route;
|
|
38
|
+
let regexp;
|
|
39
|
+
if (path) {
|
|
40
|
+
if (!path.startsWith('/')) {
|
|
41
|
+
route.path = '/' + route.path;
|
|
42
|
+
}
|
|
43
|
+
regexp = pathToRegexp(path);
|
|
59
44
|
}
|
|
60
|
-
|
|
45
|
+
mode = mode || 'push';
|
|
46
|
+
return { moduleName, mode, path, regexp, dependency };
|
|
47
|
+
}
|
|
48
|
+
isRouteConfigInflated = false;
|
|
49
|
+
routeDatas = new Map();
|
|
50
|
+
inflateRouteData() {
|
|
51
|
+
if (this.isRouteConfigInflated) {
|
|
61
52
|
return;
|
|
62
53
|
}
|
|
54
|
+
this.isRouteConfigInflated = true;
|
|
55
|
+
const routeConfigs = Navigation.routeConfigs();
|
|
56
|
+
for (const [moduleName, config] of routeConfigs) {
|
|
57
|
+
const data = this.convertConfigToData(moduleName, config);
|
|
58
|
+
this.routeDatas.set(moduleName, data);
|
|
59
|
+
}
|
|
63
60
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
61
|
+
interceptors = [];
|
|
62
|
+
addInterceptor(interceptor) {
|
|
63
|
+
this.interceptors.push(interceptor);
|
|
67
64
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
65
|
+
removeInterceptor(interceptor) {
|
|
66
|
+
this.interceptors = this.interceptors.filter(item => item !== interceptor);
|
|
67
|
+
}
|
|
68
|
+
async intercept(path) {
|
|
69
|
+
for (let interceptor of this.interceptors.values()) {
|
|
70
|
+
const result = interceptor(path);
|
|
71
|
+
if (result instanceof Promise) {
|
|
72
|
+
return await result;
|
|
75
73
|
}
|
|
76
|
-
|
|
77
|
-
|
|
74
|
+
return result;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
pathToRoute(path, props, options) {
|
|
78
|
+
for (const data of this.routeDatas.values()) {
|
|
79
|
+
if (!data.regexp) {
|
|
80
|
+
continue;
|
|
78
81
|
}
|
|
79
|
-
|
|
80
|
-
|
|
82
|
+
const [pathName, queryString] = path.split('?');
|
|
83
|
+
if (data.regexp.exec(pathName)) {
|
|
84
|
+
const moduleName = data.moduleName;
|
|
85
|
+
const params = pathParams(pathName);
|
|
86
|
+
const query = queryParams(queryString);
|
|
87
|
+
props = { ...query, ...params, ...props };
|
|
88
|
+
const dependencies = this.routeDependencies(data);
|
|
89
|
+
const mode = data.mode;
|
|
90
|
+
return { moduleName, props, dependencies, mode, options };
|
|
81
91
|
}
|
|
82
92
|
}
|
|
83
93
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
94
|
+
routeDependencies(routeData) {
|
|
95
|
+
let dependencies = [];
|
|
96
|
+
let data = routeData;
|
|
97
|
+
while (data && data.dependency) {
|
|
98
|
+
dependencies.push(data.dependency);
|
|
99
|
+
data = this.routeDatas.get(data.dependency);
|
|
90
100
|
}
|
|
91
|
-
|
|
92
|
-
|
|
101
|
+
return dependencies.reverse();
|
|
102
|
+
}
|
|
103
|
+
async processRoute(route, graph) {
|
|
104
|
+
const handler = this.handlers.get(graph.layout);
|
|
105
|
+
if (!handler) {
|
|
106
|
+
return false;
|
|
93
107
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
108
|
+
const [consumed, childGraph] = await handler.process(graph, route);
|
|
109
|
+
if (consumed && childGraph) {
|
|
110
|
+
return await this.processRoute(route, childGraph);
|
|
97
111
|
}
|
|
112
|
+
return consumed;
|
|
98
113
|
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
if (
|
|
103
|
-
|
|
114
|
+
async open(path, props = {}, options = {}) {
|
|
115
|
+
this.inflateRouteData();
|
|
116
|
+
const intercepted = await this.intercept(path);
|
|
117
|
+
if (intercepted) {
|
|
118
|
+
return;
|
|
104
119
|
}
|
|
105
|
-
const
|
|
106
|
-
if (
|
|
107
|
-
|
|
108
|
-
const params = pathParams(pathName);
|
|
109
|
-
const query = queryParams(queryString);
|
|
110
|
-
props = { ...query, ...params, ...props };
|
|
111
|
-
const dependencies = routeDependencies(data);
|
|
112
|
-
const mode = data.mode;
|
|
113
|
-
return { moduleName, props, dependencies, mode, options };
|
|
120
|
+
const route = this.pathToRoute(path, props, options);
|
|
121
|
+
if (!route) {
|
|
122
|
+
return;
|
|
114
123
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
return nextResult;
|
|
124
|
+
const graphArray = await Navigation.routeGraph();
|
|
125
|
+
if (graphArray.length > 1) {
|
|
126
|
+
for (let index = graphArray.length - 1; index > 0; index--) {
|
|
127
|
+
const { mode: layoutMode } = graphArray[index];
|
|
128
|
+
const { sceneId, moduleName } = await Navigation.currentRoute();
|
|
129
|
+
if (layoutMode === 'present') {
|
|
130
|
+
await Navigation.dispatch(sceneId, 'dismiss', { from: moduleName });
|
|
131
|
+
}
|
|
132
|
+
else if (layoutMode === 'modal') {
|
|
133
|
+
await Navigation.dispatch(sceneId, 'hideModal', { from: moduleName });
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
console.warn('尚未处理的 layout mode:' + layoutMode);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
131
139
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
140
|
+
const routeGraph = graphArray[0];
|
|
141
|
+
const consumed = await this.processRoute(route, routeGraph);
|
|
142
|
+
if (consumed) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
const { sceneId, moduleName: from } = await Navigation.currentRoute();
|
|
146
|
+
Navigation.dispatch(sceneId, 'closeMenu', { from });
|
|
147
|
+
const { moduleName, mode: routeMode, props: initialProps } = route;
|
|
148
|
+
let action = 'push';
|
|
149
|
+
if (routeMode === 'present') {
|
|
150
|
+
action = 'present';
|
|
151
|
+
}
|
|
152
|
+
else if (routeMode === 'modal') {
|
|
153
|
+
action = 'showModal';
|
|
154
|
+
}
|
|
155
|
+
Navigation.dispatch(sceneId, action, {
|
|
156
|
+
moduleName,
|
|
157
|
+
props: initialProps,
|
|
158
|
+
from,
|
|
159
|
+
to: moduleName,
|
|
160
|
+
});
|
|
141
161
|
}
|
|
142
|
-
return dependencies.reverse();
|
|
143
162
|
}
|
|
144
|
-
export const router =
|
|
145
|
-
addInterceptor,
|
|
146
|
-
removeInterceptor,
|
|
147
|
-
registerRoute,
|
|
148
|
-
use,
|
|
149
|
-
open,
|
|
150
|
-
pathToRoute,
|
|
151
|
-
};
|
|
163
|
+
export const router = new Router();
|
|
152
164
|
export * from './drawer';
|
|
153
165
|
export * from './screen';
|
|
154
166
|
export * from './stack';
|
package/lib/router/screen.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LayoutMode, RouteGraph } from '../Route';
|
|
1
|
+
import { LayoutMode, RouteGraph, RouteHandler, RouteInfo } from '../Route';
|
|
2
2
|
export interface ScreenGraph extends RouteGraph {
|
|
3
3
|
layout: 'screen';
|
|
4
4
|
sceneId: string;
|
|
@@ -6,3 +6,7 @@ export interface ScreenGraph extends RouteGraph {
|
|
|
6
6
|
moduleName: string;
|
|
7
7
|
}
|
|
8
8
|
export declare function isScreenGraph(graph: RouteGraph): graph is ScreenGraph;
|
|
9
|
+
export declare function isTargetLocateIn(graph: RouteGraph, target: RouteInfo): boolean;
|
|
10
|
+
export declare class ScreenRouteHandler implements RouteHandler {
|
|
11
|
+
process(graph: RouteGraph, target: RouteInfo): Promise<[boolean, RouteGraph | null]>;
|
|
12
|
+
}
|
package/lib/router/screen.js
CHANGED
|
@@ -1,3 +1,32 @@
|
|
|
1
1
|
export function isScreenGraph(graph) {
|
|
2
2
|
return graph.layout === 'screen';
|
|
3
3
|
}
|
|
4
|
+
function extractModuleNames(graph, set) {
|
|
5
|
+
if (isScreenGraph(graph)) {
|
|
6
|
+
set.push(graph.moduleName);
|
|
7
|
+
}
|
|
8
|
+
else {
|
|
9
|
+
const children = graph.children;
|
|
10
|
+
for (let i = 0; i < children.length; i++) {
|
|
11
|
+
extractModuleNames(children[i], set);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export function isTargetLocateIn(graph, target) {
|
|
16
|
+
const existings = [];
|
|
17
|
+
extractModuleNames(graph, existings);
|
|
18
|
+
const { dependencies, moduleName } = target;
|
|
19
|
+
const expectations = [...dependencies, moduleName];
|
|
20
|
+
return expectations.some(name => existings.includes(name));
|
|
21
|
+
}
|
|
22
|
+
export class ScreenRouteHandler {
|
|
23
|
+
process(graph, target) {
|
|
24
|
+
if (!isScreenGraph(graph)) {
|
|
25
|
+
throw new Error(`${graph} is Not a ScreenGraph`);
|
|
26
|
+
}
|
|
27
|
+
if (graph.moduleName === target.moduleName) {
|
|
28
|
+
return Promise.resolve([true, null]);
|
|
29
|
+
}
|
|
30
|
+
return Promise.resolve([false, graph]);
|
|
31
|
+
}
|
|
32
|
+
}
|
package/lib/router/stack.d.ts
CHANGED
|
@@ -6,4 +6,8 @@ export interface StackGraph extends RouteGraph {
|
|
|
6
6
|
children: RouteGraph[];
|
|
7
7
|
}
|
|
8
8
|
export declare function isStackGraph(graph: RouteGraph): graph is StackGraph;
|
|
9
|
-
export declare
|
|
9
|
+
export declare class StackRouteHandler implements RouteHandler {
|
|
10
|
+
process(graph: RouteGraph, target: RouteInfo): Promise<[boolean, RouteGraph | null]>;
|
|
11
|
+
private popToIfNeeded;
|
|
12
|
+
private navigateTo;
|
|
13
|
+
}
|