hybrid-navigation 5.2.0 → 5.3.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/README.md +9 -20
- package/android/src/main/java/com/navigation/androidx/AwesomeFragment.java +5 -13
- package/android/src/main/java/com/navigation/androidx/DefaultTabBarProvider.java +2 -2
- package/android/src/main/java/com/navigation/androidx/TabBarFragment.java +0 -50
- package/android/src/main/java/com/navigation/androidx/TabBarItem.java +0 -4
- package/android/src/main/java/com/reactnative/hybridnavigation/GlobalStyle.java +0 -7
- package/android/src/main/java/com/reactnative/hybridnavigation/HybridFragment.java +7 -43
- package/android/src/main/java/com/reactnative/hybridnavigation/NativeNavigation.java +5 -39
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactFragment.java +62 -135
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactManager.java +0 -20
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarFragment.java +10 -21
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/ScreenNavigator.java +39 -87
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/TabNavigator.java +2 -16
- package/dist/NativeEvent.d.ts +1 -11
- package/dist/NativeNavigation.d.ts +7 -6
- package/dist/Navigation.d.ts +8 -22
- package/dist/Navigation.js +33 -175
- package/dist/NavigationComponentWrap.d.ts +3 -3
- package/dist/Navigator.d.ts +4 -5
- package/dist/Navigator.js +13 -37
- package/dist/Options.d.ts +2 -2
- package/dist/Route.d.ts +10 -35
- package/dist/handler/DispatchCommandHandler.d.ts +3 -18
- package/dist/handler/DispatchCommandHandler.js +17 -64
- package/dist/handler/LayoutCommandHandler.d.ts +2 -3
- package/dist/handler/LayoutCommandHandler.js +0 -3
- package/dist/handler/LeaveGuardHandler.d.ts +3 -3
- package/dist/handler/LeaveGuardHandler.js +57 -32
- package/dist/handler/LifecycleEventHandler.d.ts +2 -14
- package/dist/handler/LifecycleEventHandler.js +2 -79
- package/dist/handler/ResultEventHandler.d.ts +0 -1
- package/dist/handler/ResultEventHandler.js +0 -3
- package/dist/handler/SceneExitHandler.d.ts +3 -0
- package/dist/handler/SceneExitHandler.js +76 -0
- package/dist/hooks.d.ts +0 -3
- package/dist/hooks.js +21 -46
- package/dist/index.d.ts +1 -12
- package/dist/index.js +0 -3
- package/dist/router/index.d.ts +0 -1
- package/dist/router/index.js +43 -11
- package/dist/router/stack.d.ts +1 -1
- package/dist/sceneCoverage.d.ts +2 -0
- package/dist/sceneCoverage.js +25 -0
- package/dist/store.d.ts +0 -2
- package/dist/store.js +0 -4
- package/ios/HBDGlobalStyle.h +0 -1
- package/ios/HBDGlobalStyle.mm +0 -7
- package/ios/HybridNavigation.h +0 -1
- package/ios/Navigator/HBDScreenNavigator.mm +89 -237
- package/ios/Navigator/HBDStackNavigator.mm +1 -1
- package/ios/Navigator/HBDTabNavigator.mm +15 -30
- package/ios/React/HBDNativeNavigation.mm +4 -31
- package/ios/React/HBDReactBridgeManager.h +0 -5
- package/ios/React/HBDReactBridgeManager.mm +0 -17
- package/ios/ViewController/HBDReactViewController.h +1 -1
- package/ios/ViewController/HBDReactViewController.mm +34 -9
- package/ios/ViewController/HBDTabBarController.h +2 -11
- package/ios/ViewController/HBDTabBarController.mm +14 -170
- package/ios/ViewController/HBDViewController.h +0 -1
- package/ios/ViewController/HBDViewController.mm +9 -57
- package/ios/ViewController/UIViewController+HBD.h +2 -0
- package/ios/ViewController/UIViewController+HBD.mm +5 -0
- package/package.json +1 -3
- package/src/NativeEvent.ts +1 -12
- package/src/NativeNavigation.ts +8 -7
- package/src/Navigation.ts +50 -281
- package/src/NavigationComponentWrap.tsx +3 -11
- package/src/Navigator.ts +15 -46
- package/src/Options.ts +2 -3
- package/src/Route.ts +13 -56
- package/src/handler/DispatchCommandHandler.ts +29 -111
- package/src/handler/LayoutCommandHandler.ts +2 -6
- package/src/handler/LeaveGuardHandler.ts +65 -32
- package/src/handler/LifecycleEventHandler.ts +22 -122
- package/src/handler/ResultEventHandler.ts +0 -6
- package/src/handler/SceneExitHandler.ts +86 -0
- package/src/hooks.ts +18 -53
- package/src/index.ts +0 -14
- package/src/router/index.ts +45 -12
- package/src/router/stack.ts +1 -1
- package/src/sceneCoverage.ts +30 -0
- package/src/store.ts +0 -5
- package/dist/defineRoutes.d.ts +0 -19
- package/dist/defineRoutes.js +0 -6
- package/dist/handler/PresentationCoordinator.d.ts +0 -39
- package/dist/handler/PresentationCoordinator.js +0 -673
- package/dist/handler/TabEventHandler.d.ts +0 -8
- package/dist/handler/TabEventHandler.js +0 -25
- package/dist/reveal.d.ts +0 -46
- package/dist/reveal.js +0 -431
- package/dist/routeGraph.d.ts +0 -12
- package/dist/routeGraph.js +0 -68
- package/dist/testing.d.ts +0 -82
- package/dist/testing.js +0 -253
- package/ios/ViewController/HBDTabBarRenderer.h +0 -28
- package/src/defineRoutes.ts +0 -46
- package/src/handler/PresentationCoordinator.ts +0 -806
- package/src/handler/TabEventHandler.ts +0 -31
- package/src/reveal.ts +0 -565
- package/src/routeGraph.ts +0 -87
- package/src/testing.ts +0 -402
- package/testing.d.ts +0 -1
- package/testing.js +0 -3
package/src/Navigation.ts
CHANGED
|
@@ -5,8 +5,6 @@ import type { DefaultOptions, NavigationOption, TabBarStyle, TabItemInfo } from
|
|
|
5
5
|
import type {
|
|
6
6
|
BeforeRemoveListener,
|
|
7
7
|
BeforeRemoveOptions,
|
|
8
|
-
BuildInLayout,
|
|
9
|
-
CloseSelfOptions,
|
|
10
8
|
DispatchResult,
|
|
11
9
|
Layout,
|
|
12
10
|
NavigationResult,
|
|
@@ -16,21 +14,12 @@ import type {
|
|
|
16
14
|
RouteConfig,
|
|
17
15
|
RouteGraph,
|
|
18
16
|
RouteName,
|
|
19
|
-
SceneCoverageListener,
|
|
20
|
-
SceneExitHandler,
|
|
21
|
-
SceneInfo,
|
|
22
17
|
SceneLifecycleState,
|
|
23
18
|
SetRootOptions,
|
|
24
|
-
TabPressListener,
|
|
25
19
|
} from './Route';
|
|
26
20
|
|
|
27
21
|
import { layoutHandler, RootLayoutListener } from './handler/LayoutCommandHandler';
|
|
28
|
-
import {
|
|
29
|
-
import { leaveGuardHandler } from './handler/LeaveGuardHandler';
|
|
30
|
-
import { presentationCoordinator } from './handler/PresentationCoordinator';
|
|
31
|
-
import { tabEventHandler } from './handler/TabEventHandler';
|
|
32
|
-
import { executeReveal, type RevealOptions, type RevealResult, type RevealTarget } from './reveal';
|
|
33
|
-
import type { RouteDefinition } from './defineRoutes';
|
|
22
|
+
import { dispatchHandler } from './handler/DispatchCommandHandler';
|
|
34
23
|
import {
|
|
35
24
|
RESULT_BLOCK,
|
|
36
25
|
RESULT_CANCEL,
|
|
@@ -39,27 +28,22 @@ import {
|
|
|
39
28
|
} from './handler/ResultEventHandler';
|
|
40
29
|
import {
|
|
41
30
|
GlobalSceneLifecycleListener,
|
|
42
|
-
GlobalVisibilityEventListener,
|
|
43
31
|
lifecycleHandler,
|
|
44
32
|
SceneLifecycleListener,
|
|
45
|
-
VisibilityEventListener,
|
|
46
33
|
} from './handler/LifecycleEventHandler';
|
|
47
34
|
|
|
35
|
+
import { leaveGuardHandler, BEFORE_REMOVE_SOURCE_PROP } from './handler/LeaveGuardHandler';
|
|
48
36
|
import NativeNavigation from './NativeNavigation';
|
|
37
|
+
import { isSceneCoveredInLayers } from './sceneCoverage';
|
|
49
38
|
import store from './store';
|
|
50
39
|
import { withNavigation } from './NavigationComponentWrap';
|
|
51
40
|
import {
|
|
52
41
|
bumpRouteConfigVersion,
|
|
53
42
|
clearRouteConfigs,
|
|
54
|
-
getRouteConfigs,
|
|
55
43
|
setRouteConfig,
|
|
56
44
|
} from './routeConfigRegistry';
|
|
57
45
|
|
|
58
|
-
|
|
59
|
-
import type {
|
|
60
|
-
DispatchParams,
|
|
61
|
-
NavigationInterceptor,
|
|
62
|
-
} from './handler/DispatchCommandHandler';
|
|
46
|
+
import type { DispatchParams, NavigationInterceptor } from './handler/DispatchCommandHandler';
|
|
63
47
|
export type {
|
|
64
48
|
DispatchParams,
|
|
65
49
|
InterceptParams,
|
|
@@ -67,9 +51,7 @@ export type {
|
|
|
67
51
|
} from './handler/DispatchCommandHandler';
|
|
68
52
|
export type {
|
|
69
53
|
GlobalSceneLifecycleListener,
|
|
70
|
-
GlobalVisibilityEventListener,
|
|
71
54
|
SceneLifecycleListener,
|
|
72
|
-
VisibilityEventListener,
|
|
73
55
|
} from './handler/LifecycleEventHandler';
|
|
74
56
|
export type { RootLayoutListener } from './handler/LayoutCommandHandler';
|
|
75
57
|
|
|
@@ -89,50 +71,20 @@ export interface Navigation {
|
|
|
89
71
|
getComponentFunc: ComponentProvider,
|
|
90
72
|
routeConfig?: RouteConfig,
|
|
91
73
|
): void;
|
|
92
|
-
registerRoutes(routes: readonly RouteDefinition<any, any, any>[]): void;
|
|
93
|
-
preloadRoute(moduleName: RouteName): void;
|
|
94
74
|
|
|
95
75
|
addLifecycleListener(sceneId: string, listener: SceneLifecycleListener): NavigationSubscription;
|
|
96
76
|
addGlobalLifecycleListener(listener: GlobalSceneLifecycleListener): NavigationSubscription;
|
|
97
77
|
getSceneState(sceneId: string): SceneLifecycleState;
|
|
98
|
-
getSceneInfo(sceneId: string): SceneInfo | undefined;
|
|
99
|
-
addGlobalVisibilityEventListener(
|
|
100
|
-
listener: GlobalVisibilityEventListener,
|
|
101
|
-
): NavigationSubscription;
|
|
102
|
-
addVisibilityEventListener(
|
|
103
|
-
sceneId: string,
|
|
104
|
-
listener: VisibilityEventListener,
|
|
105
|
-
): NavigationSubscription;
|
|
106
|
-
addTabPressListener(listener: TabPressListener): NavigationSubscription;
|
|
107
78
|
|
|
108
79
|
dispatch(sceneId: string, action: string, params?: DispatchParams): Promise<DispatchResult>;
|
|
109
80
|
addInterceptor(interceptor: NavigationInterceptor): NavigationSubscription;
|
|
110
|
-
registerSceneExitHandler(
|
|
111
|
-
sceneId: string,
|
|
112
|
-
handler: SceneExitHandler,
|
|
113
|
-
): NavigationSubscription;
|
|
114
|
-
addSceneCoverageListener(
|
|
115
|
-
sceneId: string,
|
|
116
|
-
listener: SceneCoverageListener,
|
|
117
|
-
): NavigationSubscription;
|
|
118
|
-
isSceneCovered(sceneId: string): Promise<boolean>;
|
|
119
|
-
addBeforeRemoveListener(
|
|
120
|
-
sceneId: string,
|
|
121
|
-
listener: BeforeRemoveListener,
|
|
122
|
-
options?: BeforeRemoveOptions,
|
|
123
|
-
): NavigationSubscription;
|
|
124
|
-
closeScene<T extends ResultMap = ResultMap>(
|
|
125
|
-
sceneId: string,
|
|
126
|
-
options?: CloseSelfOptions<T>,
|
|
127
|
-
): Promise<DispatchResult>;
|
|
128
|
-
reveal(target: RevealTarget, options?: RevealOptions): Promise<RevealResult>;
|
|
129
81
|
setResult<T extends ResultMap = ResultMap>(
|
|
130
82
|
sceneId: string,
|
|
131
83
|
resultCode: number,
|
|
132
84
|
data?: T | null,
|
|
133
85
|
): void;
|
|
134
86
|
result<T = unknown>(sceneId: string, requestCode: number): Promise<NavigationResult<T>>;
|
|
135
|
-
setRoot(layout:
|
|
87
|
+
setRoot(layout: Layout, options?: SetRootOptions): Promise<DispatchResult>;
|
|
136
88
|
addRootLayoutUpdateListener(
|
|
137
89
|
willSetRoot?: RootLayoutListener,
|
|
138
90
|
didSetRoot?: RootLayoutListener,
|
|
@@ -142,56 +94,45 @@ export interface Navigation {
|
|
|
142
94
|
findSceneIdByModuleName(moduleName: RouteName): Promise<string | null>;
|
|
143
95
|
isStackRoot(sceneId: string): Promise<boolean>;
|
|
144
96
|
currentRoute(): Promise<Route | null>;
|
|
145
|
-
routeGraph(): Promise<RouteGraph[]>;
|
|
146
97
|
navigationSnapshot(): Promise<NavigationSnapshot>;
|
|
98
|
+
addBeforeRemoveListener(
|
|
99
|
+
sceneId: string,
|
|
100
|
+
listener: BeforeRemoveListener,
|
|
101
|
+
options?: BeforeRemoveOptions,
|
|
102
|
+
): NavigationSubscription;
|
|
103
|
+
isSceneCovered(sceneId: string): Promise<boolean>;
|
|
104
|
+
/** @deprecated Use (await navigationSnapshot()).layers instead. */
|
|
105
|
+
routeGraph(): Promise<RouteGraph[]>;
|
|
147
106
|
|
|
148
107
|
setDefaultOptions(options: DefaultOptions): void;
|
|
149
108
|
updateOptions(sceneId: string, options: NavigationOption): void;
|
|
150
|
-
updateTabBar(options: TabBarStyle): void;
|
|
151
109
|
updateTabBar(sceneId: string, options: TabBarStyle): void;
|
|
152
|
-
setTabItem(item: TabItemInfo | TabItemInfo[]): void;
|
|
153
110
|
setTabItem(sceneId: string, item: TabItemInfo | TabItemInfo[]): void;
|
|
154
111
|
setMenuInteractive(sceneId: string, enabled: boolean): Promise<DispatchResult>;
|
|
155
112
|
}
|
|
156
113
|
|
|
157
114
|
class NavigationImpl implements Navigation {
|
|
158
115
|
constructor() {
|
|
159
|
-
leaveGuardHandler.setDispatcher((sceneId, action, params) =>
|
|
160
|
-
|
|
161
|
-
);
|
|
162
|
-
dispatchHandler.addMiddleware(leaveGuardHandler.middleware);
|
|
163
|
-
dispatchHandler.addMiddleware(dispatchHandler.interceptorMiddleware);
|
|
164
|
-
dispatchHandler.addMiddleware(presentationCoordinator.middleware);
|
|
116
|
+
leaveGuardHandler.setDispatcher((sceneId, action, params) => dispatchHandler.dispatch(sceneId, action, params));
|
|
117
|
+
leaveGuardHandler.handleNativeBeforeRemoveRequests();
|
|
165
118
|
layoutHandler.handleRootLayoutChange(() => {
|
|
166
|
-
lifecycleHandler.onRootReset();
|
|
167
119
|
leaveGuardHandler.onRootReset();
|
|
168
|
-
presentationCoordinator.onRootReset();
|
|
169
120
|
resultHandler.invalidateAll('root_reset');
|
|
170
121
|
});
|
|
171
122
|
lifecycleHandler.handleSceneLifecycle(sceneId => {
|
|
172
123
|
leaveGuardHandler.onSceneDestroyed(sceneId);
|
|
173
|
-
presentationCoordinator.onSceneDestroyed(sceneId);
|
|
174
124
|
resultHandler.invalidateResultEventListener(sceneId, 'unmounted');
|
|
175
125
|
store.removeNavigator(sceneId);
|
|
176
126
|
});
|
|
177
127
|
resultHandler.handleComponentResult();
|
|
178
|
-
leaveGuardHandler.handleNativeBeforeRemoveRequests();
|
|
179
|
-
tabEventHandler.handleTabPress();
|
|
180
128
|
}
|
|
181
129
|
|
|
182
130
|
private hoc?: HOC;
|
|
183
131
|
private registerEnded = false;
|
|
184
|
-
private registeredNames = new Set<string>();
|
|
185
|
-
private registeredPaths = new Map<string, string>();
|
|
186
|
-
private routeLoaders = new Map<string, () => React.ComponentType<any>>();
|
|
187
|
-
private revealQueue: Promise<unknown> = Promise.resolve();
|
|
188
132
|
|
|
189
133
|
startRegisterComponent(hoc?: HOC) {
|
|
190
134
|
this.hoc = hoc;
|
|
191
135
|
this.registerEnded = false;
|
|
192
|
-
this.registeredNames.clear();
|
|
193
|
-
this.registeredPaths.clear();
|
|
194
|
-
this.routeLoaders.clear();
|
|
195
136
|
clearRouteConfigs();
|
|
196
137
|
NativeNavigation.startRegisterReactComponent();
|
|
197
138
|
}
|
|
@@ -202,78 +143,25 @@ class NavigationImpl implements Navigation {
|
|
|
202
143
|
return;
|
|
203
144
|
}
|
|
204
145
|
this.registerEnded = true;
|
|
205
|
-
if (__DEV__) {
|
|
206
|
-
this.validateRouteDependencies();
|
|
207
|
-
}
|
|
208
146
|
bumpRouteConfigVersion();
|
|
209
147
|
NativeNavigation.endRegisterReactComponent();
|
|
210
148
|
}
|
|
211
149
|
|
|
212
|
-
private validateRouteDependencies() {
|
|
213
|
-
const configs = getRouteConfigs();
|
|
214
|
-
const state = new Map<string, 'visiting' | 'visited'>();
|
|
215
|
-
const stack: string[] = [];
|
|
216
|
-
|
|
217
|
-
const visit = (name: string) => {
|
|
218
|
-
state.set(name, 'visiting');
|
|
219
|
-
stack.push(name);
|
|
220
|
-
const dependency = configs.get(name)?.dependency;
|
|
221
|
-
if (dependency) {
|
|
222
|
-
const depState = state.get(dependency);
|
|
223
|
-
if (depState === 'visiting') {
|
|
224
|
-
const cycleStart = stack.indexOf(dependency);
|
|
225
|
-
const cycle = [...stack.slice(cycleStart), dependency].join(' -> ');
|
|
226
|
-
console.warn(`[hybrid-navigation] Circular route dependency detected: ${cycle}`);
|
|
227
|
-
} else if (!depState && configs.has(dependency)) {
|
|
228
|
-
visit(dependency);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
stack.pop();
|
|
232
|
-
state.set(name, 'visited');
|
|
233
|
-
};
|
|
234
|
-
|
|
235
|
-
for (const name of configs.keys()) {
|
|
236
|
-
if (!state.has(name)) {
|
|
237
|
-
visit(name);
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
150
|
registerComponent<Name extends RouteName = RouteName>(
|
|
243
151
|
appKey: Name,
|
|
244
152
|
getComponentFunc: ComponentProvider,
|
|
245
153
|
routeConfig?: RouteConfig,
|
|
246
154
|
) {
|
|
247
|
-
if (__DEV__) {
|
|
248
|
-
if (this.registeredNames.has(appKey)) {
|
|
249
|
-
console.warn(
|
|
250
|
-
`[hybrid-navigation] Duplicate route registration for "${appKey}". Later registration overrides earlier one.`,
|
|
251
|
-
);
|
|
252
|
-
}
|
|
253
|
-
if (routeConfig?.path) {
|
|
254
|
-
const existing = this.registeredPaths.get(routeConfig.path);
|
|
255
|
-
if (existing && existing !== appKey) {
|
|
256
|
-
console.warn(
|
|
257
|
-
`[hybrid-navigation] Duplicate route path "${routeConfig.path}" registered by "${appKey}" and "${existing}".`,
|
|
258
|
-
);
|
|
259
|
-
}
|
|
260
|
-
this.registeredPaths.set(routeConfig.path, appKey);
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
this.registeredNames.add(appKey);
|
|
264
|
-
|
|
265
155
|
if (routeConfig && (routeConfig.path || routeConfig.dependency || routeConfig.mode)) {
|
|
266
156
|
setRouteConfig(appKey, routeConfig);
|
|
267
157
|
}
|
|
268
158
|
|
|
269
159
|
const hoc = this.hoc;
|
|
270
160
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
if (isLazy) {
|
|
274
|
-
NativeNavigation.registerReactComponent(appKey, routeConfig?.options ?? {});
|
|
161
|
+
if (routeConfig?.options !== undefined || routeConfig?.lazy === true) {
|
|
162
|
+
NativeNavigation.registerReactComponent(appKey, routeConfig.options ?? {});
|
|
275
163
|
let CachedRootComponent: React.ComponentType<any> | undefined;
|
|
276
|
-
|
|
164
|
+
AppRegistry.registerComponent(appKey, () => {
|
|
277
165
|
if (!CachedRootComponent) {
|
|
278
166
|
let WrappedComponent = getComponentFunc();
|
|
279
167
|
if (__DEV__ && (WrappedComponent as any)?.navigationItem) {
|
|
@@ -287,57 +175,22 @@ class NavigationImpl implements Navigation {
|
|
|
287
175
|
CachedRootComponent = withNavigation(appKey)(WrappedComponent);
|
|
288
176
|
}
|
|
289
177
|
return CachedRootComponent;
|
|
290
|
-
};
|
|
291
|
-
this.routeLoaders.set(appKey, loader);
|
|
292
|
-
AppRegistry.registerComponent(appKey, loader);
|
|
178
|
+
});
|
|
293
179
|
return;
|
|
294
180
|
}
|
|
295
181
|
|
|
296
|
-
|
|
297
|
-
let WrappedComponent = RawComponent;
|
|
182
|
+
let WrappedComponent = getComponentFunc();
|
|
298
183
|
if (hoc) {
|
|
299
184
|
WrappedComponent = hoc(WrappedComponent);
|
|
300
185
|
}
|
|
301
186
|
|
|
302
|
-
const options: object =
|
|
303
|
-
routeConfig?.options ??
|
|
304
|
-
(RawComponent as any)?.navigationItem ??
|
|
305
|
-
(WrappedComponent as any)?.navigationItem ??
|
|
306
|
-
{};
|
|
187
|
+
const options: object = (WrappedComponent as any).navigationItem || {};
|
|
307
188
|
NativeNavigation.registerReactComponent(appKey, options);
|
|
308
189
|
|
|
309
190
|
const RootComponent = withNavigation(appKey)(WrappedComponent);
|
|
310
191
|
AppRegistry.registerComponent(appKey, () => RootComponent);
|
|
311
192
|
}
|
|
312
193
|
|
|
313
|
-
registerRoutes(routes: readonly RouteDefinition<any, any, any>[]) {
|
|
314
|
-
for (const route of routes) {
|
|
315
|
-
const hasConfig =
|
|
316
|
-
route.path !== undefined ||
|
|
317
|
-
route.dependency !== undefined ||
|
|
318
|
-
route.mode !== undefined ||
|
|
319
|
-
route.options !== undefined ||
|
|
320
|
-
route.lazy !== undefined;
|
|
321
|
-
const config: RouteConfig | undefined = hasConfig
|
|
322
|
-
? {
|
|
323
|
-
path: route.path,
|
|
324
|
-
dependency: route.dependency as RouteName | undefined,
|
|
325
|
-
mode: route.mode,
|
|
326
|
-
options: route.options,
|
|
327
|
-
lazy: route.lazy,
|
|
328
|
-
}
|
|
329
|
-
: undefined;
|
|
330
|
-
this.registerComponent(route.name as RouteName, route.load, config);
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
preloadRoute(moduleName: RouteName) {
|
|
335
|
-
const loader = this.routeLoaders.get(moduleName);
|
|
336
|
-
if (loader) {
|
|
337
|
-
loader();
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
|
|
341
194
|
addLifecycleListener(
|
|
342
195
|
sceneId: string,
|
|
343
196
|
listener: SceneLifecycleListener,
|
|
@@ -359,40 +212,9 @@ class NavigationImpl implements Navigation {
|
|
|
359
212
|
return lifecycleHandler.getSceneState(sceneId);
|
|
360
213
|
}
|
|
361
214
|
|
|
362
|
-
getSceneInfo(sceneId: string): SceneInfo | undefined {
|
|
363
|
-
return lifecycleHandler.getSceneInfo(sceneId);
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
addGlobalVisibilityEventListener(
|
|
367
|
-
listener: GlobalVisibilityEventListener,
|
|
368
|
-
): NavigationSubscription {
|
|
369
|
-
lifecycleHandler.addGlobalVisibilityEventListener(listener);
|
|
370
|
-
return {
|
|
371
|
-
remove: () => lifecycleHandler.removeGlobalVisibilityEventListener(listener),
|
|
372
|
-
};
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
addVisibilityEventListener(
|
|
376
|
-
sceneId: string,
|
|
377
|
-
listener: VisibilityEventListener,
|
|
378
|
-
): NavigationSubscription {
|
|
379
|
-
lifecycleHandler.addVisibilityEventListener(sceneId, listener);
|
|
380
|
-
return {
|
|
381
|
-
remove: () => lifecycleHandler.removeVisibilityEventListener(sceneId, listener),
|
|
382
|
-
};
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
addTabPressListener(listener: TabPressListener): NavigationSubscription {
|
|
386
|
-
const remove = tabEventHandler.addListener(listener);
|
|
387
|
-
return { remove };
|
|
388
|
-
}
|
|
389
215
|
|
|
390
216
|
dispatch(sceneId: string, action: string, params: DispatchParams = {}) {
|
|
391
|
-
|
|
392
|
-
params[BEFORE_REMOVE_SOURCE_PROP] !== undefined
|
|
393
|
-
? params
|
|
394
|
-
: { ...params, [BEFORE_REMOVE_SOURCE_PROP]: 'external' };
|
|
395
|
-
return dispatchHandler.dispatch(sceneId, action, nextParams);
|
|
217
|
+
return dispatchHandler.dispatch(sceneId, action, { ...params, [BEFORE_REMOVE_SOURCE_PROP]: 'external' });
|
|
396
218
|
}
|
|
397
219
|
|
|
398
220
|
addInterceptor(interceptor: NavigationInterceptor): NavigationSubscription {
|
|
@@ -402,59 +224,6 @@ class NavigationImpl implements Navigation {
|
|
|
402
224
|
};
|
|
403
225
|
}
|
|
404
226
|
|
|
405
|
-
registerSceneExitHandler(
|
|
406
|
-
sceneId: string,
|
|
407
|
-
handler: SceneExitHandler,
|
|
408
|
-
): NavigationSubscription {
|
|
409
|
-
const remove = presentationCoordinator.registerExitHandler(sceneId, handler);
|
|
410
|
-
return { remove };
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
addSceneCoverageListener(
|
|
414
|
-
sceneId: string,
|
|
415
|
-
listener: SceneCoverageListener,
|
|
416
|
-
): NavigationSubscription {
|
|
417
|
-
const remove = presentationCoordinator.addCoverageListener(sceneId, listener);
|
|
418
|
-
return { remove };
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
isSceneCovered(sceneId: string): Promise<boolean> {
|
|
422
|
-
return presentationCoordinator.isSceneVisuallyCovered(sceneId);
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
addBeforeRemoveListener(
|
|
426
|
-
sceneId: string,
|
|
427
|
-
listener: BeforeRemoveListener,
|
|
428
|
-
options?: BeforeRemoveOptions,
|
|
429
|
-
): NavigationSubscription {
|
|
430
|
-
const remove = leaveGuardHandler.addListener(sceneId, listener, options);
|
|
431
|
-
return { remove };
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
closeScene<T extends ResultMap = ResultMap>(
|
|
435
|
-
sceneId: string,
|
|
436
|
-
options?: CloseSelfOptions<T>,
|
|
437
|
-
): Promise<DispatchResult> {
|
|
438
|
-
return this.dispatch(sceneId, 'close', {
|
|
439
|
-
target: 'self' as const,
|
|
440
|
-
onCovered: options?.onCovered,
|
|
441
|
-
...(options?.bypassBeforeRemove ? { bypassBeforeRemove: true } : {}),
|
|
442
|
-
...(options?.result !== undefined ? { result: options.result } : {}),
|
|
443
|
-
});
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
reveal(target: RevealTarget, options?: RevealOptions): Promise<RevealResult> {
|
|
447
|
-
const task = this.revealQueue.then(
|
|
448
|
-
() => executeReveal(this, target, options),
|
|
449
|
-
() => executeReveal(this, target, options),
|
|
450
|
-
);
|
|
451
|
-
this.revealQueue = task.then(
|
|
452
|
-
() => undefined,
|
|
453
|
-
() => undefined,
|
|
454
|
-
);
|
|
455
|
-
return task;
|
|
456
|
-
}
|
|
457
|
-
|
|
458
227
|
setResult = <T extends ResultMap = ResultMap>(
|
|
459
228
|
sceneId: string,
|
|
460
229
|
resultCode: number,
|
|
@@ -467,7 +236,7 @@ class NavigationImpl implements Navigation {
|
|
|
467
236
|
return resultHandler.waitResult<T>(sceneId, requestCode);
|
|
468
237
|
}
|
|
469
238
|
|
|
470
|
-
setRoot(layout:
|
|
239
|
+
setRoot(layout: Layout, options?: SetRootOptions) {
|
|
471
240
|
return layoutHandler.setRoot(layout, options);
|
|
472
241
|
}
|
|
473
242
|
|
|
@@ -495,14 +264,32 @@ class NavigationImpl implements Navigation {
|
|
|
495
264
|
return NativeNavigation.currentRoute();
|
|
496
265
|
}
|
|
497
266
|
|
|
498
|
-
routeGraph(): Promise<RouteGraph[]> {
|
|
499
|
-
return NativeNavigation.routeGraph();
|
|
500
|
-
}
|
|
501
|
-
|
|
502
267
|
navigationSnapshot(): Promise<NavigationSnapshot> {
|
|
503
268
|
return NativeNavigation.navigationSnapshot();
|
|
504
269
|
}
|
|
505
270
|
|
|
271
|
+
addBeforeRemoveListener(
|
|
272
|
+
sceneId: string,
|
|
273
|
+
listener: BeforeRemoveListener,
|
|
274
|
+
options?: BeforeRemoveOptions,
|
|
275
|
+
): NavigationSubscription {
|
|
276
|
+
const remove = leaveGuardHandler.addListener(sceneId, listener, options);
|
|
277
|
+
return { remove };
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
async isSceneCovered(sceneId: string): Promise<boolean> {
|
|
281
|
+
try {
|
|
282
|
+
const { layers } = await NativeNavigation.navigationSnapshot();
|
|
283
|
+
return isSceneCoveredInLayers(layers, sceneId, 'visual');
|
|
284
|
+
} catch {
|
|
285
|
+
return false;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
async routeGraph(): Promise<RouteGraph[]> {
|
|
290
|
+
return (await NativeNavigation.navigationSnapshot()).layers;
|
|
291
|
+
}
|
|
292
|
+
|
|
506
293
|
setDefaultOptions(options: DefaultOptions) {
|
|
507
294
|
NativeNavigation.setDefaultOptions(options);
|
|
508
295
|
}
|
|
@@ -511,31 +298,13 @@ class NavigationImpl implements Navigation {
|
|
|
511
298
|
NativeNavigation.updateOptions(sceneId, options);
|
|
512
299
|
}
|
|
513
300
|
|
|
514
|
-
updateTabBar(options: TabBarStyle)
|
|
515
|
-
|
|
516
|
-
updateTabBar(sceneIdOrOptions: string | TabBarStyle, options?: TabBarStyle) {
|
|
517
|
-
if (typeof sceneIdOrOptions === 'string') {
|
|
518
|
-
NativeNavigation.updateTabBar(sceneIdOrOptions, options ?? {});
|
|
519
|
-
} else {
|
|
520
|
-
NativeNavigation.updateTabBar('', sceneIdOrOptions);
|
|
521
|
-
}
|
|
301
|
+
updateTabBar(sceneId: string, options: TabBarStyle) {
|
|
302
|
+
NativeNavigation.updateTabBar(sceneId, options);
|
|
522
303
|
}
|
|
523
304
|
|
|
524
|
-
setTabItem(item: TabItemInfo | TabItemInfo[])
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
sceneIdOrItem: string | TabItemInfo | TabItemInfo[],
|
|
528
|
-
item?: TabItemInfo | TabItemInfo[],
|
|
529
|
-
) {
|
|
530
|
-
if (typeof sceneIdOrItem === 'string') {
|
|
531
|
-
const items = Array.isArray(item) ? item : item ? [item] : [];
|
|
532
|
-
if (items.length > 0) {
|
|
533
|
-
NativeNavigation.setTabItem(sceneIdOrItem, items);
|
|
534
|
-
}
|
|
535
|
-
} else {
|
|
536
|
-
const items = Array.isArray(sceneIdOrItem) ? sceneIdOrItem : [sceneIdOrItem];
|
|
537
|
-
NativeNavigation.setTabItem('', items);
|
|
538
|
-
}
|
|
305
|
+
setTabItem(sceneId: string, item: TabItemInfo | TabItemInfo[]) {
|
|
306
|
+
const items = Array.isArray(item) ? item : [item];
|
|
307
|
+
NativeNavigation.setTabItem(sceneId, items);
|
|
539
308
|
}
|
|
540
309
|
|
|
541
310
|
setMenuInteractive(sceneId: string, enabled: boolean) {
|
|
@@ -1,23 +1,15 @@
|
|
|
1
1
|
import React, { useEffect } from 'react';
|
|
2
2
|
import type { NavigationItem } from './Options';
|
|
3
|
-
import type {
|
|
4
|
-
HasTypedRoutes,
|
|
5
|
-
InitialMetrics,
|
|
6
|
-
RegisteredRouteName,
|
|
7
|
-
RouteName,
|
|
8
|
-
RoutePropsOf,
|
|
9
|
-
} from './Route';
|
|
3
|
+
import type { HasTypedRoutes, InitialMetrics, RouteName, RoutePropsOf } from './Route';
|
|
10
4
|
import { Navigator, NavigationContext } from './Navigator';
|
|
11
5
|
import NativeNavigation from './NativeNavigation';
|
|
12
6
|
|
|
13
7
|
export type NavigationProps<Name extends RouteName = RouteName> = (HasTypedRoutes extends true
|
|
14
|
-
?
|
|
15
|
-
? RoutePropsOf<Name>
|
|
16
|
-
: Record<string, any>
|
|
8
|
+
? RoutePropsOf<Name>
|
|
17
9
|
: Record<string, any>) & {
|
|
18
10
|
navigator: Navigator<Name>;
|
|
19
|
-
sceneId: string;
|
|
20
11
|
initialMetrics?: InitialMetrics;
|
|
12
|
+
sceneId: string;
|
|
21
13
|
};
|
|
22
14
|
|
|
23
15
|
interface NativeProps {
|
package/src/Navigator.ts
CHANGED
|
@@ -7,7 +7,6 @@ import { lifecycleHandler } from './handler/LifecycleEventHandler';
|
|
|
7
7
|
import { RESULT_BLOCK, resultHandler } from './handler/ResultEventHandler';
|
|
8
8
|
import type { NavigationOption, TabBarStyle, TabItemInfo } from './Options';
|
|
9
9
|
import type {
|
|
10
|
-
BuildInLayout,
|
|
11
10
|
CloseSelfOptions,
|
|
12
11
|
DispatchResult,
|
|
13
12
|
Layout,
|
|
@@ -17,7 +16,6 @@ import type {
|
|
|
17
16
|
SceneLifecycleState,
|
|
18
17
|
ScreenPropsArgs,
|
|
19
18
|
SetResultData,
|
|
20
|
-
Visibility,
|
|
21
19
|
} from './Route';
|
|
22
20
|
|
|
23
21
|
export const NavigationContext = createContext<Navigator<any> | null>(null);
|
|
@@ -55,17 +53,6 @@ export class Navigator<CurrentRoute extends RouteName = RouteName> {
|
|
|
55
53
|
|
|
56
54
|
constructor(public sceneId: string, public moduleName?: string) {}
|
|
57
55
|
|
|
58
|
-
get visibility(): Visibility {
|
|
59
|
-
const state = lifecycleHandler.getSceneState(this.sceneId);
|
|
60
|
-
if (state === 'visible') {
|
|
61
|
-
return 'visible';
|
|
62
|
-
}
|
|
63
|
-
if (state === 'invisible' || state === 'destroyed') {
|
|
64
|
-
return 'invisible';
|
|
65
|
-
}
|
|
66
|
-
return 'pending';
|
|
67
|
-
}
|
|
68
|
-
|
|
69
56
|
get lifecycleState(): SceneLifecycleState {
|
|
70
57
|
return lifecycleHandler.getSceneState(this.sceneId);
|
|
71
58
|
}
|
|
@@ -76,13 +63,10 @@ export class Navigator<CurrentRoute extends RouteName = RouteName> {
|
|
|
76
63
|
warnOnFailure?: (code: DispatchResult['code']) => string,
|
|
77
64
|
): Promise<NavigationResult<T>> => {
|
|
78
65
|
const requestCode = --tagGenerator;
|
|
79
|
-
const { promise
|
|
80
|
-
|
|
81
|
-
requestCode,
|
|
82
|
-
);
|
|
83
|
-
let dispatchResult: DispatchResult;
|
|
66
|
+
const { promise, cancel } = resultHandler.prepareResult<T>(this.sceneId, requestCode);
|
|
67
|
+
let result: DispatchResult;
|
|
84
68
|
try {
|
|
85
|
-
|
|
69
|
+
result = await dispatchHandler.dispatch(this.sceneId, action, {
|
|
86
70
|
...params,
|
|
87
71
|
requestCode,
|
|
88
72
|
});
|
|
@@ -90,18 +74,14 @@ export class Navigator<CurrentRoute extends RouteName = RouteName> {
|
|
|
90
74
|
cancel();
|
|
91
75
|
throw error;
|
|
92
76
|
}
|
|
93
|
-
if (!
|
|
77
|
+
if (!result.ok) {
|
|
94
78
|
cancel();
|
|
95
79
|
if (warnOnFailure) {
|
|
96
|
-
console.warn(warnOnFailure(
|
|
80
|
+
console.warn(warnOnFailure(result.code));
|
|
97
81
|
}
|
|
98
|
-
return {
|
|
99
|
-
status: 'blocked',
|
|
100
|
-
code: RESULT_BLOCK,
|
|
101
|
-
reason: dispatchResult.code,
|
|
102
|
-
};
|
|
82
|
+
return { status: 'blocked', code: RESULT_BLOCK, reason: result.code };
|
|
103
83
|
}
|
|
104
|
-
return
|
|
84
|
+
return promise;
|
|
105
85
|
};
|
|
106
86
|
|
|
107
87
|
push = async <Name extends RouteName = RouteName, T = RouteResultOf<Name>>(
|
|
@@ -119,7 +99,7 @@ export class Navigator<CurrentRoute extends RouteName = RouteName> {
|
|
|
119
99
|
};
|
|
120
100
|
|
|
121
101
|
pushLayout = async <T = unknown>(
|
|
122
|
-
layout:
|
|
102
|
+
layout: Layout,
|
|
123
103
|
): Promise<NavigationResult<T>> => {
|
|
124
104
|
return this.dispatchForResult<T>('pushLayout', {
|
|
125
105
|
from: this.moduleName,
|
|
@@ -177,7 +157,7 @@ export class Navigator<CurrentRoute extends RouteName = RouteName> {
|
|
|
177
157
|
};
|
|
178
158
|
|
|
179
159
|
presentLayout = async <T = unknown>(
|
|
180
|
-
layout:
|
|
160
|
+
layout: Layout,
|
|
181
161
|
): Promise<NavigationResult<T>> => {
|
|
182
162
|
return this.dispatchForResult<T>(
|
|
183
163
|
'presentLayout',
|
|
@@ -192,17 +172,12 @@ export class Navigator<CurrentRoute extends RouteName = RouteName> {
|
|
|
192
172
|
dismiss = (): Promise<DispatchResult> =>
|
|
193
173
|
dispatchHandler.dispatch(this.sceneId, 'dismiss', { from: this.moduleName });
|
|
194
174
|
|
|
195
|
-
closeSelf = (
|
|
196
|
-
|
|
197
|
-
): Promise<DispatchResult> => {
|
|
198
|
-
return dispatchHandler.dispatch(this.sceneId, 'close', {
|
|
175
|
+
closeSelf = (options?: CloseSelfOptions<SetResultData<CurrentRoute>>): Promise<DispatchResult> =>
|
|
176
|
+
dispatchHandler.dispatch(this.sceneId, 'close', {
|
|
199
177
|
from: this.moduleName,
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
...(options?.bypassBeforeRemove ? { bypassBeforeRemove: true } : {}),
|
|
203
|
-
...(options?.result !== undefined ? { result: options.result } : {}),
|
|
178
|
+
...(options?.bypassBeforeRemove && { bypassBeforeRemove: true }),
|
|
179
|
+
...(options?.result && { result: resultHandler.normalizePendingResult(options.result) }),
|
|
204
180
|
});
|
|
205
|
-
};
|
|
206
181
|
|
|
207
182
|
showModal = async <Name extends RouteName = RouteName, T = RouteResultOf<Name>>(
|
|
208
183
|
moduleName: Name,
|
|
@@ -223,7 +198,7 @@ export class Navigator<CurrentRoute extends RouteName = RouteName> {
|
|
|
223
198
|
};
|
|
224
199
|
|
|
225
200
|
showModalLayout = async <T = unknown>(
|
|
226
|
-
layout:
|
|
201
|
+
layout: Layout,
|
|
227
202
|
): Promise<NavigationResult<T>> => {
|
|
228
203
|
return this.dispatchForResult<T>(
|
|
229
204
|
'showModalLayout',
|
|
@@ -248,16 +223,10 @@ export class Navigator<CurrentRoute extends RouteName = RouteName> {
|
|
|
248
223
|
popToRoot: boolean = false,
|
|
249
224
|
): Promise<DispatchResult> => {
|
|
250
225
|
const from = await NativeNavigation.currentTab(this.sceneId);
|
|
251
|
-
if (typeof target === 'string') {
|
|
252
|
-
return dispatchHandler.dispatch(this.sceneId, 'switchTab', {
|
|
253
|
-
from,
|
|
254
|
-
tabKey: target,
|
|
255
|
-
popToRoot,
|
|
256
|
-
});
|
|
257
|
-
}
|
|
258
226
|
return dispatchHandler.dispatch(this.sceneId, 'switchTab', {
|
|
259
227
|
from,
|
|
260
228
|
to: target,
|
|
229
|
+
...(typeof target === 'string' && { tabKey: target }),
|
|
261
230
|
popToRoot,
|
|
262
231
|
});
|
|
263
232
|
};
|
package/src/Options.ts
CHANGED
|
@@ -44,8 +44,7 @@ export interface ShadowImage {
|
|
|
44
44
|
|
|
45
45
|
export interface DefaultOptions {
|
|
46
46
|
screenBackgroundColor?: Color; // 页面背景,默认是白色
|
|
47
|
-
|
|
48
|
-
injectInitialMetrics?: boolean; // 是否为同向全屏场景注入首帧安全区 initialMetrics(默认 false)
|
|
47
|
+
injectInitialMetrics?: boolean; // 同向全屏场景的首帧安全区,默认关闭
|
|
49
48
|
prewarmPush?: boolean; // 是否对有动画的同向全屏主栈 push 启用离屏 Fabric 首帧预热(默认 false)
|
|
50
49
|
statusBarStyle?: BarStyle; // 状态栏样式,可选项有 `BarStyleLightContent` 和 `BarStyleDarkContent`
|
|
51
50
|
navigationBarColorAndroid?: Color; // 底部虚拟键背景颜色,仅对 Android 8.0 以上版本生效
|
|
@@ -67,7 +66,7 @@ export type TabBarStyle = Pick<
|
|
|
67
66
|
| 'tabBarItemNormalColor'
|
|
68
67
|
>;
|
|
69
68
|
|
|
70
|
-
|
|
69
|
+
interface TabItemInfoBase {
|
|
71
70
|
title?: string;
|
|
72
71
|
badge?: {
|
|
73
72
|
text?: string;
|