hybrid-navigation 4.1.0 → 5.1.0
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/HybridNavigation.podspec +9 -1
- package/README.md +12 -4
- package/android/build.gradle +4 -4
- package/android/proguard-rules.pro +0 -14
- package/android/src/main/java/com/navigation/androidx/AwesomeActivity.java +116 -27
- package/android/src/main/java/com/navigation/androidx/AwesomeFragment.java +162 -13
- package/android/src/main/java/com/navigation/androidx/DefaultTabBarProvider.java +2 -2
- package/android/src/main/java/com/navigation/androidx/DrawableUtils.java +83 -18
- package/android/src/main/java/com/navigation/androidx/DrawerFragment.java +185 -25
- package/android/src/main/java/com/navigation/androidx/FragmentHelper.java +18 -0
- package/android/src/main/java/com/navigation/androidx/HybridDrawerLayout.java +563 -143
- package/android/src/main/java/com/navigation/androidx/LifecycleDelegate.java +39 -12
- package/android/src/main/java/com/navigation/androidx/PresentableActivity.java +3 -0
- package/android/src/main/java/com/navigation/androidx/PresentationDelegate.java +10 -7
- package/android/src/main/java/com/navigation/androidx/StackDelegate.java +29 -9
- package/android/src/main/java/com/navigation/androidx/StackFragment.java +31 -3
- package/android/src/main/java/com/navigation/androidx/SystemUI.java +59 -90
- package/android/src/main/java/com/navigation/androidx/TabBar.java +21 -2
- package/android/src/main/java/com/navigation/androidx/TabBarFragment.java +74 -7
- package/android/src/main/java/com/navigation/androidx/TabBarItem.java +4 -0
- package/android/src/main/java/com/navigation/androidx/TabView.java +11 -2
- package/android/src/main/java/com/reactnative/hybridnavigation/DispatchResult.java +71 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/Garden.java +18 -10
- package/android/src/main/java/com/reactnative/hybridnavigation/GlobalStyle.java +34 -2
- package/android/src/main/java/com/reactnative/hybridnavigation/HBDRootView.java +20 -10
- package/android/src/main/java/com/reactnative/hybridnavigation/HybridFragment.java +179 -13
- package/android/src/main/java/com/reactnative/hybridnavigation/HybridNavigationPackage.java +13 -24
- package/android/src/main/java/com/reactnative/hybridnavigation/NativeEvent.java +5 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/NativeNavigation.java +283 -183
- package/android/src/main/java/com/reactnative/hybridnavigation/NavigationCommandQueue.java +507 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/Navigator.java +4 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/OrientationCoordinator.java +162 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactAppCompatActivity.java +103 -66
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactFragment.java +421 -92
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactManager.java +227 -78
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactStackFragment.java +6 -6
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarFragment.java +26 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarProvider.java +8 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/SceneLifecycleState.java +21 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/SceneLifecycleStateMachine.java +116 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/ScreenOrientation.java +42 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/Utils.java +17 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/DrawerNavigator.java +14 -6
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/ScreenNavigator.java +188 -26
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/StackNavigator.java +67 -16
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/TabNavigator.java +42 -14
- package/dist/DeepLink.d.ts +3 -2
- package/dist/DeepLink.js +37 -14
- package/dist/NativeEvent.d.ts +17 -10
- package/dist/NativeNavigation.d.ts +24 -18
- package/dist/Navigation.d.ts +34 -19
- package/dist/Navigation.js +225 -90
- package/dist/NavigationComponentWrap.d.ts +5 -3
- package/dist/NavigationComponentWrap.js +3 -6
- package/dist/Navigator.d.ts +32 -42
- package/dist/Navigator.js +117 -91
- package/dist/Options.d.ts +15 -3
- package/dist/Route.d.ts +149 -17
- package/dist/defineRoutes.d.ts +19 -0
- package/dist/defineRoutes.js +6 -0
- package/dist/handler/DispatchCommandHandler.d.ts +25 -6
- package/dist/handler/DispatchCommandHandler.js +99 -17
- package/dist/handler/LayoutCommandHandler.d.ts +8 -7
- package/dist/handler/LayoutCommandHandler.js +24 -15
- package/dist/handler/LeaveGuardHandler.d.ts +17 -0
- package/dist/handler/LeaveGuardHandler.js +350 -0
- package/dist/handler/LifecycleEventHandler.d.ts +30 -0
- package/dist/handler/LifecycleEventHandler.js +169 -0
- package/dist/handler/PresentationCoordinator.d.ts +24 -0
- package/dist/handler/PresentationCoordinator.js +449 -0
- package/dist/handler/ResultEventHandler.d.ts +21 -9
- package/dist/handler/ResultEventHandler.js +96 -13
- package/dist/handler/TabEventHandler.d.ts +8 -0
- package/dist/handler/TabEventHandler.js +25 -0
- package/dist/hooks.d.ts +7 -2
- package/dist/hooks.js +46 -4
- package/dist/index.d.ts +24 -0
- package/dist/index.js +3 -2
- package/dist/reveal.d.ts +46 -0
- package/dist/reveal.js +431 -0
- package/dist/routeConfigRegistry.d.ts +6 -0
- package/dist/routeConfigRegistry.js +19 -0
- package/dist/routeGraph.d.ts +12 -0
- package/dist/routeGraph.js +68 -0
- package/dist/router/drawer.d.ts +2 -2
- package/dist/router/drawer.js +6 -3
- package/dist/router/index.d.ts +8 -5
- package/dist/router/index.js +106 -58
- package/dist/router/screen.d.ts +2 -2
- package/dist/router/screen.js +1 -1
- package/dist/router/stack.d.ts +2 -2
- package/dist/router/stack.js +59 -30
- package/dist/router/tabs.d.ts +3 -2
- package/dist/router/tabs.js +4 -1
- package/dist/store.d.ts +4 -2
- package/dist/store.js +4 -0
- package/dist/testing.d.ts +79 -0
- package/dist/testing.js +251 -0
- package/ios/HBDGlobalStyle.h +29 -0
- package/ios/{GlobalStyle.mm → HBDGlobalStyle.mm} +43 -29
- package/ios/HybridNavigation.h +5 -1
- package/ios/Navigator/HBDDrawerNavigator.mm +24 -8
- package/ios/Navigator/HBDNavigatorRegistry.mm +1 -0
- package/ios/Navigator/HBDScreenNavigator.mm +278 -58
- package/ios/Navigator/HBDStackNavigator.mm +152 -61
- package/ios/Navigator/HBDTabNavigator.mm +60 -14
- package/ios/React/HBDNativeNavigation.mm +162 -123
- package/ios/React/HBDNavigator.h +37 -5
- package/ios/React/HBDOrientationCoordinator.h +29 -0
- package/ios/React/HBDOrientationCoordinator.mm +309 -0
- package/ios/React/HBDReactBridgeManager.h +46 -20
- package/ios/React/HBDReactBridgeManager.mm +496 -108
- package/ios/React/HBDSceneLifecycleStateMachine.h +38 -0
- package/ios/React/HBDSceneLifecycleStateMachine.mm +180 -0
- package/ios/View/HBDRootView.h +2 -0
- package/ios/View/HBDRootView.mm +148 -0
- package/ios/View/UIImage+WithBadge.h +3 -3
- package/ios/View/UIImage+WithBadge.mm +10 -15
- package/ios/ViewController/HBDDrawerController.mm +126 -5
- package/ios/ViewController/HBDNavigationController.mm +31 -4
- package/ios/ViewController/HBDReactViewController.h +6 -0
- package/ios/ViewController/HBDReactViewController.mm +220 -106
- package/ios/ViewController/HBDTabBarController.h +15 -0
- package/ios/ViewController/HBDTabBarController.mm +227 -45
- package/ios/ViewController/HBDTabBarRenderer.h +28 -0
- package/ios/ViewController/HBDViewController.h +11 -3
- package/ios/ViewController/HBDViewController.mm +209 -159
- package/ios/ViewController/UINavigationController+HBD.h +2 -2
- package/ios/ViewController/UINavigationController+HBD.mm +3 -3
- package/ios/ViewController/UIViewController+HBD.h +18 -10
- package/ios/ViewController/UIViewController+HBD.mm +90 -65
- package/package.json +3 -1
- package/src/DeepLink.ts +41 -14
- package/src/NativeEvent.ts +18 -11
- package/src/NativeNavigation.ts +29 -31
- package/src/Navigation.ts +377 -120
- package/src/NavigationComponentWrap.tsx +18 -9
- package/src/Navigator.ts +219 -152
- package/src/Options.ts +12 -3
- package/src/Route.ts +228 -17
- package/src/defineRoutes.ts +46 -0
- package/src/handler/DispatchCommandHandler.ts +154 -21
- package/src/handler/LayoutCommandHandler.ts +40 -17
- package/src/handler/LeaveGuardHandler.ts +436 -0
- package/src/handler/LifecycleEventHandler.ts +219 -0
- package/src/handler/PresentationCoordinator.ts +560 -0
- package/src/handler/ResultEventHandler.ts +126 -19
- package/src/handler/TabEventHandler.ts +31 -0
- package/src/hooks.ts +75 -7
- package/src/index.ts +37 -2
- package/src/reveal.ts +565 -0
- package/src/routeConfigRegistry.ts +26 -0
- package/src/routeGraph.ts +87 -0
- package/src/router/drawer.ts +8 -5
- package/src/router/index.ts +139 -63
- package/src/router/screen.ts +3 -3
- package/src/router/stack.ts +80 -29
- package/src/router/tabs.ts +16 -7
- package/src/store.ts +6 -1
- package/src/testing.ts +395 -0
- package/testing.d.ts +1 -0
- package/testing.js +3 -0
- package/android/src/main/java/androidx/fragment/app/InternalFragment.java +0 -22
- package/android/src/main/java/com/navigation/androidx/SystemUI30.java +0 -87
- package/android/src/main/java/com/reactnative/hybridnavigation/NativeGarden.java +0 -176
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBar.java +0 -130
- package/android/src/main/res/layout/nav_tab_bar_react.xml +0 -32
- package/android/src/main/res/layout/nav_tab_bar_react_indeterminate.xml +0 -32
- package/dist/NativeGarden.d.ts +0 -13
- package/dist/NativeGarden.js +0 -2
- package/dist/handler/VisibilityEventHandler.d.ts +0 -13
- package/dist/handler/VisibilityEventHandler.js +0 -39
- package/ios/GlobalStyle.h +0 -15
- package/ios/React/HBDNativeGarden.h +0 -10
- package/ios/React/HBDNativeGarden.mm +0 -111
- package/src/NativeGarden.ts +0 -16
- package/src/handler/VisibilityEventHandler.ts +0 -52
package/dist/router/index.js
CHANGED
|
@@ -4,18 +4,27 @@ import { ScreenRouteHandler } from './screen';
|
|
|
4
4
|
import { TabsRouteHandler } from './tabs';
|
|
5
5
|
import { DrawerRouteHandler } from './drawer';
|
|
6
6
|
import Navigation from '../Navigation';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
import { dismissPresentedLayers } from '../reveal';
|
|
8
|
+
import { getRouteConfigs, getRouteConfigVersion } from '../routeConfigRegistry';
|
|
9
|
+
function safeDecodeURIComponent(value) {
|
|
10
|
+
try {
|
|
11
|
+
return decodeURIComponent(value);
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
12
16
|
}
|
|
13
17
|
function queryParams(queryString) {
|
|
14
18
|
return (queryString || '').split('&').reduce((result, item) => {
|
|
15
19
|
if (item !== '') {
|
|
16
20
|
const nextResult = result || {};
|
|
17
|
-
const
|
|
18
|
-
|
|
21
|
+
const separatorIndex = item.indexOf('=');
|
|
22
|
+
const rawKey = separatorIndex >= 0 ? item.slice(0, separatorIndex) : item;
|
|
23
|
+
const rawValue = separatorIndex >= 0 ? item.slice(separatorIndex + 1) : '';
|
|
24
|
+
const key = safeDecodeURIComponent(rawKey);
|
|
25
|
+
if (key) {
|
|
26
|
+
nextResult[key] = safeDecodeURIComponent(rawValue);
|
|
27
|
+
}
|
|
19
28
|
return nextResult;
|
|
20
29
|
}
|
|
21
30
|
return result;
|
|
@@ -29,29 +38,37 @@ class Router {
|
|
|
29
38
|
this.registerRouteHandler('drawer', new DrawerRouteHandler());
|
|
30
39
|
}
|
|
31
40
|
handlers = new Map();
|
|
41
|
+
openQueue = Promise.resolve();
|
|
32
42
|
registerRouteHandler(layout, handler) {
|
|
33
43
|
this.handlers.set(layout, handler);
|
|
34
44
|
}
|
|
35
45
|
convertConfigToData(moduleName, route) {
|
|
36
46
|
let { path, dependency, mode } = route;
|
|
37
47
|
let regexp;
|
|
48
|
+
let matcher;
|
|
38
49
|
if (path) {
|
|
39
50
|
if (!path.startsWith('/')) {
|
|
40
|
-
|
|
51
|
+
path = '/' + path;
|
|
52
|
+
route.path = path;
|
|
41
53
|
}
|
|
42
54
|
regexp = pathToRegexp(path).regexp;
|
|
55
|
+
matcher = match(path, {
|
|
56
|
+
decode: safeDecodeURIComponent,
|
|
57
|
+
});
|
|
43
58
|
}
|
|
44
59
|
mode = mode || 'push';
|
|
45
|
-
return { moduleName, mode, path, regexp, dependency };
|
|
60
|
+
return { moduleName, mode, path, regexp, matcher, dependency };
|
|
46
61
|
}
|
|
47
|
-
|
|
62
|
+
inflatedRouteConfigVersion = -1;
|
|
48
63
|
routeDataSet = new Map();
|
|
49
64
|
inflateRouteData() {
|
|
50
|
-
|
|
65
|
+
const currentVersion = getRouteConfigVersion();
|
|
66
|
+
if (this.inflatedRouteConfigVersion === currentVersion) {
|
|
51
67
|
return;
|
|
52
68
|
}
|
|
53
|
-
this.
|
|
54
|
-
|
|
69
|
+
this.inflatedRouteConfigVersion = currentVersion;
|
|
70
|
+
this.routeDataSet.clear();
|
|
71
|
+
const routeConfigs = getRouteConfigs();
|
|
55
72
|
for (const [moduleName, config] of routeConfigs) {
|
|
56
73
|
const data = this.convertConfigToData(moduleName, config);
|
|
57
74
|
this.routeDataSet.set(moduleName, data);
|
|
@@ -60,47 +77,54 @@ class Router {
|
|
|
60
77
|
interceptors = [];
|
|
61
78
|
addInterceptor(interceptor) {
|
|
62
79
|
this.interceptors.push(interceptor);
|
|
80
|
+
return {
|
|
81
|
+
remove: () => this.removeInterceptor(interceptor),
|
|
82
|
+
};
|
|
63
83
|
}
|
|
64
84
|
removeInterceptor(interceptor) {
|
|
65
85
|
this.interceptors = this.interceptors.filter(item => item !== interceptor);
|
|
66
86
|
}
|
|
67
87
|
async intercept(path) {
|
|
68
|
-
for (
|
|
88
|
+
for (const interceptor of this.interceptors.slice()) {
|
|
69
89
|
const result = interceptor(path);
|
|
70
|
-
const intercepted = await
|
|
90
|
+
const intercepted = result instanceof Promise ? await result : result;
|
|
71
91
|
if (intercepted) {
|
|
72
92
|
return true;
|
|
73
93
|
}
|
|
74
94
|
}
|
|
75
95
|
return false;
|
|
76
96
|
}
|
|
77
|
-
resolveInterceptResult(result) {
|
|
78
|
-
if (result instanceof Promise) {
|
|
79
|
-
return result;
|
|
80
|
-
}
|
|
81
|
-
return Promise.resolve(result);
|
|
82
|
-
}
|
|
83
97
|
pathToRoute(path, props, options) {
|
|
98
|
+
const withoutHash = path.split('#')[0];
|
|
99
|
+
const queryIndex = withoutHash.indexOf('?');
|
|
100
|
+
const rawPathName = queryIndex >= 0 ? withoutHash.slice(0, queryIndex) : withoutHash;
|
|
101
|
+
const queryString = queryIndex >= 0 ? withoutHash.slice(queryIndex + 1) : '';
|
|
102
|
+
const pathName = rawPathName.startsWith('/') ? rawPathName : '/' + rawPathName;
|
|
84
103
|
for (const data of this.routeDataSet.values()) {
|
|
85
|
-
if (!data.
|
|
104
|
+
if (!data.matcher) {
|
|
86
105
|
continue;
|
|
87
106
|
}
|
|
88
|
-
const
|
|
89
|
-
if (
|
|
107
|
+
const matched = data.matcher(pathName);
|
|
108
|
+
if (matched) {
|
|
90
109
|
const moduleName = data.moduleName;
|
|
91
|
-
const params =
|
|
110
|
+
const params = matched.params || {};
|
|
92
111
|
const query = queryParams(queryString);
|
|
93
|
-
|
|
112
|
+
const mergedProps = { ...query, ...params, ...props };
|
|
94
113
|
const dependencies = this.routeDependencies(data);
|
|
95
114
|
const mode = data.mode;
|
|
96
|
-
return { moduleName, props, dependencies, mode, options };
|
|
115
|
+
return { moduleName, props: mergedProps, dependencies, mode, options };
|
|
97
116
|
}
|
|
98
117
|
}
|
|
99
118
|
}
|
|
100
119
|
routeDependencies(routeData) {
|
|
101
|
-
|
|
120
|
+
const dependencies = [];
|
|
121
|
+
const visited = new Set([routeData.moduleName]);
|
|
102
122
|
let data = routeData;
|
|
103
123
|
while (data && data.dependency) {
|
|
124
|
+
if (visited.has(data.dependency)) {
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
visited.add(data.dependency);
|
|
104
128
|
dependencies.push(data.dependency);
|
|
105
129
|
data = this.routeDataSet.get(data.dependency);
|
|
106
130
|
}
|
|
@@ -109,51 +133,74 @@ class Router {
|
|
|
109
133
|
async processRoute(graph, target) {
|
|
110
134
|
const handler = this.handlers.get(graph.layout);
|
|
111
135
|
if (!handler) {
|
|
112
|
-
return false;
|
|
136
|
+
return [false, { ok: false, code: 'invalid_action' }];
|
|
113
137
|
}
|
|
114
|
-
const [consumed, childGraph] = await handler.process(graph, target);
|
|
138
|
+
const [consumed, childGraph, result] = await handler.process(graph, target);
|
|
115
139
|
if (consumed && childGraph) {
|
|
116
140
|
return await this.processRoute(childGraph, target);
|
|
117
141
|
}
|
|
118
|
-
return consumed;
|
|
142
|
+
return [consumed, result ?? { ok: true, code: 'ok' }];
|
|
119
143
|
}
|
|
120
|
-
|
|
144
|
+
open(path, props = {}, options = {}) {
|
|
145
|
+
const task = this.openQueue.then(() => this.performOpen(path, props, options), () => this.performOpen(path, props, options));
|
|
146
|
+
this.openQueue = task.then(() => undefined, () => undefined);
|
|
147
|
+
return task;
|
|
148
|
+
}
|
|
149
|
+
hasDrawerLayout(graph) {
|
|
150
|
+
if (graph.layout === 'drawer') {
|
|
151
|
+
return true;
|
|
152
|
+
}
|
|
153
|
+
if (!graph.children) {
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
return graph.children.some(child => this.hasDrawerLayout(child));
|
|
157
|
+
}
|
|
158
|
+
async performOpen(path, props, options) {
|
|
121
159
|
this.inflateRouteData();
|
|
122
160
|
const intercepted = await this.intercept(path);
|
|
123
161
|
if (intercepted) {
|
|
124
|
-
return;
|
|
162
|
+
return { ok: false, code: 'intercepted' };
|
|
125
163
|
}
|
|
126
164
|
const route = this.pathToRoute(path, props, options);
|
|
127
165
|
if (!route) {
|
|
128
|
-
return
|
|
166
|
+
return {
|
|
167
|
+
ok: false,
|
|
168
|
+
code: 'scene_not_found',
|
|
169
|
+
message: `No route matched path: ${path}`,
|
|
170
|
+
};
|
|
129
171
|
}
|
|
130
|
-
const
|
|
131
|
-
if (
|
|
132
|
-
|
|
133
|
-
const { mode: layoutMode } = graphArray[index];
|
|
134
|
-
const { sceneId, moduleName } = await Navigation.currentRoute();
|
|
135
|
-
if (layoutMode === 'present') {
|
|
136
|
-
await Navigation.dispatch(sceneId, 'dismiss', {
|
|
137
|
-
from: moduleName,
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
else if (layoutMode === 'modal') {
|
|
141
|
-
await Navigation.dispatch(sceneId, 'hideModal', {
|
|
142
|
-
from: moduleName,
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
else {
|
|
146
|
-
console.warn('尚未处理的 layout mode:' + layoutMode);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
172
|
+
const dismissed = await dismissPresentedLayers(Navigation);
|
|
173
|
+
if (!dismissed.ok) {
|
|
174
|
+
return dismissed;
|
|
149
175
|
}
|
|
176
|
+
const graphArray = dismissed.layers;
|
|
150
177
|
const routeGraph = graphArray[0];
|
|
151
|
-
|
|
178
|
+
if (!routeGraph) {
|
|
179
|
+
return {
|
|
180
|
+
ok: false,
|
|
181
|
+
code: 'not_ready',
|
|
182
|
+
message: 'Root route graph is missing.',
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
const [consumed, routeResult] = await this.processRoute(routeGraph, route);
|
|
152
186
|
if (consumed) {
|
|
153
|
-
return;
|
|
187
|
+
return routeResult;
|
|
188
|
+
}
|
|
189
|
+
const currentRoute = await Navigation.currentRoute();
|
|
190
|
+
if (!currentRoute) {
|
|
191
|
+
return {
|
|
192
|
+
ok: false,
|
|
193
|
+
code: 'scene_not_found',
|
|
194
|
+
message: 'Unable to resolve current route.',
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
const { sceneId, moduleName: from } = currentRoute;
|
|
198
|
+
if (this.hasDrawerLayout(routeGraph)) {
|
|
199
|
+
const closeMenuResult = await Navigation.dispatch(sceneId, 'closeMenu', { from });
|
|
200
|
+
if (closeMenuResult.code === 'intercepted') {
|
|
201
|
+
return closeMenuResult;
|
|
202
|
+
}
|
|
154
203
|
}
|
|
155
|
-
const { sceneId, moduleName: from } = await Navigation.currentRoute();
|
|
156
|
-
Navigation.dispatch(sceneId, 'closeMenu', { from });
|
|
157
204
|
const { moduleName, mode: routeMode, props: initialProps } = route;
|
|
158
205
|
let action = 'push';
|
|
159
206
|
if (routeMode === 'present') {
|
|
@@ -162,9 +209,10 @@ class Router {
|
|
|
162
209
|
else if (routeMode === 'modal') {
|
|
163
210
|
action = 'showModal';
|
|
164
211
|
}
|
|
165
|
-
Navigation.dispatch(sceneId, action, {
|
|
212
|
+
return await Navigation.dispatch(sceneId, action, {
|
|
166
213
|
moduleName,
|
|
167
214
|
props: initialProps,
|
|
215
|
+
options: route.options,
|
|
168
216
|
from,
|
|
169
217
|
to: moduleName,
|
|
170
218
|
});
|
package/dist/router/screen.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LayoutMode, RouteGraph, RouteHandler, RouteInfo } from '../Route';
|
|
1
|
+
import { LayoutMode, RouteGraph, RouteHandler, RouteHandleResult, RouteInfo } from '../Route';
|
|
2
2
|
export interface ScreenGraph extends RouteGraph {
|
|
3
3
|
layout: 'screen';
|
|
4
4
|
sceneId: string;
|
|
@@ -8,5 +8,5 @@ export interface ScreenGraph extends RouteGraph {
|
|
|
8
8
|
export declare function isScreenGraph(graph: RouteGraph): graph is ScreenGraph;
|
|
9
9
|
export declare function isTargetLocateIn(graph: RouteGraph, target: RouteInfo): boolean;
|
|
10
10
|
export declare class ScreenRouteHandler implements RouteHandler {
|
|
11
|
-
process(graph: RouteGraph, target: RouteInfo): Promise<
|
|
11
|
+
process(graph: RouteGraph, target: RouteInfo): Promise<RouteHandleResult>;
|
|
12
12
|
}
|
package/dist/router/screen.js
CHANGED
|
@@ -25,7 +25,7 @@ export class ScreenRouteHandler {
|
|
|
25
25
|
throw new Error(`${graph} is Not a ScreenGraph`);
|
|
26
26
|
}
|
|
27
27
|
if (graph.moduleName === target.moduleName) {
|
|
28
|
-
return Promise.resolve([true, null]);
|
|
28
|
+
return Promise.resolve([true, null, { ok: true, code: 'ok' }]);
|
|
29
29
|
}
|
|
30
30
|
return Promise.resolve([false, graph]);
|
|
31
31
|
}
|
package/dist/router/stack.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LayoutMode, RouteGraph, RouteHandler, RouteInfo } from '../Route';
|
|
1
|
+
import { LayoutMode, RouteGraph, RouteHandler, RouteHandleResult, RouteInfo } from '../Route';
|
|
2
2
|
export interface StackGraph extends RouteGraph {
|
|
3
3
|
layout: 'stack';
|
|
4
4
|
sceneId: string;
|
|
@@ -7,7 +7,7 @@ export interface StackGraph extends RouteGraph {
|
|
|
7
7
|
}
|
|
8
8
|
export declare function isStackGraph(graph: RouteGraph): graph is StackGraph;
|
|
9
9
|
export declare class StackRouteHandler implements RouteHandler {
|
|
10
|
-
process(graph: RouteGraph, target: RouteInfo): Promise<
|
|
10
|
+
process(graph: RouteGraph, target: RouteInfo): Promise<RouteHandleResult>;
|
|
11
11
|
private popToIfNeeded;
|
|
12
12
|
private navigateTo;
|
|
13
13
|
}
|
package/dist/router/stack.js
CHANGED
|
@@ -13,10 +13,13 @@ export class StackRouteHandler {
|
|
|
13
13
|
const childGraph = children[i];
|
|
14
14
|
if (isTargetLocateIn(childGraph, target)) {
|
|
15
15
|
if (isScreenGraph(childGraph)) {
|
|
16
|
-
this.navigateTo(childGraph, target);
|
|
17
|
-
return [true, null];
|
|
16
|
+
const result = await this.navigateTo(childGraph, target, i === children.length - 1);
|
|
17
|
+
return [true, null, result];
|
|
18
|
+
}
|
|
19
|
+
const popResult = await this.popToIfNeeded(childGraph, i === children.length - 1);
|
|
20
|
+
if (!popResult.ok) {
|
|
21
|
+
return [true, null, popResult];
|
|
18
22
|
}
|
|
19
|
-
await this.popToIfNeeded(childGraph, i === children.length - 1);
|
|
20
23
|
return [true, childGraph];
|
|
21
24
|
}
|
|
22
25
|
}
|
|
@@ -24,55 +27,81 @@ export class StackRouteHandler {
|
|
|
24
27
|
}
|
|
25
28
|
async popToIfNeeded(childGraph, isLastChildAtStack) {
|
|
26
29
|
if (!isLastChildAtStack) {
|
|
27
|
-
await Navigation.dispatch(childGraph.sceneId, 'popTo', {
|
|
30
|
+
return await Navigation.dispatch(childGraph.sceneId, 'popTo', {
|
|
28
31
|
moduleName: childGraph.sceneId,
|
|
29
32
|
});
|
|
30
33
|
}
|
|
34
|
+
return { ok: true, code: 'ok' };
|
|
31
35
|
}
|
|
32
|
-
navigateTo(childGraph, target) {
|
|
33
|
-
const { moduleName, dependencies, props } = target;
|
|
36
|
+
async navigateTo(childGraph, target, isLastChildAtStack) {
|
|
37
|
+
const { moduleName, dependencies, props, options } = target;
|
|
34
38
|
const expectations = [...dependencies, moduleName];
|
|
35
39
|
const index = expectations.findIndex(name => name === childGraph.moduleName);
|
|
36
40
|
const pendings = expectations.slice(index + 1);
|
|
37
|
-
console.log('pendings', pendings, 'moduleName', childGraph.moduleName);
|
|
38
41
|
const sceneId = childGraph.sceneId;
|
|
39
42
|
const moduleExisting = pendings.length === 0;
|
|
40
43
|
if (moduleExisting) {
|
|
41
|
-
|
|
42
|
-
|
|
44
|
+
const hasProps = props && Object.keys(props).length > 0;
|
|
45
|
+
const hasOptions = options && Object.keys(options).length > 0;
|
|
46
|
+
if (!hasProps && !hasOptions) {
|
|
47
|
+
if (!isLastChildAtStack) {
|
|
48
|
+
return await Navigation.dispatch(sceneId, 'popTo', {
|
|
49
|
+
moduleName,
|
|
50
|
+
from: childGraph.moduleName,
|
|
51
|
+
to: moduleName,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
return { ok: true, code: 'ok' };
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
return await Navigation.dispatch(sceneId, 'redirectTo', {
|
|
43
58
|
moduleName,
|
|
44
59
|
from: childGraph.moduleName,
|
|
45
60
|
to: moduleName,
|
|
61
|
+
props,
|
|
62
|
+
options,
|
|
46
63
|
});
|
|
47
64
|
}
|
|
48
|
-
|
|
49
|
-
|
|
65
|
+
}
|
|
66
|
+
const popResult = await this.popToIfNeeded(childGraph, isLastChildAtStack);
|
|
67
|
+
if (!popResult.ok) {
|
|
68
|
+
return popResult;
|
|
69
|
+
}
|
|
70
|
+
const finalAction = target.mode === 'present'
|
|
71
|
+
? 'present'
|
|
72
|
+
: target.mode === 'modal'
|
|
73
|
+
? 'showModal'
|
|
74
|
+
: 'push';
|
|
75
|
+
let currentSceneId = sceneId;
|
|
76
|
+
let fromModule = childGraph.moduleName;
|
|
77
|
+
let lastResult = { ok: true, code: 'ok' };
|
|
78
|
+
for (let i = 0; i < pendings.length; i++) {
|
|
79
|
+
const isLast = i === pendings.length - 1;
|
|
80
|
+
const targetModule = isLast ? moduleName : pendings[i];
|
|
81
|
+
lastResult = isLast
|
|
82
|
+
? await Navigation.dispatch(currentSceneId, finalAction, {
|
|
50
83
|
moduleName,
|
|
51
|
-
from:
|
|
84
|
+
from: fromModule,
|
|
52
85
|
to: moduleName,
|
|
53
86
|
props,
|
|
87
|
+
options,
|
|
88
|
+
})
|
|
89
|
+
: await Navigation.dispatch(currentSceneId, 'push', {
|
|
90
|
+
moduleName: targetModule,
|
|
91
|
+
from: fromModule,
|
|
92
|
+
to: targetModule,
|
|
54
93
|
});
|
|
94
|
+
if (!lastResult.ok) {
|
|
95
|
+
return lastResult;
|
|
55
96
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
Navigation.dispatch(sceneId, 'push', {
|
|
62
|
-
moduleName,
|
|
63
|
-
from: childGraph.moduleName,
|
|
64
|
-
to: moduleName,
|
|
65
|
-
props,
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
Navigation.dispatch(sceneId, 'push', {
|
|
70
|
-
moduleName: pendings[i],
|
|
71
|
-
from: childGraph.moduleName,
|
|
72
|
-
to: pendings[i],
|
|
73
|
-
});
|
|
97
|
+
fromModule = targetModule;
|
|
98
|
+
if (!isLast) {
|
|
99
|
+
const current = await Navigation.currentRoute();
|
|
100
|
+
if (current?.sceneId) {
|
|
101
|
+
currentSceneId = current.sceneId;
|
|
74
102
|
}
|
|
75
103
|
}
|
|
76
104
|
}
|
|
105
|
+
return lastResult;
|
|
77
106
|
}
|
|
78
107
|
}
|
package/dist/router/tabs.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { LayoutMode, RouteGraph, RouteHandler, RouteInfo } from '../Route';
|
|
1
|
+
import { LayoutMode, RouteGraph, RouteHandler, RouteHandleResult, RouteInfo } from '../Route';
|
|
2
2
|
export interface TabsGraph extends RouteGraph {
|
|
3
3
|
layout: 'tabs';
|
|
4
4
|
sceneId: string;
|
|
5
5
|
selectedIndex: number;
|
|
6
|
+
tabKeys?: Array<string | null>;
|
|
6
7
|
mode: LayoutMode;
|
|
7
8
|
children: RouteGraph[];
|
|
8
9
|
}
|
|
9
10
|
export declare function isTabsGraph(graph: RouteGraph): graph is TabsGraph;
|
|
10
11
|
export declare class TabsRouteHandler implements RouteHandler {
|
|
11
|
-
process(graph: RouteGraph, target: RouteInfo): Promise<
|
|
12
|
+
process(graph: RouteGraph, target: RouteInfo): Promise<RouteHandleResult>;
|
|
12
13
|
}
|
package/dist/router/tabs.js
CHANGED
|
@@ -12,11 +12,14 @@ export class TabsRouteHandler {
|
|
|
12
12
|
for (let i = 0; i < children.length; i++) {
|
|
13
13
|
if (isTargetLocateIn(children[i], target)) {
|
|
14
14
|
if (selectedIndex !== i) {
|
|
15
|
-
await Navigation.dispatch(children[selectedIndex].sceneId, 'switchTab', {
|
|
15
|
+
const result = await Navigation.dispatch(children[selectedIndex].sceneId, 'switchTab', {
|
|
16
16
|
from: selectedIndex,
|
|
17
17
|
to: i,
|
|
18
18
|
popToRoot: true,
|
|
19
19
|
});
|
|
20
|
+
if (!result.ok) {
|
|
21
|
+
return [true, null, result];
|
|
22
|
+
}
|
|
20
23
|
}
|
|
21
24
|
return [true, children[i]];
|
|
22
25
|
}
|
package/dist/store.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { Navigator } from './Navigator';
|
|
1
|
+
import type { Navigator } from './Navigator';
|
|
2
2
|
declare function addNavigator(sceneId: string, navigator: Navigator): void;
|
|
3
3
|
declare function removeNavigator(sceneId: string): void;
|
|
4
|
-
declare function getNavigator(sceneId: string): Navigator | undefined;
|
|
4
|
+
declare function getNavigator(sceneId: string): Navigator<string> | undefined;
|
|
5
|
+
declare function clear(): void;
|
|
5
6
|
declare const _default: {
|
|
6
7
|
addNavigator: typeof addNavigator;
|
|
7
8
|
removeNavigator: typeof removeNavigator;
|
|
8
9
|
getNavigator: typeof getNavigator;
|
|
10
|
+
clear: typeof clear;
|
|
9
11
|
};
|
|
10
12
|
export default _default;
|
package/dist/store.js
CHANGED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { TabItemInfo } from './Options';
|
|
2
|
+
import type { DispatchResult, LayoutMode, LeaveAction, ResultMap, Route, RouteGraph, SceneLifecycleState, TabPressEvent } from './Route';
|
|
3
|
+
import type { ResultEvent, Spec as NativeEventSpec } from './NativeEvent';
|
|
4
|
+
import type { Spec as NativeNavigationSpec } from './NativeNavigation';
|
|
5
|
+
import type { DispatchParams } from './handler/DispatchCommandHandler';
|
|
6
|
+
import type { Navigator } from './Navigator';
|
|
7
|
+
export interface MockNavigationOptions {
|
|
8
|
+
defaultSceneId?: string;
|
|
9
|
+
defaultModuleName?: string;
|
|
10
|
+
onDispatch?: (sceneId: string, action: string, params: DispatchParams) => DispatchResult | Promise<DispatchResult>;
|
|
11
|
+
onSetResult?: (sceneId: string, resultCode: number, data: ResultMap | null) => void;
|
|
12
|
+
}
|
|
13
|
+
export interface MockNavigationController {
|
|
14
|
+
readonly dispatchCalls: ReadonlyArray<{
|
|
15
|
+
sceneId: string;
|
|
16
|
+
action: string;
|
|
17
|
+
params: DispatchParams;
|
|
18
|
+
}>;
|
|
19
|
+
readonly setResultCalls: ReadonlyArray<{
|
|
20
|
+
sceneId: string;
|
|
21
|
+
resultCode: number;
|
|
22
|
+
data: ResultMap | null;
|
|
23
|
+
}>;
|
|
24
|
+
readonly tabItemCalls: ReadonlyArray<{
|
|
25
|
+
sceneId: string;
|
|
26
|
+
items: TabItemInfo[];
|
|
27
|
+
}>;
|
|
28
|
+
readonly beforeRemoveEnabled: ReadonlySet<string>;
|
|
29
|
+
setCurrentRoute(route: Route | null): void;
|
|
30
|
+
setRouteGraph(layers: RouteGraph[]): void;
|
|
31
|
+
setOnDispatch(fn: MockNavigationOptions['onDispatch']): void;
|
|
32
|
+
setOnSetResult(fn: MockNavigationOptions['onSetResult']): void;
|
|
33
|
+
emitSceneState(event: {
|
|
34
|
+
sceneId: string;
|
|
35
|
+
state: SceneLifecycleState;
|
|
36
|
+
prevState?: SceneLifecycleState;
|
|
37
|
+
moduleName?: string;
|
|
38
|
+
mode?: LayoutMode;
|
|
39
|
+
presentingId?: string | null;
|
|
40
|
+
}): void;
|
|
41
|
+
emitResult(event: ResultEvent): void;
|
|
42
|
+
emitBeforeRemove(sceneId: string, action?: LeaveAction): void;
|
|
43
|
+
emitTabPress(event: TabPressEvent): void;
|
|
44
|
+
emitRootReset(): void;
|
|
45
|
+
getNavigator(sceneId: string): Navigator;
|
|
46
|
+
reset(): void;
|
|
47
|
+
}
|
|
48
|
+
export declare const mockNativeEvent: NativeEventSpec;
|
|
49
|
+
export declare const mockNativeNavigation: NativeNavigationSpec;
|
|
50
|
+
export interface MockNavigationModule {
|
|
51
|
+
readonly __esModule: true;
|
|
52
|
+
readonly default: import('./Navigation').Navigation;
|
|
53
|
+
readonly Navigator: typeof import('./Navigator').Navigator;
|
|
54
|
+
readonly NavigationContext: typeof import('./Navigator').NavigationContext;
|
|
55
|
+
readonly RESULT_OK: number;
|
|
56
|
+
readonly RESULT_CANCEL: number;
|
|
57
|
+
readonly RESULT_BLOCK: number;
|
|
58
|
+
readonly useNavigator: typeof import('./hooks').useNavigator;
|
|
59
|
+
readonly useSceneState: typeof import('./hooks').useSceneState;
|
|
60
|
+
readonly useIsVisible: typeof import('./hooks').useIsVisible;
|
|
61
|
+
readonly useBeforeRemove: typeof import('./hooks').useBeforeRemove;
|
|
62
|
+
readonly useVisibleEffect: typeof import('./hooks').useVisibleEffect;
|
|
63
|
+
readonly withNavigationItem: typeof import('./NavigationComponentWrap').withNavigationItem;
|
|
64
|
+
readonly defineRoute: typeof import('./defineRoutes').defineRoute;
|
|
65
|
+
readonly defineRoutes: typeof import('./defineRoutes').defineRoutes;
|
|
66
|
+
readonly containsScene: typeof import('./routeGraph').containsScene;
|
|
67
|
+
readonly findSceneInGraph: typeof import('./routeGraph').findSceneInGraph;
|
|
68
|
+
readonly findTabIndex: typeof import('./routeGraph').findTabIndex;
|
|
69
|
+
readonly findTabsGraph: typeof import('./routeGraph').findTabsGraph;
|
|
70
|
+
readonly dismissPresentedLayers: typeof import('./reveal').dismissPresentedLayers;
|
|
71
|
+
readonly executeReveal: typeof import('./reveal').executeReveal;
|
|
72
|
+
readonly __mock: MockNavigationController;
|
|
73
|
+
readonly [key: string]: any;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Thin test harness that mocks only the two native TurboModule boundaries
|
|
77
|
+
* (`HBDNativeNavigation` and `HBDNativeEvent`) and runs the real JS navigation layer on top.
|
|
78
|
+
*/
|
|
79
|
+
export declare function createMockNavigation(options?: MockNavigationOptions): MockNavigationModule;
|