hybrid-navigation 4.0.8 → 5.0.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 +5 -4
- package/android/proguard-rules.pro +3 -0
- package/android/src/main/java/com/navigation/androidx/AwesomeActivity.java +114 -23
- package/android/src/main/java/com/navigation/androidx/AwesomeFragment.java +116 -13
- package/android/src/main/java/com/navigation/androidx/DrawableUtils.java +83 -18
- package/android/src/main/java/com/navigation/androidx/DrawerFragment.java +192 -28
- package/android/src/main/java/com/navigation/androidx/FragmentHelper.java +11 -0
- package/android/src/main/java/com/navigation/androidx/HybridDrawerLayout.java +563 -143
- package/android/src/main/java/com/navigation/androidx/LifecycleDelegate.java +47 -15
- package/android/src/main/java/com/navigation/androidx/PresentableActivity.java +3 -0
- package/android/src/main/java/com/navigation/androidx/PresentationDelegate.java +8 -3
- package/android/src/main/java/com/navigation/androidx/StackDelegate.java +29 -9
- package/android/src/main/java/com/navigation/androidx/StackFragment.java +28 -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 +24 -7
- package/android/src/main/java/com/navigation/androidx/TabView.java +11 -2
- package/android/src/main/java/com/reactnative/hybridnavigation/DispatchResult.java +59 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/Garden.java +18 -10
- package/android/src/main/java/com/reactnative/hybridnavigation/GlobalStyle.java +15 -2
- package/android/src/main/java/com/reactnative/hybridnavigation/HBDRootView.java +3 -8
- package/android/src/main/java/com/reactnative/hybridnavigation/HybridFragment.java +113 -6
- 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 +196 -194
- package/android/src/main/java/com/reactnative/hybridnavigation/NavigationCommandQueue.java +499 -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 +50 -87
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactManager.java +156 -77
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactStackFragment.java +6 -6
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactSurfaceCleanup.java +3 -1
- 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 +62 -22
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/StackNavigator.java +35 -16
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/TabNavigator.java +16 -13
- package/dist/DeepLink.d.ts +3 -2
- package/dist/DeepLink.js +37 -14
- package/dist/NativeEvent.d.ts +4 -12
- package/dist/NativeNavigation.d.ts +17 -19
- package/dist/Navigation.d.ts +21 -19
- package/dist/Navigation.js +83 -89
- package/dist/NavigationComponentWrap.d.ts +4 -3
- package/dist/NavigationComponentWrap.js +3 -6
- package/dist/Navigator.d.ts +31 -42
- package/dist/Navigator.js +97 -90
- package/dist/Options.d.ts +3 -1
- package/dist/Route.d.ts +85 -18
- package/dist/handler/DispatchCommandHandler.d.ts +10 -6
- package/dist/handler/DispatchCommandHandler.js +41 -17
- package/dist/handler/LayoutCommandHandler.d.ts +7 -7
- package/dist/handler/LayoutCommandHandler.js +21 -15
- package/dist/handler/LifecycleEventHandler.d.ts +26 -0
- package/dist/handler/LifecycleEventHandler.js +136 -0
- package/dist/handler/ResultEventHandler.d.ts +14 -9
- package/dist/handler/ResultEventHandler.js +88 -13
- package/dist/hooks.d.ts +5 -2
- package/dist/hooks.js +26 -4
- package/dist/index.d.ts +13 -0
- package/dist/index.js +0 -2
- package/dist/routeConfigRegistry.d.ts +6 -0
- package/dist/routeConfigRegistry.js +19 -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 +127 -43
- 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 +2 -2
- package/dist/router/tabs.js +4 -1
- package/dist/store.d.ts +2 -2
- package/ios/HBDGlobalStyle.h +26 -0
- package/ios/{GlobalStyle.mm → HBDGlobalStyle.mm} +30 -27
- package/ios/HybridNavigation.h +4 -1
- package/ios/Navigator/HBDDrawerNavigator.mm +24 -8
- package/ios/Navigator/HBDNavigatorRegistry.mm +1 -0
- package/ios/Navigator/HBDScreenNavigator.mm +106 -52
- package/ios/Navigator/HBDStackNavigator.mm +109 -61
- package/ios/Navigator/HBDTabNavigator.mm +32 -14
- package/ios/React/HBDNativeNavigation.mm +109 -131
- package/ios/React/HBDNavigator.h +29 -5
- package/ios/React/HBDOrientationCoordinator.h +27 -0
- package/ios/React/HBDOrientationCoordinator.mm +282 -0
- package/ios/React/HBDReactBridgeManager.h +37 -19
- package/ios/React/HBDReactBridgeManager.mm +490 -96
- 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 +127 -6
- package/ios/ViewController/HBDNavigationController.mm +17 -4
- package/ios/ViewController/HBDReactViewController.mm +59 -121
- package/ios/ViewController/HBDTabBarController.h +4 -0
- package/ios/ViewController/HBDTabBarController.mm +59 -44
- package/ios/ViewController/HBDViewController.h +10 -3
- package/ios/ViewController/HBDViewController.mm +161 -147
- package/ios/ViewController/UINavigationController+HBD.h +2 -2
- package/ios/ViewController/UINavigationController+HBD.mm +3 -3
- package/ios/ViewController/UIViewController+HBD.h +17 -10
- package/ios/ViewController/UIViewController+HBD.mm +85 -69
- package/package.json +1 -1
- package/src/DeepLink.ts +41 -14
- package/src/NativeEvent.ts +4 -14
- package/src/NativeNavigation.ts +22 -33
- package/src/Navigation.ts +162 -121
- package/src/NavigationComponentWrap.tsx +9 -9
- package/src/Navigator.ts +191 -153
- package/src/Options.ts +3 -1
- package/src/Route.ts +134 -19
- package/src/handler/DispatchCommandHandler.ts +55 -21
- package/src/handler/LayoutCommandHandler.ts +36 -17
- package/src/handler/LifecycleEventHandler.ts +172 -0
- package/src/handler/ResultEventHandler.ts +112 -19
- package/src/hooks.ts +39 -7
- package/src/index.ts +26 -2
- package/src/routeConfigRegistry.ts +26 -0
- package/src/router/drawer.ts +8 -5
- package/src/router/index.ts +161 -50
- package/src/router/screen.ts +3 -3
- package/src/router/stack.ts +80 -29
- package/src/router/tabs.ts +15 -7
- package/src/store.ts +1 -1
- 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/src/router/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { pathToRegexp, match } from 'path-to-regexp';
|
|
1
|
+
import { pathToRegexp, match, MatchFunction } from 'path-to-regexp';
|
|
2
2
|
import {
|
|
3
|
+
DispatchResult,
|
|
3
4
|
RouteConfig,
|
|
4
5
|
RouteData,
|
|
5
6
|
RouteGraph,
|
|
@@ -14,24 +15,36 @@ import { TabsRouteHandler } from './tabs';
|
|
|
14
15
|
import { DrawerRouteHandler } from './drawer';
|
|
15
16
|
|
|
16
17
|
import Navigation from '../Navigation';
|
|
18
|
+
import type { NavigationSubscription } from '../Navigation';
|
|
19
|
+
import { getRouteConfigs, getRouteConfigVersion } from '../routeConfigRegistry';
|
|
17
20
|
|
|
18
21
|
interface IndexType {
|
|
19
22
|
[index: string]: any;
|
|
20
23
|
}
|
|
21
24
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
interface CompiledRouteData extends RouteData {
|
|
26
|
+
matcher?: MatchFunction<IndexType>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function safeDecodeURIComponent(value: string) {
|
|
30
|
+
try {
|
|
31
|
+
return decodeURIComponent(value);
|
|
32
|
+
} catch {
|
|
33
|
+
return value;
|
|
34
|
+
}
|
|
27
35
|
}
|
|
28
36
|
|
|
29
37
|
function queryParams(queryString: string) {
|
|
30
38
|
return (queryString || '').split('&').reduce((result: IndexType, item: string) => {
|
|
31
39
|
if (item !== '') {
|
|
32
40
|
const nextResult = result || {};
|
|
33
|
-
const
|
|
34
|
-
|
|
41
|
+
const separatorIndex = item.indexOf('=');
|
|
42
|
+
const rawKey = separatorIndex >= 0 ? item.slice(0, separatorIndex) : item;
|
|
43
|
+
const rawValue = separatorIndex >= 0 ? item.slice(separatorIndex + 1) : '';
|
|
44
|
+
const key = safeDecodeURIComponent(rawKey);
|
|
45
|
+
if (key) {
|
|
46
|
+
nextResult[key] = safeDecodeURIComponent(rawValue);
|
|
47
|
+
}
|
|
35
48
|
return nextResult;
|
|
36
49
|
}
|
|
37
50
|
return result;
|
|
@@ -47,33 +60,41 @@ class Router {
|
|
|
47
60
|
}
|
|
48
61
|
|
|
49
62
|
private handlers = new Map<string, RouteHandler>();
|
|
63
|
+
private openQueue: Promise<unknown> = Promise.resolve();
|
|
50
64
|
|
|
51
65
|
registerRouteHandler(layout: string, handler: RouteHandler) {
|
|
52
66
|
this.handlers.set(layout, handler);
|
|
53
67
|
}
|
|
54
68
|
|
|
55
|
-
private convertConfigToData(moduleName: string, route: RouteConfig) {
|
|
69
|
+
private convertConfigToData(moduleName: string, route: RouteConfig): CompiledRouteData {
|
|
56
70
|
let { path, dependency, mode } = route;
|
|
57
71
|
let regexp: RegExp | undefined;
|
|
72
|
+
let matcher: MatchFunction<IndexType> | undefined;
|
|
58
73
|
if (path) {
|
|
59
74
|
if (!path.startsWith('/')) {
|
|
60
|
-
|
|
75
|
+
path = '/' + path;
|
|
76
|
+
route.path = path;
|
|
61
77
|
}
|
|
62
78
|
regexp = pathToRegexp(path).regexp;
|
|
79
|
+
matcher = match<IndexType>(path, {
|
|
80
|
+
decode: safeDecodeURIComponent,
|
|
81
|
+
});
|
|
63
82
|
}
|
|
64
83
|
mode = mode || 'push';
|
|
65
|
-
return { moduleName, mode, path, regexp, dependency };
|
|
84
|
+
return { moduleName, mode, path, regexp, matcher, dependency };
|
|
66
85
|
}
|
|
67
86
|
|
|
68
|
-
private
|
|
69
|
-
private routeDataSet = new Map<string,
|
|
87
|
+
private inflatedRouteConfigVersion = -1;
|
|
88
|
+
private routeDataSet = new Map<string, CompiledRouteData>();
|
|
70
89
|
|
|
71
90
|
private inflateRouteData() {
|
|
72
|
-
|
|
91
|
+
const currentVersion = getRouteConfigVersion();
|
|
92
|
+
if (this.inflatedRouteConfigVersion === currentVersion) {
|
|
73
93
|
return;
|
|
74
94
|
}
|
|
75
|
-
this.
|
|
76
|
-
|
|
95
|
+
this.inflatedRouteConfigVersion = currentVersion;
|
|
96
|
+
this.routeDataSet.clear();
|
|
97
|
+
const routeConfigs = getRouteConfigs();
|
|
77
98
|
for (const [moduleName, config] of routeConfigs) {
|
|
78
99
|
const data = this.convertConfigToData(moduleName, config);
|
|
79
100
|
this.routeDataSet.set(moduleName, data);
|
|
@@ -82,8 +103,11 @@ class Router {
|
|
|
82
103
|
|
|
83
104
|
private interceptors: RouteInterceptor[] = [];
|
|
84
105
|
|
|
85
|
-
addInterceptor(interceptor: RouteInterceptor) {
|
|
106
|
+
addInterceptor(interceptor: RouteInterceptor): NavigationSubscription {
|
|
86
107
|
this.interceptors.push(interceptor);
|
|
108
|
+
return {
|
|
109
|
+
remove: () => this.removeInterceptor(interceptor),
|
|
110
|
+
};
|
|
87
111
|
}
|
|
88
112
|
|
|
89
113
|
removeInterceptor(interceptor: RouteInterceptor) {
|
|
@@ -91,9 +115,9 @@ class Router {
|
|
|
91
115
|
}
|
|
92
116
|
|
|
93
117
|
private async intercept(path: string) {
|
|
94
|
-
for (
|
|
118
|
+
for (const interceptor of this.interceptors.slice()) {
|
|
95
119
|
const result = interceptor(path);
|
|
96
|
-
const intercepted = await
|
|
120
|
+
const intercepted = result instanceof Promise ? await result : result;
|
|
97
121
|
if (intercepted) {
|
|
98
122
|
return true;
|
|
99
123
|
}
|
|
@@ -101,101 +125,186 @@ class Router {
|
|
|
101
125
|
return false;
|
|
102
126
|
}
|
|
103
127
|
|
|
104
|
-
private resolveInterceptResult(result: boolean | Promise<boolean>) {
|
|
105
|
-
if (result instanceof Promise) {
|
|
106
|
-
return result;
|
|
107
|
-
}
|
|
108
|
-
return Promise.resolve(result);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
128
|
private pathToRoute(
|
|
112
129
|
path: string,
|
|
113
130
|
props: object,
|
|
114
131
|
options: NavigationItem,
|
|
115
132
|
): RouteInfo | undefined {
|
|
133
|
+
const withoutHash = path.split('#')[0];
|
|
134
|
+
const queryIndex = withoutHash.indexOf('?');
|
|
135
|
+
const rawPathName = queryIndex >= 0 ? withoutHash.slice(0, queryIndex) : withoutHash;
|
|
136
|
+
const queryString = queryIndex >= 0 ? withoutHash.slice(queryIndex + 1) : '';
|
|
137
|
+
const pathName = rawPathName.startsWith('/') ? rawPathName : '/' + rawPathName;
|
|
138
|
+
|
|
116
139
|
for (const data of this.routeDataSet.values()) {
|
|
117
|
-
if (!data.
|
|
140
|
+
if (!data.matcher) {
|
|
118
141
|
continue;
|
|
119
142
|
}
|
|
120
143
|
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
if (data.regexp.exec(pathName)) {
|
|
144
|
+
const matched = data.matcher(pathName);
|
|
145
|
+
if (matched) {
|
|
124
146
|
const moduleName = data.moduleName;
|
|
125
|
-
const params =
|
|
147
|
+
const params = matched.params || {};
|
|
126
148
|
const query = queryParams(queryString);
|
|
127
|
-
|
|
149
|
+
const mergedProps = { ...query, ...params, ...props };
|
|
128
150
|
const dependencies = this.routeDependencies(data);
|
|
129
151
|
const mode = data.mode;
|
|
130
|
-
return { moduleName, props, dependencies, mode, options };
|
|
152
|
+
return { moduleName, props: mergedProps, dependencies, mode, options };
|
|
131
153
|
}
|
|
132
154
|
}
|
|
133
155
|
}
|
|
134
156
|
|
|
135
157
|
private routeDependencies(routeData: RouteData) {
|
|
136
|
-
|
|
158
|
+
const dependencies: string[] = [];
|
|
159
|
+
const visited = new Set<string>([routeData.moduleName]);
|
|
137
160
|
let data: RouteData | undefined = routeData;
|
|
138
161
|
while (data && data.dependency) {
|
|
162
|
+
if (visited.has(data.dependency)) {
|
|
163
|
+
break;
|
|
164
|
+
}
|
|
165
|
+
visited.add(data.dependency);
|
|
139
166
|
dependencies.push(data.dependency);
|
|
140
167
|
data = this.routeDataSet.get(data.dependency);
|
|
141
168
|
}
|
|
142
169
|
return dependencies.reverse();
|
|
143
170
|
}
|
|
144
171
|
|
|
145
|
-
private async processRoute(
|
|
172
|
+
private async processRoute(
|
|
173
|
+
graph: RouteGraph,
|
|
174
|
+
target: RouteInfo,
|
|
175
|
+
): Promise<[boolean, DispatchResult]> {
|
|
146
176
|
const handler = this.handlers.get(graph.layout);
|
|
147
177
|
if (!handler) {
|
|
148
|
-
return false;
|
|
178
|
+
return [false, { ok: false, code: 'invalid_action' }];
|
|
149
179
|
}
|
|
150
180
|
|
|
151
|
-
const [consumed, childGraph] = await handler.process(graph, target);
|
|
181
|
+
const [consumed, childGraph, result] = await handler.process(graph, target);
|
|
152
182
|
if (consumed && childGraph) {
|
|
153
183
|
return await this.processRoute(childGraph, target);
|
|
154
184
|
}
|
|
155
|
-
return consumed;
|
|
185
|
+
return [consumed, result ?? { ok: true, code: 'ok' }];
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
open(
|
|
189
|
+
path: string,
|
|
190
|
+
props: IndexType = {},
|
|
191
|
+
options: NavigationItem = {},
|
|
192
|
+
): Promise<DispatchResult> {
|
|
193
|
+
const task = this.openQueue.then(
|
|
194
|
+
() => this.performOpen(path, props, options),
|
|
195
|
+
() => this.performOpen(path, props, options),
|
|
196
|
+
);
|
|
197
|
+
this.openQueue = task.then(
|
|
198
|
+
() => undefined,
|
|
199
|
+
() => undefined,
|
|
200
|
+
);
|
|
201
|
+
return task;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
private hasDrawerLayout(graph: RouteGraph): boolean {
|
|
205
|
+
if (graph.layout === 'drawer') {
|
|
206
|
+
return true;
|
|
207
|
+
}
|
|
208
|
+
if (!graph.children) {
|
|
209
|
+
return false;
|
|
210
|
+
}
|
|
211
|
+
return graph.children.some(child => this.hasDrawerLayout(child));
|
|
156
212
|
}
|
|
157
213
|
|
|
158
|
-
async
|
|
214
|
+
private async performOpen(
|
|
215
|
+
path: string,
|
|
216
|
+
props: IndexType,
|
|
217
|
+
options: NavigationItem,
|
|
218
|
+
): Promise<DispatchResult> {
|
|
159
219
|
this.inflateRouteData();
|
|
160
220
|
|
|
161
221
|
const intercepted = await this.intercept(path);
|
|
162
222
|
if (intercepted) {
|
|
163
|
-
return;
|
|
223
|
+
return { ok: false, code: 'intercepted' };
|
|
164
224
|
}
|
|
165
225
|
|
|
166
226
|
const route = this.pathToRoute(path, props, options);
|
|
167
227
|
if (!route) {
|
|
168
|
-
return
|
|
228
|
+
return {
|
|
229
|
+
ok: false,
|
|
230
|
+
code: 'scene_not_found',
|
|
231
|
+
message: `No route matched path: ${path}`,
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
let graphArray = await Navigation.routeGraph();
|
|
236
|
+
if (!graphArray || graphArray.length === 0) {
|
|
237
|
+
return {
|
|
238
|
+
ok: false,
|
|
239
|
+
code: 'not_ready',
|
|
240
|
+
message: 'Route graph is empty.',
|
|
241
|
+
};
|
|
169
242
|
}
|
|
170
243
|
|
|
171
|
-
const graphArray = await Navigation.routeGraph();
|
|
172
244
|
if (graphArray.length > 1) {
|
|
173
245
|
for (let index = graphArray.length - 1; index > 0; index--) {
|
|
174
246
|
const { mode: layoutMode } = graphArray[index];
|
|
175
|
-
const
|
|
247
|
+
const currentRoute = await Navigation.currentRoute();
|
|
248
|
+
if (!currentRoute) {
|
|
249
|
+
return {
|
|
250
|
+
ok: false,
|
|
251
|
+
code: 'scene_not_found',
|
|
252
|
+
message: 'Unable to resolve current route while dismissing presented scenes.',
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
const { sceneId, moduleName } = currentRoute;
|
|
176
256
|
if (layoutMode === 'present') {
|
|
177
|
-
await Navigation.dispatch(sceneId, 'dismiss', {
|
|
257
|
+
const res = await Navigation.dispatch(sceneId, 'dismiss', {
|
|
178
258
|
from: moduleName,
|
|
179
259
|
});
|
|
260
|
+
if (!res.ok) {
|
|
261
|
+
return res;
|
|
262
|
+
}
|
|
180
263
|
} else if (layoutMode === 'modal') {
|
|
181
|
-
await Navigation.dispatch(sceneId, 'hideModal', {
|
|
264
|
+
const res = await Navigation.dispatch(sceneId, 'hideModal', {
|
|
182
265
|
from: moduleName,
|
|
183
266
|
});
|
|
267
|
+
if (!res.ok) {
|
|
268
|
+
return res;
|
|
269
|
+
}
|
|
184
270
|
} else {
|
|
185
271
|
console.warn('尚未处理的 layout mode:' + layoutMode);
|
|
186
272
|
}
|
|
187
273
|
}
|
|
274
|
+
graphArray = await Navigation.routeGraph();
|
|
188
275
|
}
|
|
189
276
|
|
|
190
277
|
const routeGraph = graphArray[0];
|
|
278
|
+
if (!routeGraph) {
|
|
279
|
+
return {
|
|
280
|
+
ok: false,
|
|
281
|
+
code: 'not_ready',
|
|
282
|
+
message: 'Root route graph is missing.',
|
|
283
|
+
};
|
|
284
|
+
}
|
|
191
285
|
|
|
192
|
-
const consumed = await this.processRoute(routeGraph, route);
|
|
286
|
+
const [consumed, routeResult] = await this.processRoute(routeGraph, route);
|
|
193
287
|
if (consumed) {
|
|
194
|
-
return;
|
|
288
|
+
return routeResult;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
const currentRoute = await Navigation.currentRoute();
|
|
292
|
+
if (!currentRoute) {
|
|
293
|
+
return {
|
|
294
|
+
ok: false,
|
|
295
|
+
code: 'scene_not_found',
|
|
296
|
+
message: 'Unable to resolve current route.',
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
const { sceneId, moduleName: from } = currentRoute;
|
|
301
|
+
if (this.hasDrawerLayout(routeGraph)) {
|
|
302
|
+
const closeMenuResult = await Navigation.dispatch(sceneId, 'closeMenu', { from });
|
|
303
|
+
if (closeMenuResult.code === 'intercepted') {
|
|
304
|
+
return closeMenuResult;
|
|
305
|
+
}
|
|
195
306
|
}
|
|
196
307
|
|
|
197
|
-
const { sceneId, moduleName: from } = await Navigation.currentRoute();
|
|
198
|
-
Navigation.dispatch(sceneId, 'closeMenu', { from });
|
|
199
308
|
const { moduleName, mode: routeMode, props: initialProps } = route;
|
|
200
309
|
let action = 'push';
|
|
201
310
|
if (routeMode === 'present') {
|
|
@@ -203,9 +312,11 @@ class Router {
|
|
|
203
312
|
} else if (routeMode === 'modal') {
|
|
204
313
|
action = 'showModal';
|
|
205
314
|
}
|
|
206
|
-
|
|
315
|
+
|
|
316
|
+
return await Navigation.dispatch(sceneId, action, {
|
|
207
317
|
moduleName,
|
|
208
318
|
props: initialProps,
|
|
319
|
+
options: route.options,
|
|
209
320
|
from,
|
|
210
321
|
to: moduleName,
|
|
211
322
|
});
|
package/src/router/screen.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
|
|
|
3
3
|
export interface ScreenGraph extends RouteGraph {
|
|
4
4
|
layout: 'screen';
|
|
@@ -31,13 +31,13 @@ export function isTargetLocateIn(graph: RouteGraph, target: RouteInfo) {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
export class ScreenRouteHandler implements RouteHandler {
|
|
34
|
-
process(graph: RouteGraph, target: RouteInfo): Promise<
|
|
34
|
+
process(graph: RouteGraph, target: RouteInfo): Promise<RouteHandleResult> {
|
|
35
35
|
if (!isScreenGraph(graph)) {
|
|
36
36
|
throw new Error(`${graph} is Not a ScreenGraph`);
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
if (graph.moduleName === target.moduleName) {
|
|
40
|
-
return Promise.resolve([true, null]);
|
|
40
|
+
return Promise.resolve([true, null, { ok: true, code: 'ok' }]);
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
return Promise.resolve([false, graph]);
|
package/src/router/stack.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { ScreenGraph, isScreenGraph, isTargetLocateIn } from './screen';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
DispatchResult,
|
|
4
|
+
LayoutMode,
|
|
5
|
+
RouteGraph,
|
|
6
|
+
RouteHandler,
|
|
7
|
+
RouteHandleResult,
|
|
8
|
+
RouteInfo,
|
|
9
|
+
} from '../Route';
|
|
3
10
|
import Navigation from '../Navigation';
|
|
4
11
|
|
|
5
12
|
export interface StackGraph extends RouteGraph {
|
|
@@ -14,7 +21,7 @@ export function isStackGraph(graph: RouteGraph): graph is StackGraph {
|
|
|
14
21
|
}
|
|
15
22
|
|
|
16
23
|
export class StackRouteHandler implements RouteHandler {
|
|
17
|
-
async process(graph: RouteGraph, target: RouteInfo): Promise<
|
|
24
|
+
async process(graph: RouteGraph, target: RouteInfo): Promise<RouteHandleResult> {
|
|
18
25
|
if (!isStackGraph(graph)) {
|
|
19
26
|
throw new Error(`${graph} is Not a StackGraph`);
|
|
20
27
|
}
|
|
@@ -25,11 +32,18 @@ export class StackRouteHandler implements RouteHandler {
|
|
|
25
32
|
const childGraph = children[i];
|
|
26
33
|
if (isTargetLocateIn(childGraph, target)) {
|
|
27
34
|
if (isScreenGraph(childGraph)) {
|
|
28
|
-
this.navigateTo(
|
|
29
|
-
|
|
35
|
+
const result = await this.navigateTo(
|
|
36
|
+
childGraph,
|
|
37
|
+
target,
|
|
38
|
+
i === children.length - 1,
|
|
39
|
+
);
|
|
40
|
+
return [true, null, result];
|
|
30
41
|
}
|
|
31
42
|
|
|
32
|
-
await this.popToIfNeeded(childGraph, i === children.length - 1);
|
|
43
|
+
const popResult = await this.popToIfNeeded(childGraph, i === children.length - 1);
|
|
44
|
+
if (!popResult.ok) {
|
|
45
|
+
return [true, null, popResult];
|
|
46
|
+
}
|
|
33
47
|
return [true, childGraph];
|
|
34
48
|
}
|
|
35
49
|
}
|
|
@@ -37,57 +51,94 @@ export class StackRouteHandler implements RouteHandler {
|
|
|
37
51
|
return [false, graph];
|
|
38
52
|
}
|
|
39
53
|
|
|
40
|
-
private async popToIfNeeded(
|
|
54
|
+
private async popToIfNeeded(
|
|
55
|
+
childGraph: RouteGraph,
|
|
56
|
+
isLastChildAtStack: boolean,
|
|
57
|
+
): Promise<DispatchResult> {
|
|
41
58
|
if (!isLastChildAtStack) {
|
|
42
|
-
await Navigation.dispatch(childGraph.sceneId, 'popTo', {
|
|
59
|
+
return await Navigation.dispatch(childGraph.sceneId, 'popTo', {
|
|
43
60
|
moduleName: childGraph.sceneId,
|
|
44
61
|
});
|
|
45
62
|
}
|
|
63
|
+
return { ok: true, code: 'ok' };
|
|
46
64
|
}
|
|
47
65
|
|
|
48
|
-
private navigateTo(
|
|
49
|
-
|
|
66
|
+
private async navigateTo(
|
|
67
|
+
childGraph: ScreenGraph,
|
|
68
|
+
target: RouteInfo,
|
|
69
|
+
isLastChildAtStack: boolean,
|
|
70
|
+
): Promise<DispatchResult> {
|
|
71
|
+
const { moduleName, dependencies, props, options } = target;
|
|
50
72
|
const expectations = [...dependencies, moduleName];
|
|
51
73
|
const index = expectations.findIndex(name => name === childGraph.moduleName);
|
|
52
74
|
const pendings = expectations.slice(index + 1);
|
|
53
|
-
console.log('pendings', pendings, 'moduleName', childGraph.moduleName);
|
|
54
75
|
const sceneId = childGraph.sceneId;
|
|
55
76
|
|
|
56
77
|
const moduleExisting = pendings.length === 0;
|
|
57
78
|
|
|
58
79
|
if (moduleExisting) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
80
|
+
const hasProps = props && Object.keys(props).length > 0;
|
|
81
|
+
const hasOptions = options && Object.keys(options).length > 0;
|
|
82
|
+
if (!hasProps && !hasOptions) {
|
|
83
|
+
if (!isLastChildAtStack) {
|
|
84
|
+
return await Navigation.dispatch(sceneId, 'popTo', {
|
|
85
|
+
moduleName,
|
|
86
|
+
from: childGraph.moduleName,
|
|
87
|
+
to: moduleName,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
return { ok: true, code: 'ok' };
|
|
65
91
|
} else {
|
|
66
|
-
Navigation.dispatch(sceneId, 'redirectTo', {
|
|
92
|
+
return await Navigation.dispatch(sceneId, 'redirectTo', {
|
|
67
93
|
moduleName,
|
|
68
94
|
from: childGraph.moduleName,
|
|
69
95
|
to: moduleName,
|
|
70
96
|
props,
|
|
97
|
+
options,
|
|
71
98
|
});
|
|
72
99
|
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const popResult = await this.popToIfNeeded(childGraph, isLastChildAtStack);
|
|
103
|
+
if (!popResult.ok) {
|
|
104
|
+
return popResult;
|
|
105
|
+
}
|
|
106
|
+
const finalAction =
|
|
107
|
+
target.mode === 'present'
|
|
108
|
+
? 'present'
|
|
109
|
+
: target.mode === 'modal'
|
|
110
|
+
? 'showModal'
|
|
111
|
+
: 'push';
|
|
112
|
+
let currentSceneId = sceneId;
|
|
113
|
+
let fromModule = childGraph.moduleName;
|
|
114
|
+
let lastResult: DispatchResult = { ok: true, code: 'ok' };
|
|
115
|
+
for (let i = 0; i < pendings.length; i++) {
|
|
116
|
+
const isLast = i === pendings.length - 1;
|
|
117
|
+
const targetModule = isLast ? moduleName : pendings[i];
|
|
118
|
+
lastResult = isLast
|
|
119
|
+
? await Navigation.dispatch(currentSceneId, finalAction, {
|
|
78
120
|
moduleName,
|
|
79
|
-
from:
|
|
121
|
+
from: fromModule,
|
|
80
122
|
to: moduleName,
|
|
81
123
|
props,
|
|
124
|
+
options,
|
|
125
|
+
})
|
|
126
|
+
: await Navigation.dispatch(currentSceneId, 'push', {
|
|
127
|
+
moduleName: targetModule,
|
|
128
|
+
from: fromModule,
|
|
129
|
+
to: targetModule,
|
|
82
130
|
});
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
131
|
+
if (!lastResult.ok) {
|
|
132
|
+
return lastResult;
|
|
133
|
+
}
|
|
134
|
+
fromModule = targetModule;
|
|
135
|
+
if (!isLast) {
|
|
136
|
+
const current = await Navigation.currentRoute();
|
|
137
|
+
if (current?.sceneId) {
|
|
138
|
+
currentSceneId = current.sceneId;
|
|
89
139
|
}
|
|
90
140
|
}
|
|
91
141
|
}
|
|
142
|
+
return lastResult;
|
|
92
143
|
}
|
|
93
144
|
}
|
package/src/router/tabs.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isTargetLocateIn } from './screen';
|
|
2
|
-
import { LayoutMode, RouteGraph, RouteHandler, RouteInfo } from '../Route';
|
|
2
|
+
import { LayoutMode, RouteGraph, RouteHandler, RouteHandleResult, RouteInfo } from '../Route';
|
|
3
3
|
import Navigation from '../Navigation';
|
|
4
4
|
|
|
5
5
|
export interface TabsGraph extends RouteGraph {
|
|
@@ -13,8 +13,9 @@ export interface TabsGraph extends RouteGraph {
|
|
|
13
13
|
export function isTabsGraph(graph: RouteGraph): graph is TabsGraph {
|
|
14
14
|
return graph.layout === 'tabs';
|
|
15
15
|
}
|
|
16
|
+
|
|
16
17
|
export class TabsRouteHandler implements RouteHandler {
|
|
17
|
-
async process(graph: RouteGraph, target: RouteInfo): Promise<
|
|
18
|
+
async process(graph: RouteGraph, target: RouteInfo): Promise<RouteHandleResult> {
|
|
18
19
|
if (!isTabsGraph(graph)) {
|
|
19
20
|
throw new Error(`${graph} is NOT a TabsGraph`);
|
|
20
21
|
}
|
|
@@ -24,11 +25,18 @@ export class TabsRouteHandler implements RouteHandler {
|
|
|
24
25
|
for (let i = 0; i < children.length; i++) {
|
|
25
26
|
if (isTargetLocateIn(children[i], target)) {
|
|
26
27
|
if (selectedIndex !== i) {
|
|
27
|
-
await Navigation.dispatch(
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
const result = await Navigation.dispatch(
|
|
29
|
+
children[selectedIndex].sceneId,
|
|
30
|
+
'switchTab',
|
|
31
|
+
{
|
|
32
|
+
from: selectedIndex,
|
|
33
|
+
to: i,
|
|
34
|
+
popToRoot: true,
|
|
35
|
+
},
|
|
36
|
+
);
|
|
37
|
+
if (!result.ok) {
|
|
38
|
+
return [true, null, result];
|
|
39
|
+
}
|
|
32
40
|
}
|
|
33
41
|
return [true, children[i]];
|
|
34
42
|
}
|
package/src/store.ts
CHANGED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
package androidx.fragment.app;
|
|
2
|
-
|
|
3
|
-
import android.os.Bundle;
|
|
4
|
-
import android.view.LayoutInflater;
|
|
5
|
-
import android.view.ViewGroup;
|
|
6
|
-
|
|
7
|
-
import androidx.annotation.NonNull;
|
|
8
|
-
import androidx.annotation.Nullable;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
public class InternalFragment extends Fragment {
|
|
12
|
-
|
|
13
|
-
public int getContainerId() {
|
|
14
|
-
return mContainerId;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
@Override
|
|
18
|
-
protected void performCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
|
19
|
-
super.performCreateView(inflater, container, savedInstanceState);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
}
|