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.
Files changed (77) hide show
  1. package/README.md +4 -4
  2. package/android/build.gradle +1 -1
  3. package/android/src/main/java/com/reactnative/hybridnavigation/Garden.java +1 -1
  4. package/android/src/main/java/com/reactnative/hybridnavigation/GardenModule.java +1 -1
  5. package/android/src/main/java/com/reactnative/hybridnavigation/GlobalStyle.java +1 -1
  6. package/android/src/main/java/com/reactnative/hybridnavigation/HBDReactRootView.java +1 -1
  7. package/android/src/main/java/com/reactnative/hybridnavigation/NavigationModule.java +10 -11
  8. package/android/src/main/java/com/reactnative/hybridnavigation/NavigatorRegistry.java +0 -2
  9. package/android/src/main/java/com/reactnative/hybridnavigation/ReactAppCompatActivity.java +32 -64
  10. package/android/src/main/java/com/reactnative/hybridnavigation/ReactAppCompatActivityDelegate.java +1 -1
  11. package/android/src/main/java/com/reactnative/hybridnavigation/ReactBridgeManager.java +8 -8
  12. package/android/src/main/java/com/reactnative/hybridnavigation/ReactFragment.java +1 -1
  13. package/android/src/main/java/com/reactnative/hybridnavigation/ReactFrameLayout.java +1 -1
  14. package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarProvider.java +1 -1
  15. package/android/src/main/java/com/reactnative/hybridnavigation/Utils.java +1 -1
  16. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/ScreenNavigator.java +1 -2
  17. package/ios/HybridNavigation/HBDUtils.m +3 -3
  18. package/ios/HybridNavigation/Navigator/HBDNavigatorRegistry.m +2 -2
  19. package/ios/HybridNavigation/ReactBridge/HBDGardenModule.m +8 -8
  20. package/ios/HybridNavigation/ReactBridge/HBDNavigationModule.m +22 -15
  21. package/ios/HybridNavigation/ReactBridge/HBDReactBridgeManager.h +2 -3
  22. package/ios/HybridNavigation/ReactBridge/HBDReactBridgeManager.m +35 -29
  23. package/ios/HybridNavigation/ViewController/HBDNavigationController.m +2 -2
  24. package/ios/HybridNavigation/ViewController/HBDViewController.m +1 -1
  25. package/ios/HybridNavigation/ViewController/UIViewController+HBD.m +1 -1
  26. package/lib/Event.d.ts +0 -2
  27. package/lib/Event.js +0 -9
  28. package/lib/Garden.d.ts +3 -0
  29. package/lib/Garden.js +3 -0
  30. package/lib/GardenModule.d.ts +4 -0
  31. package/lib/GardenModule.js +19 -1
  32. package/lib/Navigation.d.ts +4 -10
  33. package/lib/Navigation.js +8 -28
  34. package/lib/NavigationComponentWrap.d.ts +1 -1
  35. package/lib/NavigationModule.d.ts +1 -1
  36. package/lib/NavigationModule.js +6 -2
  37. package/lib/Navigator.d.ts +5 -2
  38. package/lib/Navigator.js +35 -15
  39. package/lib/ReactRegistry.d.ts +3 -0
  40. package/lib/ReactRegistry.js +3 -0
  41. package/lib/Route.d.ts +13 -8
  42. package/lib/handler/DispatchCommandHandler.d.ts +2 -0
  43. package/lib/handler/LayoutCommandHandler.d.ts +1 -3
  44. package/lib/handler/LayoutCommandHandler.js +2 -19
  45. package/lib/hooks.d.ts +4 -0
  46. package/lib/hooks.js +4 -0
  47. package/lib/index.d.ts +2 -5
  48. package/lib/index.js +3 -11
  49. package/lib/router/drawer.d.ts +3 -1
  50. package/lib/router/drawer.js +17 -17
  51. package/lib/router/index.d.ts +19 -15
  52. package/lib/router/index.js +137 -125
  53. package/lib/router/screen.d.ts +5 -1
  54. package/lib/router/screen.js +29 -0
  55. package/lib/router/stack.d.ts +5 -1
  56. package/lib/router/stack.js +59 -46
  57. package/lib/router/tabs.d.ts +3 -1
  58. package/lib/router/tabs.js +18 -28
  59. package/package.json +1 -1
  60. package/src/Event.ts +0 -11
  61. package/src/Garden.ts +4 -0
  62. package/src/GardenModule.ts +27 -1
  63. package/src/Navigation.ts +12 -37
  64. package/src/NavigationComponentWrap.tsx +1 -3
  65. package/src/NavigationModule.ts +7 -3
  66. package/src/Navigator.ts +36 -16
  67. package/src/ReactRegistry.tsx +3 -0
  68. package/src/Route.ts +14 -9
  69. package/src/handler/DispatchCommandHandler.ts +2 -0
  70. package/src/handler/LayoutCommandHandler.ts +2 -22
  71. package/src/hooks.ts +4 -1
  72. package/src/index.ts +3 -29
  73. package/src/router/drawer.ts +20 -17
  74. package/src/router/index.ts +145 -131
  75. package/src/router/screen.ts +34 -1
  76. package/src/router/stack.ts +61 -48
  77. 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<void>;
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
- if (this.canInvokeWillSetRoot) {
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
- this.willSetRoot();
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 { withNavigationItem, NavigationProps, InjectedProps, statusBarHeight, toolbarHeight, topBarHeight, };
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, withNavigationItem, } from './NavigationComponentWrap';
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 { withNavigationItem, statusBarHeight, toolbarHeight, topBarHeight, };
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';
@@ -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 function drawerRouteHandler(graph: RouteGraph, route: RouteInfo, next: RouteHandler): Promise<boolean>;
10
+ export declare class DrawerRouteHandler implements RouteHandler {
11
+ process(graph: RouteGraph, target: RouteInfo): Promise<[boolean, RouteGraph | null]>;
12
+ }
@@ -1,23 +1,23 @@
1
- import { Navigator } from '../Navigator';
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 async function drawerRouteHandler(graph, route, next) {
6
- if (!isDrawerGraph(graph)) {
7
- return false;
8
- }
9
- const { moduleName, sceneId } = graph.children[1];
10
- if (moduleName === route.moduleName) {
11
- const navigator = Navigator.of(sceneId);
12
- navigator.openMenu();
13
- return true;
14
- }
15
- else {
16
- let result = await next(graph.children[0], route, next);
17
- if (result) {
18
- const navigator = Navigator.of(sceneId);
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 result;
21
+ return [false, graph];
22
22
  }
23
23
  }
@@ -1,19 +1,23 @@
1
- import { RouteConfig, RouteHandler, RouteInfo, RouteInterceptor } from '../Route';
1
+ import { RouteHandler, RouteInterceptor } from '../Route';
2
2
  import { NavigationItem } from '../Options';
3
- declare function addInterceptor(func: RouteInterceptor): void;
4
- declare function removeInterceptor(func: RouteInterceptor): void;
5
- declare function use(handler: RouteHandler): void;
6
- declare function registerRoute(moduleName: string, route: RouteConfig): void;
7
- declare function open(path: string, props?: object, options?: NavigationItem): Promise<void>;
8
- declare function pathToRoute(path: string, props: object, options: NavigationItem): RouteInfo | undefined;
9
- export declare const router: {
10
- addInterceptor: typeof addInterceptor;
11
- removeInterceptor: typeof removeInterceptor;
12
- registerRoute: typeof registerRoute;
13
- use: typeof use;
14
- open: typeof open;
15
- pathToRoute: typeof pathToRoute;
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';
@@ -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
- let routeDatas = new Map();
8
- let interceptors = new Set();
9
- let handlers = new Set([drawerRouteHandler, tabsRouteHandler, stackRouteHandler]);
10
- const traverseHandlers = async (graph, route, next) => {
11
- for (let handler of handlers.values()) {
12
- if (await handler(graph, route, next)) {
13
- return true;
14
- }
15
- }
16
- return false;
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 registerRoute(moduleName, route) {
28
- let { path, dependency, mode } = route;
29
- let regexp;
30
- if (path) {
31
- if (!path.startsWith('/')) {
32
- route.path = '/' + route.path;
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
- regexp = pathToRegexp(path);
35
- }
36
- mode = mode || 'push';
37
- routeDatas.set(moduleName, { moduleName, mode, path, regexp, dependency });
22
+ return result;
23
+ }, {});
38
24
  }
39
- let isRouteConfigInflated = false;
40
- function inflateRouteConfigs() {
41
- const routeConfigs = Navigation.routeConfigs();
42
- for (const [moduleName, config] of routeConfigs) {
43
- registerRoute(moduleName, config);
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
- async function open(path, props = {}, options = {}) {
47
- if (!isRouteConfigInflated) {
48
- inflateRouteConfigs();
49
- isRouteConfigInflated = true;
32
+ handlers = new Map();
33
+ registerRouteHandler(layout, handler) {
34
+ this.handlers.set(layout, handler);
50
35
  }
51
- let intercepted = false;
52
- for (let interceptor of interceptors.values()) {
53
- const result = interceptor(path);
54
- if (result instanceof Promise) {
55
- intercepted = await result;
56
- }
57
- else {
58
- intercepted = result;
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
- if (intercepted) {
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
- const route = pathToRoute(path, props, options);
65
- if (!route) {
66
- return;
61
+ interceptors = [];
62
+ addInterceptor(interceptor) {
63
+ this.interceptors.push(interceptor);
67
64
  }
68
- const graphArray = await Navigator.routeGraph();
69
- if (graphArray.length > 1) {
70
- for (let index = graphArray.length - 1; index > 0; index--) {
71
- const { mode: layoutMode } = graphArray[index];
72
- const navigator = await Navigator.current();
73
- if (layoutMode === 'present') {
74
- await navigator.dismiss();
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
- else if (layoutMode === 'modal') {
77
- await navigator.hideModal();
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
- else {
80
- console.warn('尚未处理的 layout mode:' + layoutMode);
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
- if (!(await traverseHandlers(graphArray[0], route, traverseHandlers))) {
85
- const navigator = await Navigator.current();
86
- navigator.closeMenu();
87
- const { moduleName, mode: routeMode, props: initialProps } = route;
88
- if (routeMode === 'present') {
89
- navigator.present(moduleName, initialProps);
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
- else if (routeMode === 'modal') {
92
- navigator.showModal(moduleName, initialProps);
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
- else {
95
- // default push
96
- navigator.push(moduleName, initialProps);
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
- function pathToRoute(path, props, options) {
101
- for (const data of routeDatas.values()) {
102
- if (!data.regexp) {
103
- continue;
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 [pathName, queryString] = path.split('?');
106
- if (data.regexp.exec(pathName)) {
107
- const moduleName = data.moduleName;
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
- function pathParams(path) {
118
- const pathMatch = match(path, {
119
- encode: encodeURI,
120
- decode: decodeURIComponent,
121
- })(path);
122
- return pathMatch ? pathMatch.params : {};
123
- }
124
- function queryParams(queryString) {
125
- return (queryString || '').split('&').reduce((result, item) => {
126
- if (item !== '') {
127
- const nextResult = result || {};
128
- const [key, value] = item.split('=');
129
- nextResult[key] = value;
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
- return result;
133
- }, {});
134
- }
135
- function routeDependencies(routeData) {
136
- let dependencies = [];
137
- let data = routeData;
138
- while (data && data.dependency) {
139
- dependencies.push(data.dependency);
140
- data = routeDatas.get(data.dependency);
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';
@@ -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
+ }
@@ -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
+ }
@@ -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 function stackRouteHandler(graph: RouteGraph, route: RouteInfo, next: RouteHandler): Promise<boolean>;
9
+ export declare class StackRouteHandler implements RouteHandler {
10
+ process(graph: RouteGraph, target: RouteInfo): Promise<[boolean, RouteGraph | null]>;
11
+ private popToIfNeeded;
12
+ private navigateTo;
13
+ }