hybrid-navigation 2.13.0-beta.3 → 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/android/src/main/java/com/reactnative/hybridnavigation/ReactFragment.java +3 -20
- package/lib/Event.d.ts +12 -16
- package/lib/Event.js +20 -66
- package/lib/Garden.d.ts +49 -6
- package/lib/Garden.js +56 -32
- package/lib/Navigation.d.ts +68 -0
- package/lib/Navigation.js +162 -0
- package/lib/NavigationComponentWrap.d.ts +19 -0
- package/lib/NavigationComponentWrap.js +46 -0
- package/lib/Navigator.d.ts +46 -32
- package/lib/Navigator.js +110 -169
- package/lib/ReactRegistry.d.ts +19 -13
- package/lib/ReactRegistry.js +21 -73
- package/lib/Route.d.ts +13 -8
- package/lib/handler/BarButtonEventHandler.d.ts +10 -0
- package/lib/handler/BarButtonEventHandler.js +38 -0
- package/lib/handler/DispatchCommandHandler.d.ts +26 -0
- package/lib/handler/DispatchCommandHandler.js +28 -0
- package/lib/handler/LayoutCommandHandler.d.ts +11 -0
- package/lib/handler/LayoutCommandHandler.js +39 -0
- package/lib/handler/ResultEventHandler.d.ts +15 -0
- package/lib/handler/ResultEventHandler.js +47 -0
- package/lib/handler/VisibilityEventHandler.d.ts +13 -0
- package/lib/handler/VisibilityEventHandler.js +32 -0
- package/lib/hooks.d.ts +4 -0
- package/lib/hooks.js +13 -18
- package/lib/index.d.ts +8 -1
- package/lib/index.js +26 -2
- 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 +140 -116
- 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 +25 -90
- package/src/Garden.ts +60 -38
- package/src/Navigation.ts +253 -0
- package/src/NavigationComponentWrap.tsx +73 -0
- package/src/Navigator.ts +124 -233
- package/src/ReactRegistry.tsx +23 -99
- package/src/Route.ts +14 -9
- package/src/handler/BarButtonEventHandler.ts +50 -0
- package/src/handler/DispatchCommandHandler.ts +58 -0
- package/src/handler/LayoutCommandHandler.ts +49 -0
- package/src/handler/ResultEventHandler.ts +67 -0
- package/src/handler/VisibilityEventHandler.ts +44 -0
- package/src/hooks.ts +18 -30
- package/src/index.ts +38 -4
- package/src/router/drawer.ts +20 -17
- package/src/router/index.ts +150 -119
- 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,142 +1,166 @@
|
|
|
1
1
|
import { pathToRegexp, match } from 'path-to-regexp';
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
return false;
|
|
16
|
-
};
|
|
17
|
-
function addInterceptor(func) {
|
|
18
|
-
interceptors.add(func);
|
|
19
|
-
}
|
|
20
|
-
function removeInterceptor(func) {
|
|
21
|
-
interceptors.delete(func);
|
|
22
|
-
}
|
|
23
|
-
function use(handler) {
|
|
24
|
-
handlers.add(handler);
|
|
2
|
+
import Navigation from '../Navigation';
|
|
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 : {};
|
|
25
13
|
}
|
|
26
|
-
function
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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;
|
|
32
21
|
}
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
mode = mode || 'push';
|
|
36
|
-
routeDatas.set(moduleName, { moduleName, mode, path, regexp, dependency });
|
|
22
|
+
return result;
|
|
23
|
+
}, {});
|
|
37
24
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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());
|
|
31
|
+
}
|
|
32
|
+
handlers = new Map();
|
|
33
|
+
registerRouteHandler(layout, handler) {
|
|
34
|
+
this.handlers.set(layout, handler);
|
|
35
|
+
}
|
|
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);
|
|
47
44
|
}
|
|
48
|
-
|
|
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) {
|
|
49
52
|
return;
|
|
50
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
|
+
}
|
|
51
60
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
61
|
+
interceptors = [];
|
|
62
|
+
addInterceptor(interceptor) {
|
|
63
|
+
this.interceptors.push(interceptor);
|
|
55
64
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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;
|
|
63
73
|
}
|
|
64
|
-
|
|
65
|
-
|
|
74
|
+
return result;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
pathToRoute(path, props, options) {
|
|
78
|
+
for (const data of this.routeDatas.values()) {
|
|
79
|
+
if (!data.regexp) {
|
|
80
|
+
continue;
|
|
66
81
|
}
|
|
67
|
-
|
|
68
|
-
|
|
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 };
|
|
69
91
|
}
|
|
70
92
|
}
|
|
71
93
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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);
|
|
78
100
|
}
|
|
79
|
-
|
|
80
|
-
|
|
101
|
+
return dependencies.reverse();
|
|
102
|
+
}
|
|
103
|
+
async processRoute(route, graph) {
|
|
104
|
+
const handler = this.handlers.get(graph.layout);
|
|
105
|
+
if (!handler) {
|
|
106
|
+
return false;
|
|
81
107
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
108
|
+
const [consumed, childGraph] = await handler.process(graph, route);
|
|
109
|
+
if (consumed && childGraph) {
|
|
110
|
+
return await this.processRoute(route, childGraph);
|
|
85
111
|
}
|
|
112
|
+
return consumed;
|
|
86
113
|
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
if (
|
|
91
|
-
|
|
114
|
+
async open(path, props = {}, options = {}) {
|
|
115
|
+
this.inflateRouteData();
|
|
116
|
+
const intercepted = await this.intercept(path);
|
|
117
|
+
if (intercepted) {
|
|
118
|
+
return;
|
|
92
119
|
}
|
|
93
|
-
const
|
|
94
|
-
if (
|
|
95
|
-
|
|
96
|
-
const params = pathParams(pathName);
|
|
97
|
-
const query = queryParams(queryString);
|
|
98
|
-
props = { ...query, ...params, ...props };
|
|
99
|
-
const dependencies = routeDependencies(data);
|
|
100
|
-
const mode = data.mode;
|
|
101
|
-
return { moduleName, props, dependencies, mode, options };
|
|
120
|
+
const route = this.pathToRoute(path, props, options);
|
|
121
|
+
if (!route) {
|
|
122
|
+
return;
|
|
102
123
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
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
|
+
}
|
|
119
139
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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
|
+
});
|
|
129
161
|
}
|
|
130
|
-
return dependencies.reverse();
|
|
131
162
|
}
|
|
132
|
-
export const router =
|
|
133
|
-
addInterceptor,
|
|
134
|
-
removeInterceptor,
|
|
135
|
-
registerRoute,
|
|
136
|
-
use,
|
|
137
|
-
open,
|
|
138
|
-
pathToRoute,
|
|
139
|
-
};
|
|
163
|
+
export const router = new Router();
|
|
140
164
|
export * from './drawer';
|
|
141
165
|
export * from './screen';
|
|
142
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",
|