hybrid-navigation 5.2.0 → 5.4.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 +72 -136
- 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 +3 -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 +3 -3
- 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 +3 -1
- package/ios/ViewController/HBDReactViewController.mm +42 -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 +3 -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/dist/Navigation.js
CHANGED
|
@@ -1,51 +1,35 @@
|
|
|
1
1
|
import { AppRegistry } from 'react-native';
|
|
2
2
|
import { layoutHandler } from './handler/LayoutCommandHandler';
|
|
3
|
-
import {
|
|
4
|
-
import { leaveGuardHandler } from './handler/LeaveGuardHandler';
|
|
5
|
-
import { presentationCoordinator } from './handler/PresentationCoordinator';
|
|
6
|
-
import { tabEventHandler } from './handler/TabEventHandler';
|
|
7
|
-
import { executeReveal } from './reveal';
|
|
3
|
+
import { dispatchHandler } from './handler/DispatchCommandHandler';
|
|
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,30 +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
|
-
|
|
205
|
-
? params
|
|
206
|
-
: { ...params, [BEFORE_REMOVE_SOURCE_PROP]: 'external' };
|
|
207
|
-
return dispatchHandler.dispatch(sceneId, action, nextParams);
|
|
93
|
+
return dispatchHandler.dispatch(sceneId, action, { ...params, [BEFORE_REMOVE_SOURCE_PROP]: 'external' });
|
|
208
94
|
}
|
|
209
95
|
addInterceptor(interceptor) {
|
|
210
96
|
dispatchHandler.addInterceptor(interceptor);
|
|
@@ -212,34 +98,6 @@ class NavigationImpl {
|
|
|
212
98
|
remove: () => dispatchHandler.removeInterceptor(interceptor),
|
|
213
99
|
};
|
|
214
100
|
}
|
|
215
|
-
registerSceneExitHandler(sceneId, handler) {
|
|
216
|
-
const remove = presentationCoordinator.registerExitHandler(sceneId, handler);
|
|
217
|
-
return { remove };
|
|
218
|
-
}
|
|
219
|
-
addSceneCoverageListener(sceneId, listener) {
|
|
220
|
-
const remove = presentationCoordinator.addCoverageListener(sceneId, listener);
|
|
221
|
-
return { remove };
|
|
222
|
-
}
|
|
223
|
-
isSceneCovered(sceneId) {
|
|
224
|
-
return presentationCoordinator.isSceneVisuallyCovered(sceneId);
|
|
225
|
-
}
|
|
226
|
-
addBeforeRemoveListener(sceneId, listener, options) {
|
|
227
|
-
const remove = leaveGuardHandler.addListener(sceneId, listener, options);
|
|
228
|
-
return { remove };
|
|
229
|
-
}
|
|
230
|
-
closeScene(sceneId, options) {
|
|
231
|
-
return this.dispatch(sceneId, 'close', {
|
|
232
|
-
target: 'self',
|
|
233
|
-
onCovered: options?.onCovered,
|
|
234
|
-
...(options?.bypassBeforeRemove ? { bypassBeforeRemove: true } : {}),
|
|
235
|
-
...(options?.result !== undefined ? { result: options.result } : {}),
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
reveal(target, options) {
|
|
239
|
-
const task = this.revealQueue.then(() => executeReveal(this, target, options), () => executeReveal(this, target, options));
|
|
240
|
-
this.revealQueue = task.then(() => undefined, () => undefined);
|
|
241
|
-
return task;
|
|
242
|
-
}
|
|
243
101
|
setResult = (sceneId, resultCode, data = null) => {
|
|
244
102
|
resultHandler.setResult(sceneId, resultCode, data);
|
|
245
103
|
};
|
|
@@ -265,37 +123,37 @@ class NavigationImpl {
|
|
|
265
123
|
currentRoute() {
|
|
266
124
|
return NativeNavigation.currentRoute();
|
|
267
125
|
}
|
|
268
|
-
routeGraph() {
|
|
269
|
-
return NativeNavigation.routeGraph();
|
|
270
|
-
}
|
|
271
126
|
navigationSnapshot() {
|
|
272
127
|
return NativeNavigation.navigationSnapshot();
|
|
273
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
|
+
}
|
|
274
145
|
setDefaultOptions(options) {
|
|
275
146
|
NativeNavigation.setDefaultOptions(options);
|
|
276
147
|
}
|
|
277
148
|
updateOptions(sceneId, options) {
|
|
278
149
|
NativeNavigation.updateOptions(sceneId, options);
|
|
279
150
|
}
|
|
280
|
-
updateTabBar(
|
|
281
|
-
|
|
282
|
-
NativeNavigation.updateTabBar(sceneIdOrOptions, options ?? {});
|
|
283
|
-
}
|
|
284
|
-
else {
|
|
285
|
-
NativeNavigation.updateTabBar('', sceneIdOrOptions);
|
|
286
|
-
}
|
|
151
|
+
updateTabBar(sceneId, options) {
|
|
152
|
+
NativeNavigation.updateTabBar(sceneId, options);
|
|
287
153
|
}
|
|
288
|
-
setTabItem(
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
if (items.length > 0) {
|
|
292
|
-
NativeNavigation.setTabItem(sceneIdOrItem, items);
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
else {
|
|
296
|
-
const items = Array.isArray(sceneIdOrItem) ? sceneIdOrItem : [sceneIdOrItem];
|
|
297
|
-
NativeNavigation.setTabItem('', items);
|
|
298
|
-
}
|
|
154
|
+
setTabItem(sceneId, item) {
|
|
155
|
+
const items = Array.isArray(item) ? item : [item];
|
|
156
|
+
NativeNavigation.setTabItem(sceneId, items);
|
|
299
157
|
}
|
|
300
158
|
setMenuInteractive(sceneId, enabled) {
|
|
301
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,15 +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?.bypassBeforeRemove ? { bypassBeforeRemove: true } : {}),
|
|
136
|
-
...(options?.result !== undefined ? { result: options.result } : {}),
|
|
137
|
-
});
|
|
138
|
-
};
|
|
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
|
+
});
|
|
139
121
|
showModal = async (moduleName, ...args) => {
|
|
140
122
|
const [props = {}, options = {}] = args;
|
|
141
123
|
return this.dispatchForResult('showModal', {
|
|
@@ -156,16 +138,10 @@ export class Navigator {
|
|
|
156
138
|
setResult = (resultCode, data = null) => resultHandler.setResult(this.sceneId, resultCode, data);
|
|
157
139
|
switchTab = async (target, popToRoot = false) => {
|
|
158
140
|
const from = await NativeNavigation.currentTab(this.sceneId);
|
|
159
|
-
if (typeof target === 'string') {
|
|
160
|
-
return dispatchHandler.dispatch(this.sceneId, 'switchTab', {
|
|
161
|
-
from,
|
|
162
|
-
tabKey: target,
|
|
163
|
-
popToRoot,
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
141
|
return dispatchHandler.dispatch(this.sceneId, 'switchTab', {
|
|
167
142
|
from,
|
|
168
143
|
to: target,
|
|
144
|
+
...(typeof target === 'string' && { tabKey: target }),
|
|
169
145
|
popToRoot,
|
|
170
146
|
});
|
|
171
147
|
};
|
package/dist/Options.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ export interface NavigationOption {
|
|
|
24
24
|
}
|
|
25
25
|
export interface NavigationItem extends NavigationOption {
|
|
26
26
|
animatedTransition?: boolean;
|
|
27
|
+
prewarmPush?: boolean;
|
|
27
28
|
tabItem?: TabItem;
|
|
28
29
|
}
|
|
29
30
|
export interface TabItem {
|
|
@@ -38,7 +39,6 @@ export interface ShadowImage {
|
|
|
38
39
|
}
|
|
39
40
|
export interface DefaultOptions {
|
|
40
41
|
screenBackgroundColor?: Color;
|
|
41
|
-
modalBackgroundColor?: Color;
|
|
42
42
|
injectInitialMetrics?: boolean;
|
|
43
43
|
prewarmPush?: boolean;
|
|
44
44
|
statusBarStyle?: BarStyle;
|
|
@@ -52,7 +52,7 @@ export interface DefaultOptions {
|
|
|
52
52
|
tabBarBadgeColor?: Color;
|
|
53
53
|
}
|
|
54
54
|
export type TabBarStyle = Pick<DefaultOptions, 'tabBarBackgroundColor' | 'tabBarShadowImage' | 'tabBarItemSelectedColor' | 'tabBarItemNormalColor'>;
|
|
55
|
-
|
|
55
|
+
interface TabItemInfoBase {
|
|
56
56
|
title?: string;
|
|
57
57
|
badge?: {
|
|
58
58
|
text?: string;
|
|
@@ -71,3 +71,4 @@ export type TabItemInfo = (TabItemInfoBase & {
|
|
|
71
71
|
key: string;
|
|
72
72
|
index?: number;
|
|
73
73
|
});
|
|
74
|
+
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,9 +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
|
-
export type SceneCoverageListener = (covered: boolean) => void;
|
|
34
11
|
export type SceneExitRestoreReason = DispatchResultCode | 'exit_error';
|
|
35
12
|
export interface SceneExitHandler {
|
|
36
13
|
onExit: () => void | Promise<void>;
|
|
@@ -39,12 +16,11 @@ export interface SceneExitHandler {
|
|
|
39
16
|
exitTimeoutMs?: number;
|
|
40
17
|
}
|
|
41
18
|
export interface CloseSelfOptions<T extends ResultMap = ResultMap> {
|
|
19
|
+
bypassBeforeRemove?: boolean;
|
|
42
20
|
result?: {
|
|
43
21
|
code: number;
|
|
44
22
|
data?: T | null;
|
|
45
23
|
};
|
|
46
|
-
onCovered?: CoveredPolicy;
|
|
47
|
-
bypassBeforeRemove?: boolean;
|
|
48
24
|
}
|
|
49
25
|
export type LeaveAction = 'back' | 'pop' | 'popTo' | 'popToRoot' | 'dismiss' | 'hideModal' | 'close' | 'redirectTo';
|
|
50
26
|
export type BeforeRemoveSource = 'back' | 'self' | 'external';
|
|
@@ -94,11 +70,7 @@ export type ScreenRoute<Props extends Record<string, any> = Record<never, never>
|
|
|
94
70
|
result: Result;
|
|
95
71
|
};
|
|
96
72
|
export type HasTypedRoutes = keyof NavigationParamList extends never ? false : true;
|
|
97
|
-
export type
|
|
98
|
-
allowUnregisteredRoutes: true;
|
|
99
|
-
} ? true : false;
|
|
100
|
-
export type RegisteredRouteName = Extract<keyof NavigationParamList, string>;
|
|
101
|
-
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;
|
|
102
74
|
type RawRouteEntry<Name extends string> = Name extends keyof NavigationParamList ? NavigationParamList[Name] : ScreenRoute<Record<string, any>, unknown>;
|
|
103
75
|
export type RoutePropsOf<Name extends string> = RawRouteEntry<Name> extends {
|
|
104
76
|
props: infer P;
|
|
@@ -119,7 +91,7 @@ type RequiredKeysOf<T> = {
|
|
|
119
91
|
[K in keyof T]-?: {} extends Pick<T, K> ? never : K;
|
|
120
92
|
}[keyof T];
|
|
121
93
|
export type IsPropsRequired<P> = [RequiredKeysOf<P>] extends [never] ? false : true;
|
|
122
|
-
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];
|
|
123
95
|
export type Screen<Name extends RouteName = RouteName> = HasTypedRoutes extends true ? Name extends RouteName ? {
|
|
124
96
|
screen: {
|
|
125
97
|
moduleName: Name;
|
|
@@ -145,7 +117,6 @@ export interface Tabs {
|
|
|
145
117
|
children: Array<Layout>;
|
|
146
118
|
options?: {
|
|
147
119
|
selectedIndex?: number;
|
|
148
|
-
renderer?: string;
|
|
149
120
|
};
|
|
150
121
|
};
|
|
151
122
|
}
|
|
@@ -164,7 +135,6 @@ export type CustomLayout = HasCustomLayouts extends true ? {
|
|
|
164
135
|
[K in Extract<keyof CustomLayoutMap, string>]: Record<K, CustomLayoutMap[K]>;
|
|
165
136
|
}[Extract<keyof CustomLayoutMap, string>] : never;
|
|
166
137
|
export type BuiltInLayout = TypedScreen | Stack | Tabs | Drawer;
|
|
167
|
-
export type BuildInLayout = BuiltInLayout;
|
|
168
138
|
export type Layout = BuiltInLayout | CustomLayout;
|
|
169
139
|
export type RouteMode = 'modal' | 'present' | 'push';
|
|
170
140
|
export type LayoutMode = 'modal' | 'present' | 'normal';
|
|
@@ -175,6 +145,11 @@ export interface Route {
|
|
|
175
145
|
presentingId: string | null;
|
|
176
146
|
requestCode: number;
|
|
177
147
|
}
|
|
148
|
+
export interface NavigationSnapshot {
|
|
149
|
+
rootGeneration: number;
|
|
150
|
+
currentRoute: Route | null;
|
|
151
|
+
layers: RouteGraph[];
|
|
152
|
+
}
|
|
178
153
|
export interface RouteGraph {
|
|
179
154
|
layout: string;
|
|
180
155
|
sceneId: string;
|
|
@@ -183,7 +158,7 @@ export interface RouteGraph {
|
|
|
183
158
|
}
|
|
184
159
|
export interface RouteConfig {
|
|
185
160
|
path?: string;
|
|
186
|
-
dependency?:
|
|
161
|
+
dependency?: RouteName;
|
|
187
162
|
mode?: RouteMode;
|
|
188
163
|
options?: NavigationItem;
|
|
189
164
|
lazy?: boolean;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { DispatchResultWire } from '../NativeNavigation';
|
|
2
2
|
import { NavigationItem } from '../Options';
|
|
3
|
-
import type {
|
|
4
|
-
export declare const BEFORE_REMOVE_SOURCE_PROP = "__hbdBeforeRemoveSource";
|
|
3
|
+
import type { DispatchResult, Layout } from '../Route';
|
|
5
4
|
export declare function normalizeDispatchResult(wire: DispatchResultWire | null | undefined): DispatchResult;
|
|
6
5
|
export interface DispatchParams {
|
|
7
6
|
animated?: boolean;
|
|
@@ -9,17 +8,9 @@ export interface DispatchParams {
|
|
|
9
8
|
moduleName?: string;
|
|
10
9
|
from?: string | number;
|
|
11
10
|
to?: string | number;
|
|
12
|
-
layout?:
|
|
11
|
+
layout?: Layout;
|
|
13
12
|
popToRoot?: boolean;
|
|
14
|
-
tabKey?: string;
|
|
15
13
|
requestCode?: number;
|
|
16
|
-
target?: CloseTarget;
|
|
17
|
-
onCovered?: CoveredPolicy;
|
|
18
|
-
result?: {
|
|
19
|
-
code: number;
|
|
20
|
-
data?: any;
|
|
21
|
-
};
|
|
22
|
-
bypassBeforeRemove?: boolean;
|
|
23
14
|
props?: object;
|
|
24
15
|
options?: NavigationItem;
|
|
25
16
|
[index: string]: any;
|
|
@@ -31,18 +22,12 @@ export interface InterceptParams {
|
|
|
31
22
|
props?: object;
|
|
32
23
|
}
|
|
33
24
|
export type NavigationInterceptor = (action: string, params: InterceptParams) => boolean | Promise<boolean>;
|
|
34
|
-
export type DispatchMiddleware = (sceneId: string, action: string, params: DispatchParams, next: (sceneId: string, action: string, params: DispatchParams) => Promise<DispatchResult>) => Promise<DispatchResult>;
|
|
35
25
|
export default class DispatchCommandHandler {
|
|
36
26
|
private interceptors;
|
|
37
|
-
private systemMiddlewares;
|
|
38
|
-
addMiddleware(middleware: DispatchMiddleware): void;
|
|
39
|
-
removeMiddleware(middleware: DispatchMiddleware): void;
|
|
40
|
-
interceptorMiddleware: DispatchMiddleware;
|
|
41
|
-
dispatchRaw(sceneId: string, action: string, params: DispatchParams): Promise<DispatchResult>;
|
|
42
27
|
dispatch(sceneId: string, action: string, params: DispatchParams): Promise<DispatchResult>;
|
|
28
|
+
private dispatchApproved;
|
|
43
29
|
private intercept;
|
|
44
30
|
addInterceptor(interceptor: NavigationInterceptor): void;
|
|
45
31
|
removeInterceptor(interceptor: NavigationInterceptor): void;
|
|
46
|
-
clearInterceptors(): void;
|
|
47
32
|
}
|
|
48
33
|
export declare const dispatchHandler: DispatchCommandHandler;
|