hybrid-navigation 5.1.1 → 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 -20
- package/dist/Navigation.js +32 -163
- package/dist/NavigationComponentWrap.d.ts +3 -3
- package/dist/Navigator.d.ts +4 -5
- package/dist/Navigator.js +13 -36
- package/dist/Options.d.ts +2 -2
- package/dist/Route.d.ts +12 -33
- package/dist/handler/DispatchCommandHandler.d.ts +3 -17
- package/dist/handler/DispatchCommandHandler.js +17 -62
- package/dist/handler/LayoutCommandHandler.d.ts +2 -3
- package/dist/handler/LayoutCommandHandler.js +0 -3
- package/dist/handler/LeaveGuardHandler.d.ts +2 -2
- package/dist/handler/LeaveGuardHandler.js +88 -46
- 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 +2 -2
- package/dist/hooks.js +39 -22
- 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/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 +49 -257
- package/src/NavigationComponentWrap.tsx +3 -11
- package/src/Navigator.ts +15 -45
- package/src/Options.ts +2 -3
- package/src/Route.ts +17 -54
- package/src/handler/DispatchCommandHandler.ts +29 -109
- package/src/handler/LayoutCommandHandler.ts +2 -6
- package/src/handler/LeaveGuardHandler.ts +97 -46
- 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 +39 -22
- package/src/index.ts +0 -14
- package/src/router/index.ts +45 -12
- 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 -24
- package/dist/handler/PresentationCoordinator.js +0 -456
- 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 -79
- package/dist/testing.js +0 -251
- package/ios/ViewController/HBDTabBarRenderer.h +0 -28
- package/src/defineRoutes.ts +0 -46
- package/src/handler/PresentationCoordinator.ts +0 -566
- package/src/handler/TabEventHandler.ts +0 -31
- package/src/reveal.ts +0 -565
- package/src/routeGraph.ts +0 -87
- package/src/testing.ts +0 -395
- package/testing.d.ts +0 -1
- package/testing.js +0 -3
package/dist/Navigation.js
CHANGED
|
@@ -1,51 +1,35 @@
|
|
|
1
1
|
import { AppRegistry } from 'react-native';
|
|
2
2
|
import { layoutHandler } from './handler/LayoutCommandHandler';
|
|
3
3
|
import { dispatchHandler } from './handler/DispatchCommandHandler';
|
|
4
|
-
import { leaveGuardHandler } from './handler/LeaveGuardHandler';
|
|
5
|
-
import { presentationCoordinator } from './handler/PresentationCoordinator';
|
|
6
|
-
import { tabEventHandler } from './handler/TabEventHandler';
|
|
7
|
-
import { executeReveal } from './reveal';
|
|
8
4
|
import { RESULT_BLOCK, RESULT_CANCEL, RESULT_OK, resultHandler, } from './handler/ResultEventHandler';
|
|
9
5
|
import { lifecycleHandler, } from './handler/LifecycleEventHandler';
|
|
6
|
+
import { leaveGuardHandler, BEFORE_REMOVE_SOURCE_PROP } from './handler/LeaveGuardHandler';
|
|
10
7
|
import NativeNavigation from './NativeNavigation';
|
|
8
|
+
import { isSceneCoveredInLayers } from './sceneCoverage';
|
|
11
9
|
import store from './store';
|
|
12
10
|
import { withNavigation } from './NavigationComponentWrap';
|
|
13
|
-
import { bumpRouteConfigVersion, clearRouteConfigs,
|
|
11
|
+
import { bumpRouteConfigVersion, clearRouteConfigs, setRouteConfig, } from './routeConfigRegistry';
|
|
14
12
|
export { RESULT_CANCEL, RESULT_OK, RESULT_BLOCK };
|
|
15
13
|
class NavigationImpl {
|
|
16
14
|
constructor() {
|
|
17
15
|
leaveGuardHandler.setDispatcher((sceneId, action, params) => dispatchHandler.dispatch(sceneId, action, params));
|
|
18
|
-
|
|
19
|
-
dispatchHandler.addMiddleware(dispatchHandler.interceptorMiddleware);
|
|
20
|
-
dispatchHandler.addMiddleware(presentationCoordinator.middleware);
|
|
16
|
+
leaveGuardHandler.handleNativeBeforeRemoveRequests();
|
|
21
17
|
layoutHandler.handleRootLayoutChange(() => {
|
|
22
|
-
lifecycleHandler.onRootReset();
|
|
23
18
|
leaveGuardHandler.onRootReset();
|
|
24
|
-
presentationCoordinator.onRootReset();
|
|
25
19
|
resultHandler.invalidateAll('root_reset');
|
|
26
20
|
});
|
|
27
21
|
lifecycleHandler.handleSceneLifecycle(sceneId => {
|
|
28
22
|
leaveGuardHandler.onSceneDestroyed(sceneId);
|
|
29
|
-
presentationCoordinator.onSceneDestroyed(sceneId);
|
|
30
23
|
resultHandler.invalidateResultEventListener(sceneId, 'unmounted');
|
|
31
24
|
store.removeNavigator(sceneId);
|
|
32
25
|
});
|
|
33
26
|
resultHandler.handleComponentResult();
|
|
34
|
-
leaveGuardHandler.handleNativeBeforeRemoveRequests();
|
|
35
|
-
tabEventHandler.handleTabPress();
|
|
36
27
|
}
|
|
37
28
|
hoc;
|
|
38
29
|
registerEnded = false;
|
|
39
|
-
registeredNames = new Set();
|
|
40
|
-
registeredPaths = new Map();
|
|
41
|
-
routeLoaders = new Map();
|
|
42
|
-
revealQueue = Promise.resolve();
|
|
43
30
|
startRegisterComponent(hoc) {
|
|
44
31
|
this.hoc = hoc;
|
|
45
32
|
this.registerEnded = false;
|
|
46
|
-
this.registeredNames.clear();
|
|
47
|
-
this.registeredPaths.clear();
|
|
48
|
-
this.routeLoaders.clear();
|
|
49
33
|
clearRouteConfigs();
|
|
50
34
|
NativeNavigation.startRegisterReactComponent();
|
|
51
35
|
}
|
|
@@ -55,63 +39,18 @@ class NavigationImpl {
|
|
|
55
39
|
return;
|
|
56
40
|
}
|
|
57
41
|
this.registerEnded = true;
|
|
58
|
-
if (__DEV__) {
|
|
59
|
-
this.validateRouteDependencies();
|
|
60
|
-
}
|
|
61
42
|
bumpRouteConfigVersion();
|
|
62
43
|
NativeNavigation.endRegisterReactComponent();
|
|
63
44
|
}
|
|
64
|
-
validateRouteDependencies() {
|
|
65
|
-
const configs = getRouteConfigs();
|
|
66
|
-
const state = new Map();
|
|
67
|
-
const stack = [];
|
|
68
|
-
const visit = (name) => {
|
|
69
|
-
state.set(name, 'visiting');
|
|
70
|
-
stack.push(name);
|
|
71
|
-
const dependency = configs.get(name)?.dependency;
|
|
72
|
-
if (dependency) {
|
|
73
|
-
const depState = state.get(dependency);
|
|
74
|
-
if (depState === 'visiting') {
|
|
75
|
-
const cycleStart = stack.indexOf(dependency);
|
|
76
|
-
const cycle = [...stack.slice(cycleStart), dependency].join(' -> ');
|
|
77
|
-
console.warn(`[hybrid-navigation] Circular route dependency detected: ${cycle}`);
|
|
78
|
-
}
|
|
79
|
-
else if (!depState && configs.has(dependency)) {
|
|
80
|
-
visit(dependency);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
stack.pop();
|
|
84
|
-
state.set(name, 'visited');
|
|
85
|
-
};
|
|
86
|
-
for (const name of configs.keys()) {
|
|
87
|
-
if (!state.has(name)) {
|
|
88
|
-
visit(name);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
45
|
registerComponent(appKey, getComponentFunc, routeConfig) {
|
|
93
|
-
if (__DEV__) {
|
|
94
|
-
if (this.registeredNames.has(appKey)) {
|
|
95
|
-
console.warn(`[hybrid-navigation] Duplicate route registration for "${appKey}". Later registration overrides earlier one.`);
|
|
96
|
-
}
|
|
97
|
-
if (routeConfig?.path) {
|
|
98
|
-
const existing = this.registeredPaths.get(routeConfig.path);
|
|
99
|
-
if (existing && existing !== appKey) {
|
|
100
|
-
console.warn(`[hybrid-navigation] Duplicate route path "${routeConfig.path}" registered by "${appKey}" and "${existing}".`);
|
|
101
|
-
}
|
|
102
|
-
this.registeredPaths.set(routeConfig.path, appKey);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
this.registeredNames.add(appKey);
|
|
106
46
|
if (routeConfig && (routeConfig.path || routeConfig.dependency || routeConfig.mode)) {
|
|
107
47
|
setRouteConfig(appKey, routeConfig);
|
|
108
48
|
}
|
|
109
49
|
const hoc = this.hoc;
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
NativeNavigation.registerReactComponent(appKey, routeConfig?.options ?? {});
|
|
50
|
+
if (routeConfig?.options !== undefined || routeConfig?.lazy === true) {
|
|
51
|
+
NativeNavigation.registerReactComponent(appKey, routeConfig.options ?? {});
|
|
113
52
|
let CachedRootComponent;
|
|
114
|
-
|
|
53
|
+
AppRegistry.registerComponent(appKey, () => {
|
|
115
54
|
if (!CachedRootComponent) {
|
|
116
55
|
let WrappedComponent = getComponentFunc();
|
|
117
56
|
if (__DEV__ && WrappedComponent?.navigationItem) {
|
|
@@ -123,49 +62,18 @@ class NavigationImpl {
|
|
|
123
62
|
CachedRootComponent = withNavigation(appKey)(WrappedComponent);
|
|
124
63
|
}
|
|
125
64
|
return CachedRootComponent;
|
|
126
|
-
};
|
|
127
|
-
this.routeLoaders.set(appKey, loader);
|
|
128
|
-
AppRegistry.registerComponent(appKey, loader);
|
|
65
|
+
});
|
|
129
66
|
return;
|
|
130
67
|
}
|
|
131
|
-
|
|
132
|
-
let WrappedComponent = RawComponent;
|
|
68
|
+
let WrappedComponent = getComponentFunc();
|
|
133
69
|
if (hoc) {
|
|
134
70
|
WrappedComponent = hoc(WrappedComponent);
|
|
135
71
|
}
|
|
136
|
-
const options =
|
|
137
|
-
RawComponent?.navigationItem ??
|
|
138
|
-
WrappedComponent?.navigationItem ??
|
|
139
|
-
{};
|
|
72
|
+
const options = WrappedComponent.navigationItem || {};
|
|
140
73
|
NativeNavigation.registerReactComponent(appKey, options);
|
|
141
74
|
const RootComponent = withNavigation(appKey)(WrappedComponent);
|
|
142
75
|
AppRegistry.registerComponent(appKey, () => RootComponent);
|
|
143
76
|
}
|
|
144
|
-
registerRoutes(routes) {
|
|
145
|
-
for (const route of routes) {
|
|
146
|
-
const hasConfig = route.path !== undefined ||
|
|
147
|
-
route.dependency !== undefined ||
|
|
148
|
-
route.mode !== undefined ||
|
|
149
|
-
route.options !== undefined ||
|
|
150
|
-
route.lazy !== undefined;
|
|
151
|
-
const config = hasConfig
|
|
152
|
-
? {
|
|
153
|
-
path: route.path,
|
|
154
|
-
dependency: route.dependency,
|
|
155
|
-
mode: route.mode,
|
|
156
|
-
options: route.options,
|
|
157
|
-
lazy: route.lazy,
|
|
158
|
-
}
|
|
159
|
-
: undefined;
|
|
160
|
-
this.registerComponent(route.name, route.load, config);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
preloadRoute(moduleName) {
|
|
164
|
-
const loader = this.routeLoaders.get(moduleName);
|
|
165
|
-
if (loader) {
|
|
166
|
-
loader();
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
77
|
addLifecycleListener(sceneId, listener) {
|
|
170
78
|
lifecycleHandler.addLifecycleListener(sceneId, listener);
|
|
171
79
|
return {
|
|
@@ -181,27 +89,8 @@ class NavigationImpl {
|
|
|
181
89
|
getSceneState(sceneId) {
|
|
182
90
|
return lifecycleHandler.getSceneState(sceneId);
|
|
183
91
|
}
|
|
184
|
-
getSceneInfo(sceneId) {
|
|
185
|
-
return lifecycleHandler.getSceneInfo(sceneId);
|
|
186
|
-
}
|
|
187
|
-
addGlobalVisibilityEventListener(listener) {
|
|
188
|
-
lifecycleHandler.addGlobalVisibilityEventListener(listener);
|
|
189
|
-
return {
|
|
190
|
-
remove: () => lifecycleHandler.removeGlobalVisibilityEventListener(listener),
|
|
191
|
-
};
|
|
192
|
-
}
|
|
193
|
-
addVisibilityEventListener(sceneId, listener) {
|
|
194
|
-
lifecycleHandler.addVisibilityEventListener(sceneId, listener);
|
|
195
|
-
return {
|
|
196
|
-
remove: () => lifecycleHandler.removeVisibilityEventListener(sceneId, listener),
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
addTabPressListener(listener) {
|
|
200
|
-
const remove = tabEventHandler.addListener(listener);
|
|
201
|
-
return { remove };
|
|
202
|
-
}
|
|
203
92
|
dispatch(sceneId, action, params = {}) {
|
|
204
|
-
return dispatchHandler.dispatch(sceneId, action, params);
|
|
93
|
+
return dispatchHandler.dispatch(sceneId, action, { ...params, [BEFORE_REMOVE_SOURCE_PROP]: 'external' });
|
|
205
94
|
}
|
|
206
95
|
addInterceptor(interceptor) {
|
|
207
96
|
dispatchHandler.addInterceptor(interceptor);
|
|
@@ -209,26 +98,6 @@ class NavigationImpl {
|
|
|
209
98
|
remove: () => dispatchHandler.removeInterceptor(interceptor),
|
|
210
99
|
};
|
|
211
100
|
}
|
|
212
|
-
registerSceneExitHandler(sceneId, handler) {
|
|
213
|
-
const remove = presentationCoordinator.registerExitHandler(sceneId, handler);
|
|
214
|
-
return { remove };
|
|
215
|
-
}
|
|
216
|
-
addBeforeRemoveListener(sceneId, listener, options) {
|
|
217
|
-
const remove = leaveGuardHandler.addListener(sceneId, listener, options);
|
|
218
|
-
return { remove };
|
|
219
|
-
}
|
|
220
|
-
closeScene(sceneId, options) {
|
|
221
|
-
return this.dispatch(sceneId, 'close', {
|
|
222
|
-
target: 'self',
|
|
223
|
-
onCovered: options?.onCovered,
|
|
224
|
-
...(options?.result !== undefined ? { result: options.result } : {}),
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
|
-
reveal(target, options) {
|
|
228
|
-
const task = this.revealQueue.then(() => executeReveal(this, target, options), () => executeReveal(this, target, options));
|
|
229
|
-
this.revealQueue = task.then(() => undefined, () => undefined);
|
|
230
|
-
return task;
|
|
231
|
-
}
|
|
232
101
|
setResult = (sceneId, resultCode, data = null) => {
|
|
233
102
|
resultHandler.setResult(sceneId, resultCode, data);
|
|
234
103
|
};
|
|
@@ -254,37 +123,37 @@ class NavigationImpl {
|
|
|
254
123
|
currentRoute() {
|
|
255
124
|
return NativeNavigation.currentRoute();
|
|
256
125
|
}
|
|
257
|
-
routeGraph() {
|
|
258
|
-
return NativeNavigation.routeGraph();
|
|
259
|
-
}
|
|
260
126
|
navigationSnapshot() {
|
|
261
127
|
return NativeNavigation.navigationSnapshot();
|
|
262
128
|
}
|
|
129
|
+
addBeforeRemoveListener(sceneId, listener, options) {
|
|
130
|
+
const remove = leaveGuardHandler.addListener(sceneId, listener, options);
|
|
131
|
+
return { remove };
|
|
132
|
+
}
|
|
133
|
+
async isSceneCovered(sceneId) {
|
|
134
|
+
try {
|
|
135
|
+
const { layers } = await NativeNavigation.navigationSnapshot();
|
|
136
|
+
return isSceneCoveredInLayers(layers, sceneId, 'visual');
|
|
137
|
+
}
|
|
138
|
+
catch {
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
async routeGraph() {
|
|
143
|
+
return (await NativeNavigation.navigationSnapshot()).layers;
|
|
144
|
+
}
|
|
263
145
|
setDefaultOptions(options) {
|
|
264
146
|
NativeNavigation.setDefaultOptions(options);
|
|
265
147
|
}
|
|
266
148
|
updateOptions(sceneId, options) {
|
|
267
149
|
NativeNavigation.updateOptions(sceneId, options);
|
|
268
150
|
}
|
|
269
|
-
updateTabBar(
|
|
270
|
-
|
|
271
|
-
NativeNavigation.updateTabBar(sceneIdOrOptions, options ?? {});
|
|
272
|
-
}
|
|
273
|
-
else {
|
|
274
|
-
NativeNavigation.updateTabBar('', sceneIdOrOptions);
|
|
275
|
-
}
|
|
151
|
+
updateTabBar(sceneId, options) {
|
|
152
|
+
NativeNavigation.updateTabBar(sceneId, options);
|
|
276
153
|
}
|
|
277
|
-
setTabItem(
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
if (items.length > 0) {
|
|
281
|
-
NativeNavigation.setTabItem(sceneIdOrItem, items);
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
else {
|
|
285
|
-
const items = Array.isArray(sceneIdOrItem) ? sceneIdOrItem : [sceneIdOrItem];
|
|
286
|
-
NativeNavigation.setTabItem('', items);
|
|
287
|
-
}
|
|
154
|
+
setTabItem(sceneId, item) {
|
|
155
|
+
const items = Array.isArray(item) ? item : [item];
|
|
156
|
+
NativeNavigation.setTabItem(sceneId, items);
|
|
288
157
|
}
|
|
289
158
|
setMenuInteractive(sceneId, enabled) {
|
|
290
159
|
return this.dispatch(sceneId, 'setMenuInteractive', { enabled });
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { NavigationItem } from './Options';
|
|
3
|
-
import type { HasTypedRoutes, InitialMetrics,
|
|
3
|
+
import type { HasTypedRoutes, InitialMetrics, RouteName, RoutePropsOf } from './Route';
|
|
4
4
|
import { Navigator } from './Navigator';
|
|
5
|
-
export type NavigationProps<Name extends RouteName = RouteName> = (HasTypedRoutes extends true ?
|
|
5
|
+
export type NavigationProps<Name extends RouteName = RouteName> = (HasTypedRoutes extends true ? RoutePropsOf<Name> : Record<string, any>) & {
|
|
6
6
|
navigator: Navigator<Name>;
|
|
7
|
-
sceneId: string;
|
|
8
7
|
initialMetrics?: InitialMetrics;
|
|
8
|
+
sceneId: string;
|
|
9
9
|
};
|
|
10
10
|
interface NativeProps {
|
|
11
11
|
sceneId: string;
|
package/dist/Navigator.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { NavigationOption, TabBarStyle, TabItemInfo } from './Options';
|
|
2
|
-
import type {
|
|
2
|
+
import type { CloseSelfOptions, DispatchResult, Layout, NavigationResult, RouteName, RouteResultOf, SceneLifecycleState, ScreenPropsArgs, SetResultData } from './Route';
|
|
3
3
|
export declare const NavigationContext: import("react").Context<Navigator<any> | null>;
|
|
4
4
|
export declare class Navigator<CurrentRoute extends RouteName = RouteName> {
|
|
5
5
|
sceneId: string;
|
|
@@ -8,21 +8,20 @@ export declare class Navigator<CurrentRoute extends RouteName = RouteName> {
|
|
|
8
8
|
static find<Name extends RouteName = RouteName>(moduleName: Name): Promise<Navigator<Name> | undefined>;
|
|
9
9
|
static current(): Promise<Navigator | undefined>;
|
|
10
10
|
constructor(sceneId: string, moduleName?: string | undefined);
|
|
11
|
-
get visibility(): Visibility;
|
|
12
11
|
get lifecycleState(): SceneLifecycleState;
|
|
13
12
|
private dispatchForResult;
|
|
14
13
|
push: <Name extends RouteName = RouteName, T = RouteResultOf<Name>>(moduleName: Name, ...args: ScreenPropsArgs<Name>) => Promise<NavigationResult<T>>;
|
|
15
|
-
pushLayout: <T = unknown>(layout:
|
|
14
|
+
pushLayout: <T = unknown>(layout: Layout) => Promise<NavigationResult<T>>;
|
|
16
15
|
pop: () => Promise<DispatchResult>;
|
|
17
16
|
popTo: (moduleName: RouteName | (string & {}), inclusive?: boolean) => Promise<DispatchResult>;
|
|
18
17
|
popToRoot: () => Promise<DispatchResult>;
|
|
19
18
|
redirectTo: <Name extends RouteName = RouteName>(moduleName: Name, ...args: ScreenPropsArgs<Name>) => Promise<DispatchResult>;
|
|
20
19
|
present: <Name extends RouteName = RouteName, T = RouteResultOf<Name>>(moduleName: Name, ...args: ScreenPropsArgs<Name>) => Promise<NavigationResult<T>>;
|
|
21
|
-
presentLayout: <T = unknown>(layout:
|
|
20
|
+
presentLayout: <T = unknown>(layout: Layout) => Promise<NavigationResult<T>>;
|
|
22
21
|
dismiss: () => Promise<DispatchResult>;
|
|
23
22
|
closeSelf: (options?: CloseSelfOptions<SetResultData<CurrentRoute>>) => Promise<DispatchResult>;
|
|
24
23
|
showModal: <Name extends RouteName = RouteName, T = RouteResultOf<Name>>(moduleName: Name, ...args: ScreenPropsArgs<Name>) => Promise<NavigationResult<T>>;
|
|
25
|
-
showModalLayout: <T = unknown>(layout:
|
|
24
|
+
showModalLayout: <T = unknown>(layout: Layout) => Promise<NavigationResult<T>>;
|
|
26
25
|
hideModal: () => Promise<DispatchResult>;
|
|
27
26
|
setResult: (resultCode: number, data?: SetResultData<CurrentRoute> | null) => void;
|
|
28
27
|
switchTab: (target: number | string, popToRoot?: boolean) => Promise<DispatchResult>;
|
package/dist/Navigator.js
CHANGED
|
@@ -36,25 +36,15 @@ export class Navigator {
|
|
|
36
36
|
this.sceneId = sceneId;
|
|
37
37
|
this.moduleName = moduleName;
|
|
38
38
|
}
|
|
39
|
-
get visibility() {
|
|
40
|
-
const state = lifecycleHandler.getSceneState(this.sceneId);
|
|
41
|
-
if (state === 'visible') {
|
|
42
|
-
return 'visible';
|
|
43
|
-
}
|
|
44
|
-
if (state === 'invisible' || state === 'destroyed') {
|
|
45
|
-
return 'invisible';
|
|
46
|
-
}
|
|
47
|
-
return 'pending';
|
|
48
|
-
}
|
|
49
39
|
get lifecycleState() {
|
|
50
40
|
return lifecycleHandler.getSceneState(this.sceneId);
|
|
51
41
|
}
|
|
52
42
|
dispatchForResult = async (action, params, warnOnFailure) => {
|
|
53
43
|
const requestCode = --tagGenerator;
|
|
54
|
-
const { promise
|
|
55
|
-
let
|
|
44
|
+
const { promise, cancel } = resultHandler.prepareResult(this.sceneId, requestCode);
|
|
45
|
+
let result;
|
|
56
46
|
try {
|
|
57
|
-
|
|
47
|
+
result = await dispatchHandler.dispatch(this.sceneId, action, {
|
|
58
48
|
...params,
|
|
59
49
|
requestCode,
|
|
60
50
|
});
|
|
@@ -63,18 +53,14 @@ export class Navigator {
|
|
|
63
53
|
cancel();
|
|
64
54
|
throw error;
|
|
65
55
|
}
|
|
66
|
-
if (!
|
|
56
|
+
if (!result.ok) {
|
|
67
57
|
cancel();
|
|
68
58
|
if (warnOnFailure) {
|
|
69
|
-
console.warn(warnOnFailure(
|
|
59
|
+
console.warn(warnOnFailure(result.code));
|
|
70
60
|
}
|
|
71
|
-
return {
|
|
72
|
-
status: 'blocked',
|
|
73
|
-
code: RESULT_BLOCK,
|
|
74
|
-
reason: dispatchResult.code,
|
|
75
|
-
};
|
|
61
|
+
return { status: 'blocked', code: RESULT_BLOCK, reason: result.code };
|
|
76
62
|
}
|
|
77
|
-
return
|
|
63
|
+
return promise;
|
|
78
64
|
};
|
|
79
65
|
push = async (moduleName, ...args) => {
|
|
80
66
|
const [props = {}, options = {}] = args;
|
|
@@ -127,14 +113,11 @@ export class Navigator {
|
|
|
127
113
|
}, code => `presentLayout from:${this.moduleName} failed (${code}).`);
|
|
128
114
|
};
|
|
129
115
|
dismiss = () => dispatchHandler.dispatch(this.sceneId, 'dismiss', { from: this.moduleName });
|
|
130
|
-
closeSelf = (options) => {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
...(options?.result !== undefined ? { result: options.result } : {}),
|
|
136
|
-
});
|
|
137
|
-
};
|
|
116
|
+
closeSelf = (options) => dispatchHandler.dispatch(this.sceneId, 'close', {
|
|
117
|
+
from: this.moduleName,
|
|
118
|
+
...(options?.bypassBeforeRemove && { bypassBeforeRemove: true }),
|
|
119
|
+
...(options?.result && { result: resultHandler.normalizePendingResult(options.result) }),
|
|
120
|
+
});
|
|
138
121
|
showModal = async (moduleName, ...args) => {
|
|
139
122
|
const [props = {}, options = {}] = args;
|
|
140
123
|
return this.dispatchForResult('showModal', {
|
|
@@ -155,16 +138,10 @@ export class Navigator {
|
|
|
155
138
|
setResult = (resultCode, data = null) => resultHandler.setResult(this.sceneId, resultCode, data);
|
|
156
139
|
switchTab = async (target, popToRoot = false) => {
|
|
157
140
|
const from = await NativeNavigation.currentTab(this.sceneId);
|
|
158
|
-
if (typeof target === 'string') {
|
|
159
|
-
return dispatchHandler.dispatch(this.sceneId, 'switchTab', {
|
|
160
|
-
from,
|
|
161
|
-
tabKey: target,
|
|
162
|
-
popToRoot,
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
141
|
return dispatchHandler.dispatch(this.sceneId, 'switchTab', {
|
|
166
142
|
from,
|
|
167
143
|
to: target,
|
|
144
|
+
...(typeof target === 'string' && { tabKey: target }),
|
|
168
145
|
popToRoot,
|
|
169
146
|
});
|
|
170
147
|
};
|
package/dist/Options.d.ts
CHANGED
|
@@ -38,7 +38,6 @@ export interface ShadowImage {
|
|
|
38
38
|
}
|
|
39
39
|
export interface DefaultOptions {
|
|
40
40
|
screenBackgroundColor?: Color;
|
|
41
|
-
modalBackgroundColor?: Color;
|
|
42
41
|
injectInitialMetrics?: boolean;
|
|
43
42
|
prewarmPush?: boolean;
|
|
44
43
|
statusBarStyle?: BarStyle;
|
|
@@ -52,7 +51,7 @@ export interface DefaultOptions {
|
|
|
52
51
|
tabBarBadgeColor?: Color;
|
|
53
52
|
}
|
|
54
53
|
export type TabBarStyle = Pick<DefaultOptions, 'tabBarBackgroundColor' | 'tabBarShadowImage' | 'tabBarItemSelectedColor' | 'tabBarItemNormalColor'>;
|
|
55
|
-
|
|
54
|
+
interface TabItemInfoBase {
|
|
56
55
|
title?: string;
|
|
57
56
|
badge?: {
|
|
58
57
|
text?: string;
|
|
@@ -71,3 +70,4 @@ export type TabItemInfo = (TabItemInfoBase & {
|
|
|
71
70
|
key: string;
|
|
72
71
|
index?: number;
|
|
73
72
|
});
|
|
73
|
+
export {};
|
package/dist/Route.d.ts
CHANGED
|
@@ -1,26 +1,6 @@
|
|
|
1
1
|
import type { NavigationItem } from './Options';
|
|
2
|
-
import type { CustomLayoutMap, NavigationParamList
|
|
3
|
-
export type Visibility = 'visible' | 'invisible' | 'pending';
|
|
2
|
+
import type { CustomLayoutMap, NavigationParamList } from './index';
|
|
4
3
|
export type SceneLifecycleState = 'created' | 'visible' | 'invisible' | 'destroyed';
|
|
5
|
-
export interface SceneInfo {
|
|
6
|
-
sceneId: string;
|
|
7
|
-
moduleName?: string;
|
|
8
|
-
mode: LayoutMode;
|
|
9
|
-
presentingId: string | null;
|
|
10
|
-
state: SceneLifecycleState;
|
|
11
|
-
}
|
|
12
|
-
export interface TabPressEvent {
|
|
13
|
-
index: number;
|
|
14
|
-
tabKey?: string;
|
|
15
|
-
previousIndex: number;
|
|
16
|
-
reselected: boolean;
|
|
17
|
-
}
|
|
18
|
-
export type TabPressListener = (event: TabPressEvent) => void;
|
|
19
|
-
export interface NavigationSnapshot {
|
|
20
|
-
rootGeneration: number;
|
|
21
|
-
currentRoute: Route | null;
|
|
22
|
-
layers: RouteGraph[];
|
|
23
|
-
}
|
|
24
4
|
export type DispatchResultCode = 'ok' | 'intercepted' | 'scene_not_found' | 'already_presenting' | 'covered' | 'not_ready' | 'superseded' | 'invalid_action' | 'host_unavailable';
|
|
25
5
|
export interface DispatchResult {
|
|
26
6
|
ok: boolean;
|
|
@@ -28,8 +8,6 @@ export interface DispatchResult {
|
|
|
28
8
|
message?: string;
|
|
29
9
|
sceneId?: string;
|
|
30
10
|
}
|
|
31
|
-
export type CloseTarget = 'self' | 'presented';
|
|
32
|
-
export type CoveredPolicy = 'fail' | 'defer';
|
|
33
11
|
export type SceneExitRestoreReason = DispatchResultCode | 'exit_error';
|
|
34
12
|
export interface SceneExitHandler {
|
|
35
13
|
onExit: () => void | Promise<void>;
|
|
@@ -38,16 +16,18 @@ export interface SceneExitHandler {
|
|
|
38
16
|
exitTimeoutMs?: number;
|
|
39
17
|
}
|
|
40
18
|
export interface CloseSelfOptions<T extends ResultMap = ResultMap> {
|
|
19
|
+
bypassBeforeRemove?: boolean;
|
|
41
20
|
result?: {
|
|
42
21
|
code: number;
|
|
43
22
|
data?: T | null;
|
|
44
23
|
};
|
|
45
|
-
onCovered?: CoveredPolicy;
|
|
46
24
|
}
|
|
47
25
|
export type LeaveAction = 'back' | 'pop' | 'popTo' | 'popToRoot' | 'dismiss' | 'hideModal' | 'close' | 'redirectTo';
|
|
26
|
+
export type BeforeRemoveSource = 'back' | 'self' | 'external';
|
|
48
27
|
export interface BeforeRemoveEvent {
|
|
49
28
|
sceneId: string;
|
|
50
29
|
action: LeaveAction;
|
|
30
|
+
source: BeforeRemoveSource;
|
|
51
31
|
proceed: () => Promise<DispatchResult>;
|
|
52
32
|
}
|
|
53
33
|
export interface BeforeRemoveOptions {
|
|
@@ -90,11 +70,7 @@ export type ScreenRoute<Props extends Record<string, any> = Record<never, never>
|
|
|
90
70
|
result: Result;
|
|
91
71
|
};
|
|
92
72
|
export type HasTypedRoutes = keyof NavigationParamList extends never ? false : true;
|
|
93
|
-
export type
|
|
94
|
-
allowUnregisteredRoutes: true;
|
|
95
|
-
} ? true : false;
|
|
96
|
-
export type RegisteredRouteName = Extract<keyof NavigationParamList, string>;
|
|
97
|
-
export type RouteName = HasTypedRoutes extends true ? AllowUnregisteredRoutes extends true ? RegisteredRouteName | (string & {}) : RegisteredRouteName : string;
|
|
73
|
+
export type RouteName = HasTypedRoutes extends true ? Extract<keyof NavigationParamList, string> : string;
|
|
98
74
|
type RawRouteEntry<Name extends string> = Name extends keyof NavigationParamList ? NavigationParamList[Name] : ScreenRoute<Record<string, any>, unknown>;
|
|
99
75
|
export type RoutePropsOf<Name extends string> = RawRouteEntry<Name> extends {
|
|
100
76
|
props: infer P;
|
|
@@ -115,7 +91,7 @@ type RequiredKeysOf<T> = {
|
|
|
115
91
|
[K in keyof T]-?: {} extends Pick<T, K> ? never : K;
|
|
116
92
|
}[keyof T];
|
|
117
93
|
export type IsPropsRequired<P> = [RequiredKeysOf<P>] extends [never] ? false : true;
|
|
118
|
-
export type ScreenPropsArgs<Name extends string> = HasTypedRoutes extends true ?
|
|
94
|
+
export type ScreenPropsArgs<Name extends string> = HasTypedRoutes extends true ? IsPropsRequired<RoutePropsOf<Name>> extends true ? [props: RoutePropsOf<Name>, options?: NavigationItem] : [props?: RoutePropsOf<Name>, options?: NavigationItem] : [props?: Record<string, any>, options?: NavigationItem];
|
|
119
95
|
export type Screen<Name extends RouteName = RouteName> = HasTypedRoutes extends true ? Name extends RouteName ? {
|
|
120
96
|
screen: {
|
|
121
97
|
moduleName: Name;
|
|
@@ -141,7 +117,6 @@ export interface Tabs {
|
|
|
141
117
|
children: Array<Layout>;
|
|
142
118
|
options?: {
|
|
143
119
|
selectedIndex?: number;
|
|
144
|
-
renderer?: string;
|
|
145
120
|
};
|
|
146
121
|
};
|
|
147
122
|
}
|
|
@@ -160,7 +135,6 @@ export type CustomLayout = HasCustomLayouts extends true ? {
|
|
|
160
135
|
[K in Extract<keyof CustomLayoutMap, string>]: Record<K, CustomLayoutMap[K]>;
|
|
161
136
|
}[Extract<keyof CustomLayoutMap, string>] : never;
|
|
162
137
|
export type BuiltInLayout = TypedScreen | Stack | Tabs | Drawer;
|
|
163
|
-
export type BuildInLayout = BuiltInLayout;
|
|
164
138
|
export type Layout = BuiltInLayout | CustomLayout;
|
|
165
139
|
export type RouteMode = 'modal' | 'present' | 'push';
|
|
166
140
|
export type LayoutMode = 'modal' | 'present' | 'normal';
|
|
@@ -171,6 +145,11 @@ export interface Route {
|
|
|
171
145
|
presentingId: string | null;
|
|
172
146
|
requestCode: number;
|
|
173
147
|
}
|
|
148
|
+
export interface NavigationSnapshot {
|
|
149
|
+
rootGeneration: number;
|
|
150
|
+
currentRoute: Route | null;
|
|
151
|
+
layers: RouteGraph[];
|
|
152
|
+
}
|
|
174
153
|
export interface RouteGraph {
|
|
175
154
|
layout: string;
|
|
176
155
|
sceneId: string;
|
|
@@ -179,7 +158,7 @@ export interface RouteGraph {
|
|
|
179
158
|
}
|
|
180
159
|
export interface RouteConfig {
|
|
181
160
|
path?: string;
|
|
182
|
-
dependency?:
|
|
161
|
+
dependency?: RouteName;
|
|
183
162
|
mode?: RouteMode;
|
|
184
163
|
options?: NavigationItem;
|
|
185
164
|
lazy?: boolean;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DispatchResultWire } from '../NativeNavigation';
|
|
2
2
|
import { NavigationItem } from '../Options';
|
|
3
|
-
import type {
|
|
3
|
+
import type { DispatchResult, Layout } from '../Route';
|
|
4
4
|
export declare function normalizeDispatchResult(wire: DispatchResultWire | null | undefined): DispatchResult;
|
|
5
5
|
export interface DispatchParams {
|
|
6
6
|
animated?: boolean;
|
|
@@ -8,17 +8,9 @@ export interface DispatchParams {
|
|
|
8
8
|
moduleName?: string;
|
|
9
9
|
from?: string | number;
|
|
10
10
|
to?: string | number;
|
|
11
|
-
layout?:
|
|
11
|
+
layout?: Layout;
|
|
12
12
|
popToRoot?: boolean;
|
|
13
|
-
tabKey?: string;
|
|
14
13
|
requestCode?: number;
|
|
15
|
-
target?: CloseTarget;
|
|
16
|
-
onCovered?: CoveredPolicy;
|
|
17
|
-
result?: {
|
|
18
|
-
code: number;
|
|
19
|
-
data?: any;
|
|
20
|
-
};
|
|
21
|
-
bypassBeforeRemove?: boolean;
|
|
22
14
|
props?: object;
|
|
23
15
|
options?: NavigationItem;
|
|
24
16
|
[index: string]: any;
|
|
@@ -30,18 +22,12 @@ export interface InterceptParams {
|
|
|
30
22
|
props?: object;
|
|
31
23
|
}
|
|
32
24
|
export type NavigationInterceptor = (action: string, params: InterceptParams) => boolean | Promise<boolean>;
|
|
33
|
-
export type DispatchMiddleware = (sceneId: string, action: string, params: DispatchParams, next: (sceneId: string, action: string, params: DispatchParams) => Promise<DispatchResult>) => Promise<DispatchResult>;
|
|
34
25
|
export default class DispatchCommandHandler {
|
|
35
26
|
private interceptors;
|
|
36
|
-
private systemMiddlewares;
|
|
37
|
-
addMiddleware(middleware: DispatchMiddleware): void;
|
|
38
|
-
removeMiddleware(middleware: DispatchMiddleware): void;
|
|
39
|
-
interceptorMiddleware: DispatchMiddleware;
|
|
40
|
-
dispatchRaw(sceneId: string, action: string, params: DispatchParams): Promise<DispatchResult>;
|
|
41
27
|
dispatch(sceneId: string, action: string, params: DispatchParams): Promise<DispatchResult>;
|
|
28
|
+
private dispatchApproved;
|
|
42
29
|
private intercept;
|
|
43
30
|
addInterceptor(interceptor: NavigationInterceptor): void;
|
|
44
31
|
removeInterceptor(interceptor: NavigationInterceptor): void;
|
|
45
|
-
clearInterceptors(): void;
|
|
46
32
|
}
|
|
47
33
|
export declare const dispatchHandler: DispatchCommandHandler;
|