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/src/router/stack.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { isScreenGraph } from './screen'
|
|
2
|
-
import { Navigator } from '../Navigator'
|
|
1
|
+
import { ScreenGraph, isScreenGraph, isTargetLocateIn } from './screen'
|
|
3
2
|
import { LayoutMode, RouteGraph, RouteHandler, RouteInfo } from '../Route'
|
|
3
|
+
import Navigation from '../Navigation'
|
|
4
4
|
|
|
5
5
|
export interface StackGraph extends RouteGraph {
|
|
6
6
|
layout: 'stack'
|
|
@@ -13,68 +13,81 @@ export function isStackGraph(graph: RouteGraph): graph is StackGraph {
|
|
|
13
13
|
return graph.layout === 'stack'
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
export
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const { mode, moduleName, dependencies, props } = route
|
|
16
|
+
export class StackRouteHandler implements RouteHandler {
|
|
17
|
+
async process(graph: RouteGraph, target: RouteInfo): Promise<[boolean, RouteGraph | null]> {
|
|
18
|
+
if (!isStackGraph(graph)) {
|
|
19
|
+
throw new Error(`${graph} is Not a StackGraph`)
|
|
20
|
+
}
|
|
22
21
|
|
|
23
|
-
|
|
24
|
-
return false
|
|
25
|
-
}
|
|
22
|
+
const { children } = graph
|
|
26
23
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
24
|
+
for (let i = children.length - 1; i > -1; i--) {
|
|
25
|
+
const childGraph = children[i]
|
|
26
|
+
if (isTargetLocateIn(childGraph, target)) {
|
|
27
|
+
if (isScreenGraph(childGraph)) {
|
|
28
|
+
this.navigateTo(childGraph, target)
|
|
29
|
+
return [true, null]
|
|
30
|
+
}
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
expectedIndex = expectedModuleNames.findIndex(name => existingModuleNames.includes(name))
|
|
36
|
-
if (expectedIndex !== -1) {
|
|
37
|
-
childIndex = i
|
|
38
|
-
break
|
|
32
|
+
await this.popToIfNeeded(childGraph, i === children.length - 1)
|
|
33
|
+
return [true, childGraph]
|
|
34
|
+
}
|
|
39
35
|
}
|
|
36
|
+
|
|
37
|
+
return [false, graph]
|
|
40
38
|
}
|
|
41
39
|
|
|
42
|
-
|
|
43
|
-
if (!
|
|
44
|
-
await
|
|
40
|
+
private async popToIfNeeded(childGraph: RouteGraph, isLastChildAtStack: boolean) {
|
|
41
|
+
if (!isLastChildAtStack) {
|
|
42
|
+
await Navigation.dispatch(childGraph.sceneId, 'popTo', {
|
|
43
|
+
moduleName: childGraph.sceneId,
|
|
44
|
+
})
|
|
45
45
|
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
private navigateTo(childGraph: ScreenGraph, target: RouteInfo) {
|
|
49
|
+
const { mode, moduleName, dependencies, props } = target
|
|
50
|
+
const expectations = [...dependencies, moduleName]
|
|
51
|
+
const index = expectations.findIndex(name => name === childGraph.moduleName)
|
|
52
|
+
const pendings = expectations.slice(index + 1)
|
|
53
|
+
console.log('pendings', pendings, 'moduleName', childGraph.moduleName)
|
|
54
|
+
const sceneId = childGraph.sceneId
|
|
46
55
|
|
|
47
|
-
|
|
48
|
-
const navigator = Navigator.of(children[children.length - 1].sceneId)
|
|
56
|
+
const moduleExisting = pendings.length === 0
|
|
49
57
|
|
|
50
|
-
if (
|
|
58
|
+
if (moduleExisting) {
|
|
51
59
|
if (JSON.stringify(props) === '{}') {
|
|
52
|
-
|
|
60
|
+
Navigation.dispatch(sceneId, 'popTo', {
|
|
61
|
+
moduleName,
|
|
62
|
+
from: childGraph.moduleName,
|
|
63
|
+
to: moduleName,
|
|
64
|
+
})
|
|
53
65
|
} else {
|
|
54
|
-
|
|
66
|
+
Navigation.dispatch(sceneId, 'redirectTo', {
|
|
67
|
+
moduleName,
|
|
68
|
+
from: childGraph.moduleName,
|
|
69
|
+
to: moduleName,
|
|
70
|
+
props,
|
|
71
|
+
})
|
|
55
72
|
}
|
|
56
73
|
} else {
|
|
57
|
-
for (let i = 0; i <
|
|
58
|
-
|
|
59
|
-
|
|
74
|
+
for (let i = 0; i < pendings.length; i++) {
|
|
75
|
+
const isLast = i === pendings.length - 1
|
|
76
|
+
if (isLast) {
|
|
77
|
+
Navigation.dispatch(sceneId, 'push', {
|
|
78
|
+
moduleName,
|
|
79
|
+
from: childGraph.moduleName,
|
|
80
|
+
to: moduleName,
|
|
81
|
+
props,
|
|
82
|
+
})
|
|
60
83
|
} else {
|
|
61
|
-
|
|
84
|
+
Navigation.dispatch(sceneId, 'push', {
|
|
85
|
+
moduleName: pendings[i],
|
|
86
|
+
from: childGraph.moduleName,
|
|
87
|
+
to: pendings[i],
|
|
88
|
+
})
|
|
62
89
|
}
|
|
63
90
|
}
|
|
64
91
|
}
|
|
65
|
-
return true
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return false
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function extractModuleNames(graph: RouteGraph, set: string[]) {
|
|
72
|
-
if (isScreenGraph(graph)) {
|
|
73
|
-
set.push(graph.moduleName)
|
|
74
|
-
} else {
|
|
75
|
-
const children = graph.children!
|
|
76
|
-
for (let i = 0; i < children.length; i++) {
|
|
77
|
-
extractModuleNames(children[i], set)
|
|
78
|
-
}
|
|
79
92
|
}
|
|
80
93
|
}
|
package/src/router/tabs.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { isScreenGraph } from './screen'
|
|
1
|
+
import { isTargetLocateIn } from './screen'
|
|
3
2
|
import { LayoutMode, RouteGraph, RouteHandler, RouteInfo } from '../Route'
|
|
3
|
+
import Navigation from '../Navigation'
|
|
4
4
|
|
|
5
5
|
export interface TabsGraph extends RouteGraph {
|
|
6
6
|
layout: 'tabs'
|
|
@@ -13,37 +13,27 @@ export interface TabsGraph extends RouteGraph {
|
|
|
13
13
|
export function isTabsGraph(graph: RouteGraph): graph is TabsGraph {
|
|
14
14
|
return graph.layout === 'tabs'
|
|
15
15
|
}
|
|
16
|
+
export class TabsRouteHandler implements RouteHandler {
|
|
17
|
+
async process(graph: RouteGraph, target: RouteInfo): Promise<[boolean, RouteGraph]> {
|
|
18
|
+
if (!isTabsGraph(graph)) {
|
|
19
|
+
throw new Error(`${graph} is NOT a TabsGraph`)
|
|
20
|
+
}
|
|
16
21
|
|
|
17
|
-
|
|
18
|
-
if (!isTabsGraph(graph)) {
|
|
19
|
-
return false
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const { children, selectedIndex } = graph
|
|
23
|
-
const { dependencies, moduleName } = route
|
|
24
|
-
const expectedModuleNames = [...dependencies, moduleName]
|
|
22
|
+
const { children, selectedIndex } = graph
|
|
25
23
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
24
|
+
for (let i = 0; i < children.length; i++) {
|
|
25
|
+
if (isTargetLocateIn(children[i], target)) {
|
|
26
|
+
if (selectedIndex !== i) {
|
|
27
|
+
await Navigation.dispatch(children[selectedIndex].sceneId, 'switchTab', {
|
|
28
|
+
from: selectedIndex,
|
|
29
|
+
to: i,
|
|
30
|
+
popToRoot: true,
|
|
31
|
+
})
|
|
32
|
+
}
|
|
33
|
+
return [true, children[i]]
|
|
33
34
|
}
|
|
34
|
-
return next(children[i], route, next)
|
|
35
35
|
}
|
|
36
|
-
}
|
|
37
|
-
return false
|
|
38
|
-
}
|
|
39
36
|
|
|
40
|
-
|
|
41
|
-
if (isScreenGraph(graph)) {
|
|
42
|
-
set.push(graph.moduleName)
|
|
43
|
-
} else {
|
|
44
|
-
const children = graph.children!
|
|
45
|
-
for (let i = 0; i < children.length; i++) {
|
|
46
|
-
extractModuleNames(children[i], set)
|
|
47
|
-
}
|
|
37
|
+
return [false, graph]
|
|
48
38
|
}
|
|
49
39
|
}
|