hybrid-navigation 5.0.0 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/src/main/java/com/navigation/androidx/AwesomeActivity.java +2 -4
- package/android/src/main/java/com/navigation/androidx/AwesomeFragment.java +48 -2
- package/android/src/main/java/com/navigation/androidx/DefaultTabBarProvider.java +2 -2
- package/android/src/main/java/com/navigation/androidx/FragmentHelper.java +7 -0
- package/android/src/main/java/com/navigation/androidx/PresentationDelegate.java +2 -4
- package/android/src/main/java/com/navigation/androidx/StackFragment.java +3 -0
- package/android/src/main/java/com/navigation/androidx/TabBarFragment.java +50 -0
- package/android/src/main/java/com/navigation/androidx/TabBarItem.java +4 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/DispatchResult.java +16 -4
- package/android/src/main/java/com/reactnative/hybridnavigation/GlobalStyle.java +19 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/HBDRootView.java +17 -2
- package/android/src/main/java/com/reactnative/hybridnavigation/HybridFragment.java +66 -7
- package/android/src/main/java/com/reactnative/hybridnavigation/NativeNavigation.java +116 -18
- package/android/src/main/java/com/reactnative/hybridnavigation/NavigationCommandQueue.java +8 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactFragment.java +376 -8
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactManager.java +72 -2
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarFragment.java +26 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/ScreenNavigator.java +134 -12
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/StackNavigator.java +35 -3
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/TabNavigator.java +29 -4
- package/dist/NativeEvent.d.ts +15 -0
- package/dist/NativeNavigation.d.ts +8 -0
- package/dist/Navigation.d.ts +14 -1
- package/dist/Navigation.js +153 -12
- package/dist/NavigationComponentWrap.d.ts +3 -2
- package/dist/Navigator.d.ts +3 -2
- package/dist/Navigator.js +28 -9
- package/dist/Options.d.ts +12 -2
- package/dist/Route.d.ts +70 -5
- package/dist/defineRoutes.d.ts +19 -0
- package/dist/defineRoutes.js +6 -0
- package/dist/handler/DispatchCommandHandler.d.ts +16 -1
- package/dist/handler/DispatchCommandHandler.js +63 -5
- package/dist/handler/LayoutCommandHandler.d.ts +1 -0
- package/dist/handler/LayoutCommandHandler.js +3 -0
- package/dist/handler/LeaveGuardHandler.d.ts +17 -0
- package/dist/handler/LeaveGuardHandler.js +350 -0
- package/dist/handler/LifecycleEventHandler.d.ts +7 -3
- package/dist/handler/LifecycleEventHandler.js +36 -3
- package/dist/handler/PresentationCoordinator.d.ts +24 -0
- package/dist/handler/PresentationCoordinator.js +449 -0
- package/dist/handler/ResultEventHandler.d.ts +7 -0
- package/dist/handler/ResultEventHandler.js +13 -5
- package/dist/handler/TabEventHandler.d.ts +8 -0
- package/dist/handler/TabEventHandler.js +25 -0
- package/dist/hooks.d.ts +3 -1
- package/dist/hooks.js +20 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +3 -0
- package/dist/reveal.d.ts +46 -0
- package/dist/reveal.js +431 -0
- package/dist/routeGraph.d.ts +12 -0
- package/dist/routeGraph.js +68 -0
- package/dist/router/index.js +5 -41
- package/dist/router/tabs.d.ts +1 -0
- package/dist/store.d.ts +2 -0
- package/dist/store.js +4 -0
- package/dist/testing.d.ts +79 -0
- package/dist/testing.js +251 -0
- package/ios/HBDGlobalStyle.h +3 -0
- package/ios/HBDGlobalStyle.mm +13 -0
- package/ios/HybridNavigation.h +1 -0
- package/ios/Navigator/HBDScreenNavigator.mm +177 -11
- package/ios/Navigator/HBDStackNavigator.mm +50 -7
- package/ios/Navigator/HBDTabNavigator.mm +33 -5
- package/ios/React/HBDNativeNavigation.mm +73 -12
- package/ios/React/HBDNavigator.h +8 -0
- package/ios/React/HBDOrientationCoordinator.h +2 -0
- package/ios/React/HBDOrientationCoordinator.mm +27 -0
- package/ios/React/HBDReactBridgeManager.h +10 -0
- package/ios/React/HBDReactBridgeManager.mm +48 -2
- package/ios/ViewController/HBDNavigationController.mm +14 -0
- package/ios/ViewController/HBDReactViewController.h +6 -0
- package/ios/ViewController/HBDReactViewController.mm +177 -1
- package/ios/ViewController/HBDTabBarController.h +11 -0
- package/ios/ViewController/HBDTabBarController.mm +170 -3
- package/ios/ViewController/HBDTabBarRenderer.h +28 -0
- package/ios/ViewController/HBDViewController.h +1 -0
- package/ios/ViewController/HBDViewController.mm +57 -9
- package/ios/ViewController/UIViewController+HBD.h +1 -0
- package/ios/ViewController/UIViewController+HBD.mm +13 -4
- package/package.json +3 -1
- package/src/NativeEvent.ts +17 -0
- package/src/NativeNavigation.ts +9 -0
- package/src/Navigation.ts +228 -12
- package/src/NavigationComponentWrap.tsx +11 -2
- package/src/Navigator.ts +38 -9
- package/src/Options.ts +9 -2
- package/src/Route.ts +102 -6
- package/src/defineRoutes.ts +46 -0
- package/src/handler/DispatchCommandHandler.ts +110 -11
- package/src/handler/LayoutCommandHandler.ts +4 -0
- package/src/handler/LeaveGuardHandler.ts +436 -0
- package/src/handler/LifecycleEventHandler.ts +85 -38
- package/src/handler/PresentationCoordinator.ts +560 -0
- package/src/handler/ResultEventHandler.ts +23 -9
- package/src/handler/TabEventHandler.ts +31 -0
- package/src/hooks.ts +37 -1
- package/src/index.ts +11 -0
- package/src/reveal.ts +565 -0
- package/src/routeGraph.ts +87 -0
- package/src/router/index.ts +5 -40
- package/src/router/tabs.ts +1 -0
- package/src/store.ts +5 -0
- package/src/testing.ts +395 -0
- package/testing.d.ts +1 -0
- package/testing.js +3 -0
package/dist/Navigation.js
CHANGED
|
@@ -1,29 +1,51 @@
|
|
|
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';
|
|
4
8
|
import { RESULT_BLOCK, RESULT_CANCEL, RESULT_OK, resultHandler, } from './handler/ResultEventHandler';
|
|
5
9
|
import { lifecycleHandler, } from './handler/LifecycleEventHandler';
|
|
6
10
|
import NativeNavigation from './NativeNavigation';
|
|
7
11
|
import store from './store';
|
|
8
12
|
import { withNavigation } from './NavigationComponentWrap';
|
|
9
|
-
import { bumpRouteConfigVersion, clearRouteConfigs, setRouteConfig, } from './routeConfigRegistry';
|
|
13
|
+
import { bumpRouteConfigVersion, clearRouteConfigs, getRouteConfigs, setRouteConfig, } from './routeConfigRegistry';
|
|
10
14
|
export { RESULT_CANCEL, RESULT_OK, RESULT_BLOCK };
|
|
11
15
|
class NavigationImpl {
|
|
12
16
|
constructor() {
|
|
17
|
+
leaveGuardHandler.setDispatcher((sceneId, action, params) => dispatchHandler.dispatch(sceneId, action, params));
|
|
18
|
+
dispatchHandler.addMiddleware(leaveGuardHandler.middleware);
|
|
19
|
+
dispatchHandler.addMiddleware(dispatchHandler.interceptorMiddleware);
|
|
20
|
+
dispatchHandler.addMiddleware(presentationCoordinator.middleware);
|
|
13
21
|
layoutHandler.handleRootLayoutChange(() => {
|
|
22
|
+
lifecycleHandler.onRootReset();
|
|
23
|
+
leaveGuardHandler.onRootReset();
|
|
24
|
+
presentationCoordinator.onRootReset();
|
|
14
25
|
resultHandler.invalidateAll('root_reset');
|
|
15
26
|
});
|
|
16
27
|
lifecycleHandler.handleSceneLifecycle(sceneId => {
|
|
28
|
+
leaveGuardHandler.onSceneDestroyed(sceneId);
|
|
29
|
+
presentationCoordinator.onSceneDestroyed(sceneId);
|
|
17
30
|
resultHandler.invalidateResultEventListener(sceneId, 'unmounted');
|
|
18
31
|
store.removeNavigator(sceneId);
|
|
19
32
|
});
|
|
20
33
|
resultHandler.handleComponentResult();
|
|
34
|
+
leaveGuardHandler.handleNativeBeforeRemoveRequests();
|
|
35
|
+
tabEventHandler.handleTabPress();
|
|
21
36
|
}
|
|
22
37
|
hoc;
|
|
23
38
|
registerEnded = false;
|
|
39
|
+
registeredNames = new Set();
|
|
40
|
+
registeredPaths = new Map();
|
|
41
|
+
routeLoaders = new Map();
|
|
42
|
+
revealQueue = Promise.resolve();
|
|
24
43
|
startRegisterComponent(hoc) {
|
|
25
44
|
this.hoc = hoc;
|
|
26
45
|
this.registerEnded = false;
|
|
46
|
+
this.registeredNames.clear();
|
|
47
|
+
this.registeredPaths.clear();
|
|
48
|
+
this.routeLoaders.clear();
|
|
27
49
|
clearRouteConfigs();
|
|
28
50
|
NativeNavigation.startRegisterReactComponent();
|
|
29
51
|
}
|
|
@@ -33,18 +55,63 @@ class NavigationImpl {
|
|
|
33
55
|
return;
|
|
34
56
|
}
|
|
35
57
|
this.registerEnded = true;
|
|
58
|
+
if (__DEV__) {
|
|
59
|
+
this.validateRouteDependencies();
|
|
60
|
+
}
|
|
36
61
|
bumpRouteConfigVersion();
|
|
37
62
|
NativeNavigation.endRegisterReactComponent();
|
|
38
63
|
}
|
|
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
|
+
}
|
|
39
92
|
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);
|
|
40
106
|
if (routeConfig && (routeConfig.path || routeConfig.dependency || routeConfig.mode)) {
|
|
41
107
|
setRouteConfig(appKey, routeConfig);
|
|
42
108
|
}
|
|
43
109
|
const hoc = this.hoc;
|
|
44
|
-
|
|
45
|
-
|
|
110
|
+
const isLazy = routeConfig?.lazy === true;
|
|
111
|
+
if (isLazy) {
|
|
112
|
+
NativeNavigation.registerReactComponent(appKey, routeConfig?.options ?? {});
|
|
46
113
|
let CachedRootComponent;
|
|
47
|
-
|
|
114
|
+
const loader = () => {
|
|
48
115
|
if (!CachedRootComponent) {
|
|
49
116
|
let WrappedComponent = getComponentFunc();
|
|
50
117
|
if (__DEV__ && WrappedComponent?.navigationItem) {
|
|
@@ -56,18 +123,49 @@ class NavigationImpl {
|
|
|
56
123
|
CachedRootComponent = withNavigation(appKey)(WrappedComponent);
|
|
57
124
|
}
|
|
58
125
|
return CachedRootComponent;
|
|
59
|
-
}
|
|
126
|
+
};
|
|
127
|
+
this.routeLoaders.set(appKey, loader);
|
|
128
|
+
AppRegistry.registerComponent(appKey, loader);
|
|
60
129
|
return;
|
|
61
130
|
}
|
|
62
|
-
|
|
131
|
+
const RawComponent = getComponentFunc();
|
|
132
|
+
let WrappedComponent = RawComponent;
|
|
63
133
|
if (hoc) {
|
|
64
134
|
WrappedComponent = hoc(WrappedComponent);
|
|
65
135
|
}
|
|
66
|
-
const options =
|
|
136
|
+
const options = routeConfig?.options ??
|
|
137
|
+
RawComponent?.navigationItem ??
|
|
138
|
+
WrappedComponent?.navigationItem ??
|
|
139
|
+
{};
|
|
67
140
|
NativeNavigation.registerReactComponent(appKey, options);
|
|
68
141
|
const RootComponent = withNavigation(appKey)(WrappedComponent);
|
|
69
142
|
AppRegistry.registerComponent(appKey, () => RootComponent);
|
|
70
143
|
}
|
|
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
|
+
}
|
|
71
169
|
addLifecycleListener(sceneId, listener) {
|
|
72
170
|
lifecycleHandler.addLifecycleListener(sceneId, listener);
|
|
73
171
|
return {
|
|
@@ -83,6 +181,9 @@ class NavigationImpl {
|
|
|
83
181
|
getSceneState(sceneId) {
|
|
84
182
|
return lifecycleHandler.getSceneState(sceneId);
|
|
85
183
|
}
|
|
184
|
+
getSceneInfo(sceneId) {
|
|
185
|
+
return lifecycleHandler.getSceneInfo(sceneId);
|
|
186
|
+
}
|
|
86
187
|
addGlobalVisibilityEventListener(listener) {
|
|
87
188
|
lifecycleHandler.addGlobalVisibilityEventListener(listener);
|
|
88
189
|
return {
|
|
@@ -95,6 +196,10 @@ class NavigationImpl {
|
|
|
95
196
|
remove: () => lifecycleHandler.removeVisibilityEventListener(sceneId, listener),
|
|
96
197
|
};
|
|
97
198
|
}
|
|
199
|
+
addTabPressListener(listener) {
|
|
200
|
+
const remove = tabEventHandler.addListener(listener);
|
|
201
|
+
return { remove };
|
|
202
|
+
}
|
|
98
203
|
dispatch(sceneId, action, params = {}) {
|
|
99
204
|
return dispatchHandler.dispatch(sceneId, action, params);
|
|
100
205
|
}
|
|
@@ -104,6 +209,26 @@ class NavigationImpl {
|
|
|
104
209
|
remove: () => dispatchHandler.removeInterceptor(interceptor),
|
|
105
210
|
};
|
|
106
211
|
}
|
|
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
|
+
}
|
|
107
232
|
setResult = (sceneId, resultCode, data = null) => {
|
|
108
233
|
resultHandler.setResult(sceneId, resultCode, data);
|
|
109
234
|
};
|
|
@@ -132,18 +257,34 @@ class NavigationImpl {
|
|
|
132
257
|
routeGraph() {
|
|
133
258
|
return NativeNavigation.routeGraph();
|
|
134
259
|
}
|
|
260
|
+
navigationSnapshot() {
|
|
261
|
+
return NativeNavigation.navigationSnapshot();
|
|
262
|
+
}
|
|
135
263
|
setDefaultOptions(options) {
|
|
136
264
|
NativeNavigation.setDefaultOptions(options);
|
|
137
265
|
}
|
|
138
266
|
updateOptions(sceneId, options) {
|
|
139
267
|
NativeNavigation.updateOptions(sceneId, options);
|
|
140
268
|
}
|
|
141
|
-
updateTabBar(
|
|
142
|
-
|
|
269
|
+
updateTabBar(sceneIdOrOptions, options) {
|
|
270
|
+
if (typeof sceneIdOrOptions === 'string') {
|
|
271
|
+
NativeNavigation.updateTabBar(sceneIdOrOptions, options ?? {});
|
|
272
|
+
}
|
|
273
|
+
else {
|
|
274
|
+
NativeNavigation.updateTabBar('', sceneIdOrOptions);
|
|
275
|
+
}
|
|
143
276
|
}
|
|
144
|
-
setTabItem(
|
|
145
|
-
|
|
146
|
-
|
|
277
|
+
setTabItem(sceneIdOrItem, item) {
|
|
278
|
+
if (typeof sceneIdOrItem === 'string') {
|
|
279
|
+
const items = Array.isArray(item) ? item : item ? [item] : [];
|
|
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
|
+
}
|
|
147
288
|
}
|
|
148
289
|
setMenuInteractive(sceneId, enabled) {
|
|
149
290
|
return this.dispatch(sceneId, 'setMenuInteractive', { enabled });
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { NavigationItem } from './Options';
|
|
3
|
-
import type { HasTypedRoutes, RouteName, RoutePropsOf } from './Route';
|
|
3
|
+
import type { HasTypedRoutes, InitialMetrics, RegisteredRouteName, RouteName, RoutePropsOf } from './Route';
|
|
4
4
|
import { Navigator } from './Navigator';
|
|
5
|
-
export type NavigationProps<Name extends RouteName = RouteName> = (HasTypedRoutes extends true ? RoutePropsOf<Name> : Record<string, any>) & {
|
|
5
|
+
export type NavigationProps<Name extends RouteName = RouteName> = (HasTypedRoutes extends true ? [Name] extends [RegisteredRouteName] ? RoutePropsOf<Name> : Record<string, any> : Record<string, any>) & {
|
|
6
6
|
navigator: Navigator<Name>;
|
|
7
7
|
sceneId: string;
|
|
8
|
+
initialMetrics?: InitialMetrics;
|
|
8
9
|
};
|
|
9
10
|
interface NativeProps {
|
|
10
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 { BuildInLayout, DispatchResult, Layout, NavigationResult, RouteName, RouteResultOf, SceneLifecycleState, ScreenPropsArgs, SetResultData, Visibility } from './Route';
|
|
2
|
+
import type { BuildInLayout, CloseSelfOptions, DispatchResult, Layout, NavigationResult, RouteName, RouteResultOf, SceneLifecycleState, ScreenPropsArgs, SetResultData, Visibility } 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;
|
|
@@ -20,11 +20,12 @@ export declare class Navigator<CurrentRoute extends RouteName = RouteName> {
|
|
|
20
20
|
present: <Name extends RouteName = RouteName, T = RouteResultOf<Name>>(moduleName: Name, ...args: ScreenPropsArgs<Name>) => Promise<NavigationResult<T>>;
|
|
21
21
|
presentLayout: <T = unknown>(layout: BuildInLayout | Layout) => Promise<NavigationResult<T>>;
|
|
22
22
|
dismiss: () => Promise<DispatchResult>;
|
|
23
|
+
closeSelf: (options?: CloseSelfOptions<SetResultData<CurrentRoute>>) => Promise<DispatchResult>;
|
|
23
24
|
showModal: <Name extends RouteName = RouteName, T = RouteResultOf<Name>>(moduleName: Name, ...args: ScreenPropsArgs<Name>) => Promise<NavigationResult<T>>;
|
|
24
25
|
showModalLayout: <T = unknown>(layout: BuildInLayout | Layout) => Promise<NavigationResult<T>>;
|
|
25
26
|
hideModal: () => Promise<DispatchResult>;
|
|
26
27
|
setResult: (resultCode: number, data?: SetResultData<CurrentRoute> | null) => void;
|
|
27
|
-
switchTab: (
|
|
28
|
+
switchTab: (target: number | string, popToRoot?: boolean) => Promise<DispatchResult>;
|
|
28
29
|
toggleMenu: () => Promise<DispatchResult>;
|
|
29
30
|
openMenu: () => Promise<DispatchResult>;
|
|
30
31
|
closeMenu: () => Promise<DispatchResult>;
|
package/dist/Navigator.js
CHANGED
|
@@ -51,10 +51,10 @@ export class Navigator {
|
|
|
51
51
|
}
|
|
52
52
|
dispatchForResult = async (action, params, warnOnFailure) => {
|
|
53
53
|
const requestCode = --tagGenerator;
|
|
54
|
-
const { promise, cancel } = resultHandler.prepareResult(this.sceneId, requestCode);
|
|
55
|
-
let
|
|
54
|
+
const { promise: resultPromise, cancel } = resultHandler.prepareResult(this.sceneId, requestCode);
|
|
55
|
+
let dispatchResult;
|
|
56
56
|
try {
|
|
57
|
-
|
|
57
|
+
dispatchResult = await dispatchHandler.dispatch(this.sceneId, action, {
|
|
58
58
|
...params,
|
|
59
59
|
requestCode,
|
|
60
60
|
});
|
|
@@ -63,14 +63,18 @@ export class Navigator {
|
|
|
63
63
|
cancel();
|
|
64
64
|
throw error;
|
|
65
65
|
}
|
|
66
|
-
if (!
|
|
66
|
+
if (!dispatchResult.ok) {
|
|
67
67
|
cancel();
|
|
68
68
|
if (warnOnFailure) {
|
|
69
|
-
console.warn(warnOnFailure(
|
|
69
|
+
console.warn(warnOnFailure(dispatchResult.code));
|
|
70
70
|
}
|
|
71
|
-
return {
|
|
71
|
+
return {
|
|
72
|
+
status: 'blocked',
|
|
73
|
+
code: RESULT_BLOCK,
|
|
74
|
+
reason: dispatchResult.code,
|
|
75
|
+
};
|
|
72
76
|
}
|
|
73
|
-
return
|
|
77
|
+
return resultPromise;
|
|
74
78
|
};
|
|
75
79
|
push = async (moduleName, ...args) => {
|
|
76
80
|
const [props = {}, options = {}] = args;
|
|
@@ -123,6 +127,14 @@ export class Navigator {
|
|
|
123
127
|
}, code => `presentLayout from:${this.moduleName} failed (${code}).`);
|
|
124
128
|
};
|
|
125
129
|
dismiss = () => dispatchHandler.dispatch(this.sceneId, 'dismiss', { from: this.moduleName });
|
|
130
|
+
closeSelf = (options) => {
|
|
131
|
+
return dispatchHandler.dispatch(this.sceneId, 'close', {
|
|
132
|
+
from: this.moduleName,
|
|
133
|
+
target: 'self',
|
|
134
|
+
onCovered: options?.onCovered,
|
|
135
|
+
...(options?.result !== undefined ? { result: options.result } : {}),
|
|
136
|
+
});
|
|
137
|
+
};
|
|
126
138
|
showModal = async (moduleName, ...args) => {
|
|
127
139
|
const [props = {}, options = {}] = args;
|
|
128
140
|
return this.dispatchForResult('showModal', {
|
|
@@ -141,11 +153,18 @@ export class Navigator {
|
|
|
141
153
|
};
|
|
142
154
|
hideModal = () => dispatchHandler.dispatch(this.sceneId, 'hideModal', { from: this.moduleName });
|
|
143
155
|
setResult = (resultCode, data = null) => resultHandler.setResult(this.sceneId, resultCode, data);
|
|
144
|
-
switchTab = async (
|
|
156
|
+
switchTab = async (target, popToRoot = false) => {
|
|
145
157
|
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
|
+
}
|
|
146
165
|
return dispatchHandler.dispatch(this.sceneId, 'switchTab', {
|
|
147
166
|
from,
|
|
148
|
-
to:
|
|
167
|
+
to: target,
|
|
149
168
|
popToRoot,
|
|
150
169
|
});
|
|
151
170
|
};
|
package/dist/Options.d.ts
CHANGED
|
@@ -27,6 +27,7 @@ export interface NavigationItem extends NavigationOption {
|
|
|
27
27
|
tabItem?: TabItem;
|
|
28
28
|
}
|
|
29
29
|
export interface TabItem {
|
|
30
|
+
key?: string;
|
|
30
31
|
title: string;
|
|
31
32
|
icon?: ImageSource;
|
|
32
33
|
unselectedIcon?: ImageSource;
|
|
@@ -37,6 +38,9 @@ export interface ShadowImage {
|
|
|
37
38
|
}
|
|
38
39
|
export interface DefaultOptions {
|
|
39
40
|
screenBackgroundColor?: Color;
|
|
41
|
+
modalBackgroundColor?: Color;
|
|
42
|
+
injectInitialMetrics?: boolean;
|
|
43
|
+
prewarmPush?: boolean;
|
|
40
44
|
statusBarStyle?: BarStyle;
|
|
41
45
|
navigationBarColorAndroid?: Color;
|
|
42
46
|
displayCutoutWhenLandscapeAndroid?: boolean;
|
|
@@ -48,8 +52,7 @@ export interface DefaultOptions {
|
|
|
48
52
|
tabBarBadgeColor?: Color;
|
|
49
53
|
}
|
|
50
54
|
export type TabBarStyle = Pick<DefaultOptions, 'tabBarBackgroundColor' | 'tabBarShadowImage' | 'tabBarItemSelectedColor' | 'tabBarItemNormalColor'>;
|
|
51
|
-
export interface
|
|
52
|
-
index: number;
|
|
55
|
+
export interface TabItemInfoBase {
|
|
53
56
|
title?: string;
|
|
54
57
|
badge?: {
|
|
55
58
|
text?: string;
|
|
@@ -61,3 +64,10 @@ export interface TabItemInfo {
|
|
|
61
64
|
unselected?: ImageSource;
|
|
62
65
|
};
|
|
63
66
|
}
|
|
67
|
+
export type TabItemInfo = (TabItemInfoBase & {
|
|
68
|
+
index: number;
|
|
69
|
+
key?: string;
|
|
70
|
+
}) | (TabItemInfoBase & {
|
|
71
|
+
key: string;
|
|
72
|
+
index?: number;
|
|
73
|
+
});
|
package/dist/Route.d.ts
CHANGED
|
@@ -1,12 +1,72 @@
|
|
|
1
1
|
import type { NavigationItem } from './Options';
|
|
2
|
-
import type { CustomLayoutMap, NavigationParamList } from './index';
|
|
2
|
+
import type { CustomLayoutMap, NavigationParamList, NavigationTypeConfig } from './index';
|
|
3
3
|
export type Visibility = 'visible' | 'invisible' | 'pending';
|
|
4
4
|
export type SceneLifecycleState = 'created' | 'visible' | 'invisible' | 'destroyed';
|
|
5
|
-
export
|
|
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
|
+
export type DispatchResultCode = 'ok' | 'intercepted' | 'scene_not_found' | 'already_presenting' | 'covered' | 'not_ready' | 'superseded' | 'invalid_action' | 'host_unavailable';
|
|
6
25
|
export interface DispatchResult {
|
|
7
26
|
ok: boolean;
|
|
8
27
|
code: DispatchResultCode;
|
|
9
28
|
message?: string;
|
|
29
|
+
sceneId?: string;
|
|
30
|
+
}
|
|
31
|
+
export type CloseTarget = 'self' | 'presented';
|
|
32
|
+
export type CoveredPolicy = 'fail' | 'defer';
|
|
33
|
+
export type SceneExitRestoreReason = DispatchResultCode | 'exit_error';
|
|
34
|
+
export interface SceneExitHandler {
|
|
35
|
+
onExit: () => void | Promise<void>;
|
|
36
|
+
onRestore?: (reason: SceneExitRestoreReason) => void;
|
|
37
|
+
/** Optional timeout in milliseconds for async onExit(); defaults to 1200ms. */
|
|
38
|
+
exitTimeoutMs?: number;
|
|
39
|
+
}
|
|
40
|
+
export interface CloseSelfOptions<T extends ResultMap = ResultMap> {
|
|
41
|
+
result?: {
|
|
42
|
+
code: number;
|
|
43
|
+
data?: T | null;
|
|
44
|
+
};
|
|
45
|
+
onCovered?: CoveredPolicy;
|
|
46
|
+
}
|
|
47
|
+
export type LeaveAction = 'back' | 'pop' | 'popTo' | 'popToRoot' | 'dismiss' | 'hideModal' | 'close' | 'redirectTo';
|
|
48
|
+
export interface BeforeRemoveEvent {
|
|
49
|
+
sceneId: string;
|
|
50
|
+
action: LeaveAction;
|
|
51
|
+
proceed: () => Promise<DispatchResult>;
|
|
52
|
+
}
|
|
53
|
+
export interface BeforeRemoveOptions {
|
|
54
|
+
actions?: LeaveAction[];
|
|
55
|
+
}
|
|
56
|
+
export type BeforeRemoveListener = (event: BeforeRemoveEvent) => void | Promise<void>;
|
|
57
|
+
export interface InitialMetrics {
|
|
58
|
+
insets: {
|
|
59
|
+
top: number;
|
|
60
|
+
right: number;
|
|
61
|
+
bottom: number;
|
|
62
|
+
left: number;
|
|
63
|
+
};
|
|
64
|
+
frame: {
|
|
65
|
+
x: number;
|
|
66
|
+
y: number;
|
|
67
|
+
width: number;
|
|
68
|
+
height: number;
|
|
69
|
+
};
|
|
10
70
|
}
|
|
11
71
|
export interface SetRootOptions {
|
|
12
72
|
stickyAndroid?: boolean;
|
|
@@ -30,7 +90,11 @@ export type ScreenRoute<Props extends Record<string, any> = Record<never, never>
|
|
|
30
90
|
result: Result;
|
|
31
91
|
};
|
|
32
92
|
export type HasTypedRoutes = keyof NavigationParamList extends never ? false : true;
|
|
33
|
-
export type
|
|
93
|
+
export type AllowUnregisteredRoutes = NavigationTypeConfig extends {
|
|
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;
|
|
34
98
|
type RawRouteEntry<Name extends string> = Name extends keyof NavigationParamList ? NavigationParamList[Name] : ScreenRoute<Record<string, any>, unknown>;
|
|
35
99
|
export type RoutePropsOf<Name extends string> = RawRouteEntry<Name> extends {
|
|
36
100
|
props: infer P;
|
|
@@ -51,7 +115,7 @@ type RequiredKeysOf<T> = {
|
|
|
51
115
|
[K in keyof T]-?: {} extends Pick<T, K> ? never : K;
|
|
52
116
|
}[keyof T];
|
|
53
117
|
export type IsPropsRequired<P> = [RequiredKeysOf<P>] extends [never] ? false : true;
|
|
54
|
-
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];
|
|
118
|
+
export type ScreenPropsArgs<Name extends string> = HasTypedRoutes extends true ? [Name] extends [RegisteredRouteName] ? IsPropsRequired<RoutePropsOf<Name>> extends true ? [props: RoutePropsOf<Name>, options?: NavigationItem] : [props?: RoutePropsOf<Name>, options?: NavigationItem] : [props?: Record<string, any>, options?: NavigationItem] : [props?: Record<string, any>, options?: NavigationItem];
|
|
55
119
|
export type Screen<Name extends RouteName = RouteName> = HasTypedRoutes extends true ? Name extends RouteName ? {
|
|
56
120
|
screen: {
|
|
57
121
|
moduleName: Name;
|
|
@@ -77,6 +141,7 @@ export interface Tabs {
|
|
|
77
141
|
children: Array<Layout>;
|
|
78
142
|
options?: {
|
|
79
143
|
selectedIndex?: number;
|
|
144
|
+
renderer?: string;
|
|
80
145
|
};
|
|
81
146
|
};
|
|
82
147
|
}
|
|
@@ -114,7 +179,7 @@ export interface RouteGraph {
|
|
|
114
179
|
}
|
|
115
180
|
export interface RouteConfig {
|
|
116
181
|
path?: string;
|
|
117
|
-
dependency?:
|
|
182
|
+
dependency?: string;
|
|
118
183
|
mode?: RouteMode;
|
|
119
184
|
options?: NavigationItem;
|
|
120
185
|
lazy?: boolean;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ComponentType } from 'react';
|
|
2
|
+
import type { NavigationItem } from './Options';
|
|
3
|
+
import type { RouteMode, ScreenRoute } from './Route';
|
|
4
|
+
export interface RouteDefinition<Name extends string = string, Props extends Record<string, any> = Record<never, never>, Result = unknown> {
|
|
5
|
+
readonly name: Name;
|
|
6
|
+
readonly load: () => ComponentType<any>;
|
|
7
|
+
readonly options?: NavigationItem;
|
|
8
|
+
readonly path?: string;
|
|
9
|
+
readonly dependency?: string;
|
|
10
|
+
readonly mode?: RouteMode;
|
|
11
|
+
readonly lazy?: boolean;
|
|
12
|
+
readonly __types?: ScreenRoute<Props, Result>;
|
|
13
|
+
}
|
|
14
|
+
export type RouteDefinitionInput<Name extends string, Props extends Record<string, any> = Record<never, never>, Result = unknown> = Omit<RouteDefinition<Name, Props, Result>, '__types'>;
|
|
15
|
+
export declare function defineRoute<const Name extends string, Props extends Record<string, any> = Record<never, never>, Result = unknown>(definition: RouteDefinitionInput<Name, Props, Result>): RouteDefinition<Name, Props, Result>;
|
|
16
|
+
export declare function defineRoutes<const T extends readonly RouteDefinition<any, any, any>[]>(routes: T): T;
|
|
17
|
+
export type RouteParamListOf<T extends readonly RouteDefinition<any, any, any>[]> = {
|
|
18
|
+
[R in T[number] as R['name']]: R extends RouteDefinition<any, infer P, infer Res> ? ScreenRoute<P, Res> : ScreenRoute<Record<string, any>, unknown>;
|
|
19
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DispatchResultWire } from '../NativeNavigation';
|
|
2
2
|
import { NavigationItem } from '../Options';
|
|
3
|
-
import type { BuildInLayout, DispatchResult, Layout } from '../Route';
|
|
3
|
+
import type { BuildInLayout, CloseTarget, CoveredPolicy, DispatchResult, Layout } from '../Route';
|
|
4
4
|
export declare function normalizeDispatchResult(wire: DispatchResultWire | null | undefined): DispatchResult;
|
|
5
5
|
export interface DispatchParams {
|
|
6
6
|
animated?: boolean;
|
|
@@ -10,7 +10,15 @@ export interface DispatchParams {
|
|
|
10
10
|
to?: string | number;
|
|
11
11
|
layout?: BuildInLayout | Layout;
|
|
12
12
|
popToRoot?: boolean;
|
|
13
|
+
tabKey?: string;
|
|
13
14
|
requestCode?: number;
|
|
15
|
+
target?: CloseTarget;
|
|
16
|
+
onCovered?: CoveredPolicy;
|
|
17
|
+
result?: {
|
|
18
|
+
code: number;
|
|
19
|
+
data?: any;
|
|
20
|
+
};
|
|
21
|
+
bypassBeforeRemove?: boolean;
|
|
14
22
|
props?: object;
|
|
15
23
|
options?: NavigationItem;
|
|
16
24
|
[index: string]: any;
|
|
@@ -22,11 +30,18 @@ export interface InterceptParams {
|
|
|
22
30
|
props?: object;
|
|
23
31
|
}
|
|
24
32
|
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>;
|
|
25
34
|
export default class DispatchCommandHandler {
|
|
26
35
|
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>;
|
|
27
41
|
dispatch(sceneId: string, action: string, params: DispatchParams): Promise<DispatchResult>;
|
|
28
42
|
private intercept;
|
|
29
43
|
addInterceptor(interceptor: NavigationInterceptor): void;
|
|
30
44
|
removeInterceptor(interceptor: NavigationInterceptor): void;
|
|
45
|
+
clearInterceptors(): void;
|
|
31
46
|
}
|
|
32
47
|
export declare const dispatchHandler: DispatchCommandHandler;
|