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
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.3",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"typings": "./lib/index.d.ts",
|
|
7
7
|
"react-native": "src/index",
|
package/src/Event.ts
CHANGED
|
@@ -1,15 +1,5 @@
|
|
|
1
1
|
import { NativeModules, NativeEventEmitter, NativeModule } from 'react-native'
|
|
2
|
-
import GardenModule from './GardenModule'
|
|
3
2
|
import type { Visibility } from './Route'
|
|
4
|
-
|
|
5
|
-
function listenStatusBarHeightChange(listener: (statusBarHeight: number) => void) {
|
|
6
|
-
const GardenEventReceiver = new NativeEventEmitter(GardenModule)
|
|
7
|
-
const { EVENT_STATUSBAR_FRAME_CHANGE } = GardenModule.getConstants()
|
|
8
|
-
return GardenEventReceiver.addListener(EVENT_STATUSBAR_FRAME_CHANGE, ({ statusBarHeight }) => {
|
|
9
|
-
listener(statusBarHeight)
|
|
10
|
-
})
|
|
11
|
-
}
|
|
12
|
-
|
|
13
3
|
interface HBDEventEmitter extends NativeModule {
|
|
14
4
|
getConstants: () => {
|
|
15
5
|
EVENT_NAVIGATION: string
|
|
@@ -113,7 +103,6 @@ function listenDidSetRoot(didSetRoot: (tag: number) => void) {
|
|
|
113
103
|
}
|
|
114
104
|
|
|
115
105
|
export default {
|
|
116
|
-
listenStatusBarHeightChange,
|
|
117
106
|
listenBarButtonItemClick,
|
|
118
107
|
listenComponentResult,
|
|
119
108
|
listenComponentVisibility,
|
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/GardenModule.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NativeModules, NativeModule } from 'react-native'
|
|
1
|
+
import { NativeModules, NativeModule, NativeEventEmitter, Platform } from 'react-native'
|
|
2
2
|
|
|
3
3
|
interface GardenModule extends NativeModule {
|
|
4
4
|
getConstants: () => {
|
|
@@ -21,4 +21,30 @@ interface GardenModule extends NativeModule {
|
|
|
21
21
|
|
|
22
22
|
const GardenModule: GardenModule = NativeModules.GardenModule
|
|
23
23
|
|
|
24
|
+
const { STATUSBAR_HEIGHT, TOOLBAR_HEIGHT, EVENT_STATUSBAR_FRAME_CHANGE } =
|
|
25
|
+
GardenModule.getConstants()
|
|
26
|
+
|
|
27
|
+
let _statusBarHeight = STATUSBAR_HEIGHT
|
|
28
|
+
|
|
29
|
+
if (Platform.OS === 'ios') {
|
|
30
|
+
const GardenEventReceiver = new NativeEventEmitter(GardenModule)
|
|
31
|
+
GardenEventReceiver.addListener(EVENT_STATUSBAR_FRAME_CHANGE, ({ statusBarHeight: height }) => {
|
|
32
|
+
_statusBarHeight = height
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function statusBarHeight() {
|
|
37
|
+
return _statusBarHeight
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function toolbarHeight() {
|
|
41
|
+
return TOOLBAR_HEIGHT
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function topBarHeight() {
|
|
45
|
+
return statusBarHeight() + toolbarHeight()
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export { statusBarHeight, toolbarHeight, topBarHeight }
|
|
49
|
+
|
|
24
50
|
export default GardenModule
|
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
|
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import React, { useEffect } from 'react'
|
|
2
|
-
|
|
3
2
|
import type { Garden } from './Garden'
|
|
4
3
|
import type { NavigationItem } from './Options'
|
|
5
|
-
|
|
6
4
|
import { Navigator, NavigationContext } from './Navigator'
|
|
7
5
|
|
|
8
6
|
export interface NavigationProps {
|
|
@@ -12,7 +10,7 @@ export interface NavigationProps {
|
|
|
12
10
|
}
|
|
13
11
|
|
|
14
12
|
/**
|
|
15
|
-
* @deprecated Use
|
|
13
|
+
* @deprecated Use NavigationProps instead.
|
|
16
14
|
*/
|
|
17
15
|
export type InjectedProps = NavigationProps
|
|
18
16
|
|
package/src/NavigationModule.ts
CHANGED
|
@@ -13,7 +13,7 @@ interface NavigationModule {
|
|
|
13
13
|
endRegisterReactComponent: () => void
|
|
14
14
|
registerReactComponent: (appKey: string, options: object) => void
|
|
15
15
|
signalFirstRenderComplete: (sceneId: string) => void
|
|
16
|
-
setRoot: (layout: object, sticky: boolean,
|
|
16
|
+
setRoot: (layout: object, sticky: boolean, callback: Callback) => void
|
|
17
17
|
setResult: (sceneId: string, resultCode: number, data: object | null) => void
|
|
18
18
|
dispatch: (sceneId: string, action: string, params: object, callback: Callback) => void
|
|
19
19
|
currentTab: (sceneId: string, callback: Callback) => void
|
|
@@ -49,8 +49,12 @@ function setResult(sceneId: string, resultCode: number, data: object | null) {
|
|
|
49
49
|
NavigationModule.setResult(sceneId, resultCode, data)
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
function setRoot(layout: object, sticky: boolean
|
|
53
|
-
|
|
52
|
+
function setRoot(layout: object, sticky: boolean) {
|
|
53
|
+
return new Promise<boolean>(resolve => {
|
|
54
|
+
NavigationModule.setRoot(layout, sticky, (_, success) => {
|
|
55
|
+
resolve(success)
|
|
56
|
+
})
|
|
57
|
+
})
|
|
54
58
|
}
|
|
55
59
|
|
|
56
60
|
function dispatch(sceneId: string, action: string, params: object) {
|
package/src/Navigator.ts
CHANGED
|
@@ -47,8 +47,13 @@ export class Navigator implements Navigator {
|
|
|
47
47
|
return navigator
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
static async current(): Promise<Navigator> {
|
|
51
|
+
const route = await Navigation.currentRoute()
|
|
52
|
+
return Navigator.of(route.sceneId)
|
|
53
|
+
}
|
|
54
|
+
|
|
50
55
|
/**
|
|
51
|
-
* @deprecated
|
|
56
|
+
* @deprecated Garden is deprecated, use Navigation.findSceneIdByModuleName() instead.
|
|
52
57
|
* @param moduleName
|
|
53
58
|
* @returns
|
|
54
59
|
*/
|
|
@@ -59,11 +64,6 @@ export class Navigator implements Navigator {
|
|
|
59
64
|
}
|
|
60
65
|
}
|
|
61
66
|
|
|
62
|
-
static async current(): Promise<Navigator> {
|
|
63
|
-
const route = await Navigator.currentRoute()
|
|
64
|
-
return Navigator.of(route.sceneId)
|
|
65
|
-
}
|
|
66
|
-
|
|
67
67
|
/**
|
|
68
68
|
* @deprecated Use Navigation.currentRoute() instead
|
|
69
69
|
* @returns
|
|
@@ -125,6 +125,9 @@ export class Navigator implements Navigator {
|
|
|
125
125
|
|
|
126
126
|
private _garden?: Garden
|
|
127
127
|
|
|
128
|
+
/**
|
|
129
|
+
* @deprecated Garden is deprecated, Use Navigation related methods instead.
|
|
130
|
+
*/
|
|
128
131
|
get garden() {
|
|
129
132
|
if (!this._garden) {
|
|
130
133
|
this._garden = new Garden(this.sceneId)
|
|
@@ -152,7 +155,13 @@ export class Navigator implements Navigator {
|
|
|
152
155
|
props: P = {} as P,
|
|
153
156
|
options: NavigationItem = {},
|
|
154
157
|
) => {
|
|
155
|
-
const success = await Navigation.dispatch(this.sceneId, 'push', {
|
|
158
|
+
const success = await Navigation.dispatch(this.sceneId, 'push', {
|
|
159
|
+
moduleName,
|
|
160
|
+
from: this.moduleName,
|
|
161
|
+
to: moduleName,
|
|
162
|
+
props,
|
|
163
|
+
options,
|
|
164
|
+
})
|
|
156
165
|
if (!success) {
|
|
157
166
|
return [RESULT_CANCEL, null] as [number, T]
|
|
158
167
|
}
|
|
@@ -160,19 +169,22 @@ export class Navigator implements Navigator {
|
|
|
160
169
|
}
|
|
161
170
|
|
|
162
171
|
pushLayout = async <T extends ResultType>(layout: BuildInLayout | Layout) => {
|
|
163
|
-
const success = await Navigation.dispatch(this.sceneId, 'pushLayout', {
|
|
172
|
+
const success = await Navigation.dispatch(this.sceneId, 'pushLayout', {
|
|
173
|
+
from: this.moduleName,
|
|
174
|
+
layout,
|
|
175
|
+
})
|
|
164
176
|
if (!success) {
|
|
165
177
|
return [RESULT_CANCEL, null] as [number, T]
|
|
166
178
|
}
|
|
167
179
|
return await Navigation.result<T>(this.sceneId, 0)
|
|
168
180
|
}
|
|
169
181
|
|
|
170
|
-
pop = () => Navigation.dispatch(this.sceneId, 'pop')
|
|
182
|
+
pop = () => Navigation.dispatch(this.sceneId, 'pop', { from: this.moduleName })
|
|
171
183
|
|
|
172
184
|
popTo = (moduleName: string, inclusive: boolean = false) =>
|
|
173
|
-
Navigation.dispatch(this.sceneId, 'popTo', { moduleName, inclusive })
|
|
185
|
+
Navigation.dispatch(this.sceneId, 'popTo', { moduleName, inclusive, from: this.moduleName })
|
|
174
186
|
|
|
175
|
-
popToRoot = () => Navigation.dispatch(this.sceneId, 'popToRoot')
|
|
187
|
+
popToRoot = () => Navigation.dispatch(this.sceneId, 'popToRoot', { from: this.moduleName })
|
|
176
188
|
|
|
177
189
|
redirectTo = <P extends PropsType>(
|
|
178
190
|
moduleName: string,
|
|
@@ -181,6 +193,8 @@ export class Navigator implements Navigator {
|
|
|
181
193
|
) =>
|
|
182
194
|
Navigation.dispatch(this.sceneId, 'redirectTo', {
|
|
183
195
|
moduleName,
|
|
196
|
+
from: this.moduleName,
|
|
197
|
+
to: moduleName,
|
|
184
198
|
props,
|
|
185
199
|
options,
|
|
186
200
|
})
|
|
@@ -193,6 +207,8 @@ export class Navigator implements Navigator {
|
|
|
193
207
|
const requestCode = --tagGenerator
|
|
194
208
|
const success = await Navigation.dispatch(this.sceneId, 'present', {
|
|
195
209
|
moduleName,
|
|
210
|
+
from: this.moduleName,
|
|
211
|
+
to: moduleName,
|
|
196
212
|
props,
|
|
197
213
|
options,
|
|
198
214
|
requestCode,
|
|
@@ -207,6 +223,7 @@ export class Navigator implements Navigator {
|
|
|
207
223
|
const requestCode = --tagGenerator
|
|
208
224
|
const success = await Navigation.dispatch(this.sceneId, 'presentLayout', {
|
|
209
225
|
layout,
|
|
226
|
+
from: this.moduleName,
|
|
210
227
|
requestCode,
|
|
211
228
|
})
|
|
212
229
|
if (!success) {
|
|
@@ -215,7 +232,7 @@ export class Navigator implements Navigator {
|
|
|
215
232
|
return await Navigation.result<T>(this.sceneId, requestCode)
|
|
216
233
|
}
|
|
217
234
|
|
|
218
|
-
dismiss = () => Navigation.dispatch(this.sceneId, 'dismiss')
|
|
235
|
+
dismiss = () => Navigation.dispatch(this.sceneId, 'dismiss', { from: this.moduleName })
|
|
219
236
|
|
|
220
237
|
showModal = async <T extends ResultType, P extends PropsType = {}>(
|
|
221
238
|
moduleName: string,
|
|
@@ -225,6 +242,8 @@ export class Navigator implements Navigator {
|
|
|
225
242
|
const requestCode = --tagGenerator
|
|
226
243
|
const success = await Navigation.dispatch(this.sceneId, 'showModal', {
|
|
227
244
|
moduleName,
|
|
245
|
+
from: this.moduleName,
|
|
246
|
+
to: moduleName,
|
|
228
247
|
props,
|
|
229
248
|
options,
|
|
230
249
|
requestCode,
|
|
@@ -238,6 +257,7 @@ export class Navigator implements Navigator {
|
|
|
238
257
|
showModalLayout = async <T extends ResultType>(layout: BuildInLayout | Layout) => {
|
|
239
258
|
const requestCode = --tagGenerator
|
|
240
259
|
const success = await Navigation.dispatch(this.sceneId, 'showModalLayout', {
|
|
260
|
+
from: this.moduleName,
|
|
241
261
|
layout,
|
|
242
262
|
requestCode,
|
|
243
263
|
})
|
|
@@ -247,7 +267,7 @@ export class Navigator implements Navigator {
|
|
|
247
267
|
return await Navigation.result<T>(this.sceneId, requestCode)
|
|
248
268
|
}
|
|
249
269
|
|
|
250
|
-
hideModal = () => Navigation.dispatch(this.sceneId, 'hideModal')
|
|
270
|
+
hideModal = () => Navigation.dispatch(this.sceneId, 'hideModal', { from: this.moduleName })
|
|
251
271
|
|
|
252
272
|
setResult = <T extends ResultType>(resultCode: number, data: T = null as any): void =>
|
|
253
273
|
Navigation.setResult(this.sceneId, resultCode, data)
|
|
@@ -257,11 +277,11 @@ export class Navigator implements Navigator {
|
|
|
257
277
|
return Navigation.dispatch(this.sceneId, 'switchTab', { from, to: index, popToRoot })
|
|
258
278
|
}
|
|
259
279
|
|
|
260
|
-
toggleMenu = () => Navigation.dispatch(this.sceneId, 'toggleMenu')
|
|
280
|
+
toggleMenu = () => Navigation.dispatch(this.sceneId, 'toggleMenu', { from: this.moduleName })
|
|
261
281
|
|
|
262
|
-
openMenu = () => Navigation.dispatch(this.sceneId, 'openMenu')
|
|
282
|
+
openMenu = () => Navigation.dispatch(this.sceneId, 'openMenu', { from: this.moduleName })
|
|
263
283
|
|
|
264
|
-
closeMenu = () => Navigation.dispatch(this.sceneId, 'closeMenu')
|
|
284
|
+
closeMenu = () => Navigation.dispatch(this.sceneId, 'closeMenu', { from: this.moduleName })
|
|
265
285
|
|
|
266
286
|
isStackRoot = () => Navigation.isStackRoot(this.sceneId)
|
|
267
287
|
|
package/src/ReactRegistry.tsx
CHANGED
|
@@ -3,6 +3,9 @@ import type { RouteConfig } from './Route'
|
|
|
3
3
|
|
|
4
4
|
import Navigation, { HOC } from './Navigation'
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* @deprecated use Navigation instead. import Navigation from 'hybrid-navigation'
|
|
8
|
+
*/
|
|
6
9
|
export class ReactRegistry {
|
|
7
10
|
/**
|
|
8
11
|
* @deprecated Use Navigation.startRegisterComponent() instead.
|
package/src/Route.ts
CHANGED
|
@@ -65,14 +65,6 @@ export interface RouteConfig {
|
|
|
65
65
|
mode?: RouteMode
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
export interface RouteInfo {
|
|
69
|
-
moduleName: string
|
|
70
|
-
dependencies: string[]
|
|
71
|
-
mode: RouteMode
|
|
72
|
-
props: object
|
|
73
|
-
options: object
|
|
74
|
-
}
|
|
75
|
-
|
|
76
68
|
export interface RouteData {
|
|
77
69
|
moduleName: string
|
|
78
70
|
regexp?: RegExp
|
|
@@ -81,8 +73,21 @@ export interface RouteData {
|
|
|
81
73
|
mode: RouteMode
|
|
82
74
|
}
|
|
83
75
|
|
|
76
|
+
export interface RouteInfo {
|
|
77
|
+
moduleName: string
|
|
78
|
+
mode: RouteMode
|
|
79
|
+
dependencies: string[]
|
|
80
|
+
props: object
|
|
81
|
+
options: object
|
|
82
|
+
}
|
|
83
|
+
|
|
84
84
|
export interface RouteHandler {
|
|
85
|
-
|
|
85
|
+
/**
|
|
86
|
+
* @param graph - current RouteGraph to process
|
|
87
|
+
* @param target - route may add to the graph
|
|
88
|
+
* @reurns [boolean, RouteGraph] - if the route is handled, return true and childGraph for next Handler to process, [false, graph] otherwise
|
|
89
|
+
*/
|
|
90
|
+
process: (graph: RouteGraph, target: RouteInfo) => Promise<[boolean, RouteGraph | null]>
|
|
86
91
|
}
|
|
87
92
|
|
|
88
93
|
export type RouteInterceptor = (path: string) => boolean | Promise<boolean>
|
|
@@ -6,40 +6,20 @@ export default class LayoutCommandHandler {
|
|
|
6
6
|
private willSetRoot = () => {}
|
|
7
7
|
private didSetRoot = () => {}
|
|
8
8
|
|
|
9
|
-
private canInvokeWillSetRoot = true
|
|
10
|
-
private tagGenerator = 0
|
|
11
|
-
|
|
12
9
|
constructor() {}
|
|
13
10
|
|
|
14
11
|
handleRootLayoutChange() {
|
|
15
12
|
Event.listenWillSetRoot(() => {
|
|
16
|
-
|
|
17
|
-
this.willSetRoot()
|
|
18
|
-
}
|
|
13
|
+
this.willSetRoot()
|
|
19
14
|
})
|
|
20
15
|
|
|
21
16
|
Event.listenDidSetRoot(() => {
|
|
22
17
|
this.didSetRoot()
|
|
23
|
-
this.canInvokeWillSetRoot = true
|
|
24
18
|
})
|
|
25
19
|
}
|
|
26
20
|
|
|
27
21
|
setRoot(layout: BuildInLayout | Layout, sticky = false) {
|
|
28
|
-
|
|
29
|
-
this.canInvokeWillSetRoot = false
|
|
30
|
-
|
|
31
|
-
const flag = this.tagGenerator++
|
|
32
|
-
NavigationModule.setRoot(layout, sticky, flag)
|
|
33
|
-
|
|
34
|
-
return new Promise<void>(resolve => {
|
|
35
|
-
const subscription = Event.listenDidSetRoot((tag: number) => {
|
|
36
|
-
// FIXME: 此处恐有内存泄漏
|
|
37
|
-
if (tag === flag) {
|
|
38
|
-
subscription.remove()
|
|
39
|
-
resolve()
|
|
40
|
-
}
|
|
41
|
-
})
|
|
42
|
-
})
|
|
22
|
+
return NavigationModule.setRoot(layout, sticky)
|
|
43
23
|
}
|
|
44
24
|
|
|
45
25
|
setRootLayoutUpdateListener(willSetRoot = () => {}, didSetRoot = () => {}) {
|