hybrid-navigation 2.13.0 → 2.13.1
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/lib/Garden.d.ts +3 -0
- package/lib/Garden.js +3 -0
- package/lib/Navigation.d.ts +3 -9
- package/lib/Navigation.js +8 -28
- package/lib/NavigationComponentWrap.d.ts +1 -1
- package/lib/Navigator.d.ts +5 -2
- package/lib/Navigator.js +25 -7
- 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/hooks.d.ts +4 -0
- package/lib/hooks.js +4 -0
- package/lib/index.d.ts +2 -2
- package/lib/index.js +16 -5
- 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/Garden.ts +4 -0
- package/src/Navigation.ts +12 -37
- package/src/NavigationComponentWrap.tsx +1 -1
- package/src/Navigator.ts +26 -8
- package/src/ReactRegistry.tsx +3 -0
- package/src/Route.ts +14 -9
- package/src/handler/DispatchCommandHandler.ts +2 -0
- package/src/hooks.ts +4 -0
- package/src/index.ts +18 -16
- package/src/router/drawer.ts +20 -17
- package/src/router/index.ts +147 -131
- package/src/router/screen.ts +34 -1
- package/src/router/stack.ts +61 -48
- package/src/router/tabs.ts +19 -29
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
|
+
}
|
package/lib/router/stack.js
CHANGED
|
@@ -1,65 +1,78 @@
|
|
|
1
|
-
import { isScreenGraph } from './screen';
|
|
2
|
-
import
|
|
1
|
+
import { isScreenGraph, isTargetLocateIn } from './screen';
|
|
2
|
+
import Navigation from '../Navigation';
|
|
3
3
|
export function isStackGraph(graph) {
|
|
4
4
|
return graph.layout === 'stack';
|
|
5
5
|
}
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
if (expectedIndex !== -1) {
|
|
23
|
-
childIndex = i;
|
|
24
|
-
break;
|
|
6
|
+
export class StackRouteHandler {
|
|
7
|
+
async process(graph, target) {
|
|
8
|
+
if (!isStackGraph(graph)) {
|
|
9
|
+
throw new Error(`${graph} is Not a StackGraph`);
|
|
10
|
+
}
|
|
11
|
+
const { children } = graph;
|
|
12
|
+
for (let i = children.length - 1; i > -1; i--) {
|
|
13
|
+
const childGraph = children[i];
|
|
14
|
+
if (isTargetLocateIn(childGraph, target)) {
|
|
15
|
+
if (isScreenGraph(childGraph)) {
|
|
16
|
+
this.navigateTo(childGraph, target);
|
|
17
|
+
return [true, null];
|
|
18
|
+
}
|
|
19
|
+
await this.popToIfNeeded(childGraph, i === children.length - 1);
|
|
20
|
+
return [true, childGraph];
|
|
21
|
+
}
|
|
25
22
|
}
|
|
23
|
+
return [false, graph];
|
|
26
24
|
}
|
|
27
|
-
|
|
28
|
-
if (!
|
|
29
|
-
await
|
|
25
|
+
async popToIfNeeded(childGraph, isLastChildAtStack) {
|
|
26
|
+
if (!isLastChildAtStack) {
|
|
27
|
+
await Navigation.dispatch(childGraph.sceneId, 'popTo', {
|
|
28
|
+
moduleName: childGraph.sceneId,
|
|
29
|
+
});
|
|
30
30
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
}
|
|
32
|
+
navigateTo(childGraph, target) {
|
|
33
|
+
const { mode, moduleName, dependencies, props } = target;
|
|
34
|
+
const expectations = [...dependencies, moduleName];
|
|
35
|
+
const index = expectations.findIndex(name => name === childGraph.moduleName);
|
|
36
|
+
const pendings = expectations.slice(index + 1);
|
|
37
|
+
console.log('pendings', pendings, 'moduleName', childGraph.moduleName);
|
|
38
|
+
const sceneId = childGraph.sceneId;
|
|
39
|
+
const moduleExisting = pendings.length === 0;
|
|
40
|
+
if (moduleExisting) {
|
|
34
41
|
if (JSON.stringify(props) === '{}') {
|
|
35
|
-
|
|
42
|
+
Navigation.dispatch(sceneId, 'popTo', {
|
|
43
|
+
moduleName,
|
|
44
|
+
from: childGraph.moduleName,
|
|
45
|
+
to: moduleName,
|
|
46
|
+
});
|
|
36
47
|
}
|
|
37
48
|
else {
|
|
38
|
-
|
|
49
|
+
Navigation.dispatch(sceneId, 'redirectTo', {
|
|
50
|
+
moduleName,
|
|
51
|
+
from: childGraph.moduleName,
|
|
52
|
+
to: moduleName,
|
|
53
|
+
props,
|
|
54
|
+
});
|
|
39
55
|
}
|
|
40
56
|
}
|
|
41
57
|
else {
|
|
42
|
-
for (let i = 0; i <
|
|
43
|
-
|
|
44
|
-
|
|
58
|
+
for (let i = 0; i < pendings.length; i++) {
|
|
59
|
+
const isLast = i === pendings.length - 1;
|
|
60
|
+
if (isLast) {
|
|
61
|
+
Navigation.dispatch(sceneId, 'push', {
|
|
62
|
+
moduleName,
|
|
63
|
+
from: childGraph.moduleName,
|
|
64
|
+
to: moduleName,
|
|
65
|
+
props,
|
|
66
|
+
});
|
|
45
67
|
}
|
|
46
68
|
else {
|
|
47
|
-
|
|
69
|
+
Navigation.dispatch(sceneId, 'push', {
|
|
70
|
+
moduleName: pendings[i],
|
|
71
|
+
from: childGraph.moduleName,
|
|
72
|
+
to: pendings[i],
|
|
73
|
+
});
|
|
48
74
|
}
|
|
49
75
|
}
|
|
50
76
|
}
|
|
51
|
-
return true;
|
|
52
|
-
}
|
|
53
|
-
return false;
|
|
54
|
-
}
|
|
55
|
-
function extractModuleNames(graph, set) {
|
|
56
|
-
if (isScreenGraph(graph)) {
|
|
57
|
-
set.push(graph.moduleName);
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
const children = graph.children;
|
|
61
|
-
for (let i = 0; i < children.length; i++) {
|
|
62
|
-
extractModuleNames(children[i], set);
|
|
63
|
-
}
|
|
64
77
|
}
|
|
65
78
|
}
|
package/lib/router/tabs.d.ts
CHANGED
|
@@ -7,4 +7,6 @@ export interface TabsGraph extends RouteGraph {
|
|
|
7
7
|
children: RouteGraph[];
|
|
8
8
|
}
|
|
9
9
|
export declare function isTabsGraph(graph: RouteGraph): graph is TabsGraph;
|
|
10
|
-
export declare
|
|
10
|
+
export declare class TabsRouteHandler implements RouteHandler {
|
|
11
|
+
process(graph: RouteGraph, target: RouteInfo): Promise<[boolean, RouteGraph]>;
|
|
12
|
+
}
|
package/lib/router/tabs.js
CHANGED
|
@@ -1,36 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import { isTargetLocateIn } from './screen';
|
|
2
|
+
import Navigation from '../Navigation';
|
|
3
3
|
export function isTabsGraph(graph) {
|
|
4
4
|
return graph.layout === 'tabs';
|
|
5
5
|
}
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const { children, selectedIndex } = graph;
|
|
11
|
-
const { dependencies, moduleName } = route;
|
|
12
|
-
const expectedModuleNames = [...dependencies, moduleName];
|
|
13
|
-
for (let i = 0; i < children.length; i++) {
|
|
14
|
-
const existingModuleNames = [];
|
|
15
|
-
extractModuleNames(children[i], existingModuleNames);
|
|
16
|
-
if (expectedModuleNames.some(name => existingModuleNames.includes(name))) {
|
|
17
|
-
if (selectedIndex !== i) {
|
|
18
|
-
const navigator = Navigator.of(children[i].sceneId);
|
|
19
|
-
await navigator.switchTab(i, true);
|
|
20
|
-
}
|
|
21
|
-
return next(children[i], route, next);
|
|
6
|
+
export class TabsRouteHandler {
|
|
7
|
+
async process(graph, target) {
|
|
8
|
+
if (!isTabsGraph(graph)) {
|
|
9
|
+
throw new Error(`${graph} is NOT a TabsGraph`);
|
|
22
10
|
}
|
|
23
|
-
|
|
24
|
-
return false;
|
|
25
|
-
}
|
|
26
|
-
function extractModuleNames(graph, set) {
|
|
27
|
-
if (isScreenGraph(graph)) {
|
|
28
|
-
set.push(graph.moduleName);
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
const children = graph.children;
|
|
11
|
+
const { children, selectedIndex } = graph;
|
|
32
12
|
for (let i = 0; i < children.length; i++) {
|
|
33
|
-
|
|
13
|
+
if (isTargetLocateIn(children[i], target)) {
|
|
14
|
+
if (selectedIndex !== i) {
|
|
15
|
+
await Navigation.dispatch(children[selectedIndex].sceneId, 'switchTab', {
|
|
16
|
+
from: selectedIndex,
|
|
17
|
+
to: i,
|
|
18
|
+
popToRoot: true,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return [true, children[i]];
|
|
22
|
+
}
|
|
34
23
|
}
|
|
24
|
+
return [false, graph];
|
|
35
25
|
}
|
|
36
26
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hybrid-navigation",
|
|
3
3
|
"description": "React Native Navigation that supports seamless navigation between Native and React.",
|
|
4
|
-
"version": "2.13.
|
|
4
|
+
"version": "2.13.1",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"typings": "./lib/index.d.ts",
|
|
7
7
|
"react-native": "src/index",
|
package/src/Garden.ts
CHANGED
|
@@ -13,6 +13,10 @@ type Nullable<T> = {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
export interface Garden {}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @deprecated use Navigation instead. import Navigation from 'hybrid-navigation'
|
|
19
|
+
*/
|
|
16
20
|
export class Garden implements Garden {
|
|
17
21
|
/**
|
|
18
22
|
* @deprecated Use Navigation.setDefaultOptions() instead.
|
package/src/Navigation.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type React from 'react'
|
|
2
|
-
import { AppRegistry, ComponentProvider
|
|
2
|
+
import { AppRegistry, ComponentProvider } from 'react-native'
|
|
3
3
|
|
|
4
4
|
import type {
|
|
5
5
|
BarButtonItem,
|
|
@@ -34,7 +34,6 @@ type Nullable<T> = {
|
|
|
34
34
|
[P in keyof T]: T[P] extends T[P] | undefined ? T[P] | null : T[P]
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
const { STATUSBAR_HEIGHT, TOOLBAR_HEIGHT } = GardenModule.getConstants()
|
|
38
37
|
export const { RESULT_CANCEL, RESULT_OK } = NavigationModule.getConstants()
|
|
39
38
|
|
|
40
39
|
export type NavigationSubscription = {
|
|
@@ -53,7 +52,6 @@ export class Navigation implements Navigation {
|
|
|
53
52
|
private visibilityHandler = new VisibilityEventHandler()
|
|
54
53
|
|
|
55
54
|
constructor() {
|
|
56
|
-
this.handleStatusBarHeightChange()
|
|
57
55
|
this.handleTabSwitch()
|
|
58
56
|
this.layoutHandler.handleRootLayoutChange()
|
|
59
57
|
this.visibilityHandler.handleComponentVisibility()
|
|
@@ -102,6 +100,16 @@ export class Navigation implements Navigation {
|
|
|
102
100
|
AppRegistry.registerComponent(appKey, () => RootComponent)
|
|
103
101
|
}
|
|
104
102
|
|
|
103
|
+
private _routeConfigs = new Map<string, RouteConfig>()
|
|
104
|
+
|
|
105
|
+
private registerRoute(moduleName: string, route: RouteConfig) {
|
|
106
|
+
this._routeConfigs.set(moduleName, route)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
routeConfigs() {
|
|
110
|
+
return this._routeConfigs
|
|
111
|
+
}
|
|
112
|
+
|
|
105
113
|
setNavigationComponentWrap(wrap: (moduleName: string) => HOC) {
|
|
106
114
|
this.wrap = wrap
|
|
107
115
|
}
|
|
@@ -142,7 +150,7 @@ export class Navigation implements Navigation {
|
|
|
142
150
|
setResult = <T extends ResultType>(
|
|
143
151
|
sceneId: string,
|
|
144
152
|
resultCode: number,
|
|
145
|
-
data: T = null as
|
|
153
|
+
data: T = null as T,
|
|
146
154
|
): void => NavigationModule.setResult(sceneId, resultCode, data)
|
|
147
155
|
|
|
148
156
|
result<T>(sceneId: string, resultCode: number) {
|
|
@@ -186,16 +194,6 @@ export class Navigation implements Navigation {
|
|
|
186
194
|
return NavigationModule.routeGraph()
|
|
187
195
|
}
|
|
188
196
|
|
|
189
|
-
private _routeConfigs = new Map<string, RouteConfig>()
|
|
190
|
-
|
|
191
|
-
private registerRoute(moduleName: string, route: RouteConfig) {
|
|
192
|
-
this._routeConfigs.set(moduleName, route)
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
routeConfigs() {
|
|
196
|
-
return this._routeConfigs
|
|
197
|
-
}
|
|
198
|
-
|
|
199
197
|
setDefaultOptions(options: DefaultOptions) {
|
|
200
198
|
GardenModule.setStyle(options)
|
|
201
199
|
}
|
|
@@ -243,29 +241,6 @@ export class Navigation implements Navigation {
|
|
|
243
241
|
GardenModule.setMenuInteractive(sceneId, enabled)
|
|
244
242
|
}
|
|
245
243
|
|
|
246
|
-
private _statusBarHeight = STATUSBAR_HEIGHT
|
|
247
|
-
private _toolbarHeight = TOOLBAR_HEIGHT
|
|
248
|
-
|
|
249
|
-
private handleStatusBarHeightChange() {
|
|
250
|
-
if (Platform.OS === 'ios') {
|
|
251
|
-
Event.listenStatusBarHeightChange(statusBarHeight => {
|
|
252
|
-
this._statusBarHeight = statusBarHeight
|
|
253
|
-
})
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
statusBarHeight() {
|
|
258
|
-
return this._statusBarHeight
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
toolbarHeight() {
|
|
262
|
-
return this._toolbarHeight
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
topBarHeight() {
|
|
266
|
-
return this.statusBarHeight() + this.toolbarHeight()
|
|
267
|
-
}
|
|
268
|
-
|
|
269
244
|
setBarButtonClickEventListener(listener: BarButtonClickEventListener) {
|
|
270
245
|
this.buttonHandler.setBarButtonClickEventListener(listener)
|
|
271
246
|
}
|