hybrid-navigation 4.1.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/HybridNavigation.podspec +9 -1
- package/README.md +12 -4
- package/android/build.gradle +4 -4
- package/android/proguard-rules.pro +0 -14
- package/android/src/main/java/com/navigation/androidx/AwesomeActivity.java +116 -27
- package/android/src/main/java/com/navigation/androidx/AwesomeFragment.java +162 -13
- package/android/src/main/java/com/navigation/androidx/DefaultTabBarProvider.java +2 -2
- package/android/src/main/java/com/navigation/androidx/DrawableUtils.java +83 -18
- package/android/src/main/java/com/navigation/androidx/DrawerFragment.java +185 -25
- package/android/src/main/java/com/navigation/androidx/FragmentHelper.java +18 -0
- package/android/src/main/java/com/navigation/androidx/HybridDrawerLayout.java +563 -143
- package/android/src/main/java/com/navigation/androidx/LifecycleDelegate.java +39 -12
- package/android/src/main/java/com/navigation/androidx/PresentableActivity.java +3 -0
- package/android/src/main/java/com/navigation/androidx/PresentationDelegate.java +10 -7
- package/android/src/main/java/com/navigation/androidx/StackDelegate.java +29 -9
- package/android/src/main/java/com/navigation/androidx/StackFragment.java +31 -3
- package/android/src/main/java/com/navigation/androidx/SystemUI.java +59 -90
- package/android/src/main/java/com/navigation/androidx/TabBar.java +21 -2
- package/android/src/main/java/com/navigation/androidx/TabBarFragment.java +74 -7
- package/android/src/main/java/com/navigation/androidx/TabBarItem.java +4 -0
- package/android/src/main/java/com/navigation/androidx/TabView.java +11 -2
- package/android/src/main/java/com/reactnative/hybridnavigation/DispatchResult.java +71 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/Garden.java +18 -10
- package/android/src/main/java/com/reactnative/hybridnavigation/GlobalStyle.java +34 -2
- package/android/src/main/java/com/reactnative/hybridnavigation/HBDRootView.java +20 -10
- package/android/src/main/java/com/reactnative/hybridnavigation/HybridFragment.java +179 -13
- package/android/src/main/java/com/reactnative/hybridnavigation/HybridNavigationPackage.java +13 -24
- package/android/src/main/java/com/reactnative/hybridnavigation/NativeEvent.java +5 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/NativeNavigation.java +283 -183
- package/android/src/main/java/com/reactnative/hybridnavigation/NavigationCommandQueue.java +507 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/Navigator.java +4 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/OrientationCoordinator.java +162 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactAppCompatActivity.java +103 -66
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactFragment.java +421 -92
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactManager.java +227 -78
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactStackFragment.java +6 -6
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarFragment.java +26 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarProvider.java +8 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/SceneLifecycleState.java +21 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/SceneLifecycleStateMachine.java +116 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/ScreenOrientation.java +42 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/Utils.java +17 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/DrawerNavigator.java +14 -6
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/ScreenNavigator.java +188 -26
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/StackNavigator.java +67 -16
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/TabNavigator.java +42 -14
- package/dist/DeepLink.d.ts +3 -2
- package/dist/DeepLink.js +37 -14
- package/dist/NativeEvent.d.ts +17 -10
- package/dist/NativeNavigation.d.ts +24 -18
- package/dist/Navigation.d.ts +34 -19
- package/dist/Navigation.js +225 -90
- package/dist/NavigationComponentWrap.d.ts +5 -3
- package/dist/NavigationComponentWrap.js +3 -6
- package/dist/Navigator.d.ts +32 -42
- package/dist/Navigator.js +117 -91
- package/dist/Options.d.ts +15 -3
- package/dist/Route.d.ts +149 -17
- package/dist/defineRoutes.d.ts +19 -0
- package/dist/defineRoutes.js +6 -0
- package/dist/handler/DispatchCommandHandler.d.ts +25 -6
- package/dist/handler/DispatchCommandHandler.js +99 -17
- package/dist/handler/LayoutCommandHandler.d.ts +8 -7
- package/dist/handler/LayoutCommandHandler.js +24 -15
- package/dist/handler/LeaveGuardHandler.d.ts +17 -0
- package/dist/handler/LeaveGuardHandler.js +350 -0
- package/dist/handler/LifecycleEventHandler.d.ts +30 -0
- package/dist/handler/LifecycleEventHandler.js +169 -0
- package/dist/handler/PresentationCoordinator.d.ts +24 -0
- package/dist/handler/PresentationCoordinator.js +449 -0
- package/dist/handler/ResultEventHandler.d.ts +21 -9
- package/dist/handler/ResultEventHandler.js +96 -13
- package/dist/handler/TabEventHandler.d.ts +8 -0
- package/dist/handler/TabEventHandler.js +25 -0
- package/dist/hooks.d.ts +7 -2
- package/dist/hooks.js +46 -4
- package/dist/index.d.ts +24 -0
- package/dist/index.js +3 -2
- package/dist/reveal.d.ts +46 -0
- package/dist/reveal.js +431 -0
- package/dist/routeConfigRegistry.d.ts +6 -0
- package/dist/routeConfigRegistry.js +19 -0
- package/dist/routeGraph.d.ts +12 -0
- package/dist/routeGraph.js +68 -0
- package/dist/router/drawer.d.ts +2 -2
- package/dist/router/drawer.js +6 -3
- package/dist/router/index.d.ts +8 -5
- package/dist/router/index.js +106 -58
- package/dist/router/screen.d.ts +2 -2
- package/dist/router/screen.js +1 -1
- package/dist/router/stack.d.ts +2 -2
- package/dist/router/stack.js +59 -30
- package/dist/router/tabs.d.ts +3 -2
- package/dist/router/tabs.js +4 -1
- package/dist/store.d.ts +4 -2
- package/dist/store.js +4 -0
- package/dist/testing.d.ts +79 -0
- package/dist/testing.js +251 -0
- package/ios/HBDGlobalStyle.h +29 -0
- package/ios/{GlobalStyle.mm → HBDGlobalStyle.mm} +43 -29
- package/ios/HybridNavigation.h +5 -1
- package/ios/Navigator/HBDDrawerNavigator.mm +24 -8
- package/ios/Navigator/HBDNavigatorRegistry.mm +1 -0
- package/ios/Navigator/HBDScreenNavigator.mm +278 -58
- package/ios/Navigator/HBDStackNavigator.mm +152 -61
- package/ios/Navigator/HBDTabNavigator.mm +60 -14
- package/ios/React/HBDNativeNavigation.mm +162 -123
- package/ios/React/HBDNavigator.h +37 -5
- package/ios/React/HBDOrientationCoordinator.h +29 -0
- package/ios/React/HBDOrientationCoordinator.mm +309 -0
- package/ios/React/HBDReactBridgeManager.h +46 -20
- package/ios/React/HBDReactBridgeManager.mm +496 -108
- package/ios/React/HBDSceneLifecycleStateMachine.h +38 -0
- package/ios/React/HBDSceneLifecycleStateMachine.mm +180 -0
- package/ios/View/HBDRootView.h +2 -0
- package/ios/View/HBDRootView.mm +148 -0
- package/ios/View/UIImage+WithBadge.h +3 -3
- package/ios/View/UIImage+WithBadge.mm +10 -15
- package/ios/ViewController/HBDDrawerController.mm +126 -5
- package/ios/ViewController/HBDNavigationController.mm +31 -4
- package/ios/ViewController/HBDReactViewController.h +6 -0
- package/ios/ViewController/HBDReactViewController.mm +220 -106
- package/ios/ViewController/HBDTabBarController.h +15 -0
- package/ios/ViewController/HBDTabBarController.mm +227 -45
- package/ios/ViewController/HBDTabBarRenderer.h +28 -0
- package/ios/ViewController/HBDViewController.h +11 -3
- package/ios/ViewController/HBDViewController.mm +209 -159
- package/ios/ViewController/UINavigationController+HBD.h +2 -2
- package/ios/ViewController/UINavigationController+HBD.mm +3 -3
- package/ios/ViewController/UIViewController+HBD.h +18 -10
- package/ios/ViewController/UIViewController+HBD.mm +90 -65
- package/package.json +3 -1
- package/src/DeepLink.ts +41 -14
- package/src/NativeEvent.ts +18 -11
- package/src/NativeNavigation.ts +29 -31
- package/src/Navigation.ts +377 -120
- package/src/NavigationComponentWrap.tsx +18 -9
- package/src/Navigator.ts +219 -152
- package/src/Options.ts +12 -3
- package/src/Route.ts +228 -17
- package/src/defineRoutes.ts +46 -0
- package/src/handler/DispatchCommandHandler.ts +154 -21
- package/src/handler/LayoutCommandHandler.ts +40 -17
- package/src/handler/LeaveGuardHandler.ts +436 -0
- package/src/handler/LifecycleEventHandler.ts +219 -0
- package/src/handler/PresentationCoordinator.ts +560 -0
- package/src/handler/ResultEventHandler.ts +126 -19
- package/src/handler/TabEventHandler.ts +31 -0
- package/src/hooks.ts +75 -7
- package/src/index.ts +37 -2
- package/src/reveal.ts +565 -0
- package/src/routeConfigRegistry.ts +26 -0
- package/src/routeGraph.ts +87 -0
- package/src/router/drawer.ts +8 -5
- package/src/router/index.ts +139 -63
- package/src/router/screen.ts +3 -3
- package/src/router/stack.ts +80 -29
- package/src/router/tabs.ts +16 -7
- package/src/store.ts +6 -1
- package/src/testing.ts +395 -0
- package/testing.d.ts +1 -0
- package/testing.js +3 -0
- package/android/src/main/java/androidx/fragment/app/InternalFragment.java +0 -22
- package/android/src/main/java/com/navigation/androidx/SystemUI30.java +0 -87
- package/android/src/main/java/com/reactnative/hybridnavigation/NativeGarden.java +0 -176
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBar.java +0 -130
- package/android/src/main/res/layout/nav_tab_bar_react.xml +0 -32
- package/android/src/main/res/layout/nav_tab_bar_react_indeterminate.xml +0 -32
- package/dist/NativeGarden.d.ts +0 -13
- package/dist/NativeGarden.js +0 -2
- package/dist/handler/VisibilityEventHandler.d.ts +0 -13
- package/dist/handler/VisibilityEventHandler.js +0 -39
- package/ios/GlobalStyle.h +0 -15
- package/ios/React/HBDNativeGarden.h +0 -10
- package/ios/React/HBDNativeGarden.mm +0 -111
- package/src/NativeGarden.ts +0 -16
- package/src/handler/VisibilityEventHandler.ts +0 -52
package/src/Route.ts
CHANGED
|
@@ -1,32 +1,233 @@
|
|
|
1
|
+
import type { NavigationItem } from './Options';
|
|
2
|
+
import type { CustomLayoutMap, NavigationParamList, NavigationTypeConfig } from './index';
|
|
3
|
+
|
|
1
4
|
export type Visibility = 'visible' | 'invisible' | 'pending';
|
|
2
5
|
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
export type SceneLifecycleState = 'created' | 'visible' | 'invisible' | 'destroyed';
|
|
7
|
+
|
|
8
|
+
export interface SceneInfo {
|
|
9
|
+
sceneId: string;
|
|
10
|
+
moduleName?: string;
|
|
11
|
+
mode: LayoutMode;
|
|
12
|
+
presentingId: string | null;
|
|
13
|
+
state: SceneLifecycleState;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface TabPressEvent {
|
|
17
|
+
index: number;
|
|
18
|
+
tabKey?: string;
|
|
19
|
+
previousIndex: number;
|
|
20
|
+
reselected: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type TabPressListener = (event: TabPressEvent) => void;
|
|
24
|
+
|
|
25
|
+
export interface NavigationSnapshot {
|
|
26
|
+
rootGeneration: number;
|
|
27
|
+
currentRoute: Route | null;
|
|
28
|
+
layers: RouteGraph[];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export type DispatchResultCode =
|
|
32
|
+
| 'ok'
|
|
33
|
+
| 'intercepted'
|
|
34
|
+
| 'scene_not_found'
|
|
35
|
+
| 'already_presenting'
|
|
36
|
+
| 'covered'
|
|
37
|
+
| 'not_ready'
|
|
38
|
+
| 'superseded'
|
|
39
|
+
| 'invalid_action'
|
|
40
|
+
| 'host_unavailable';
|
|
41
|
+
|
|
42
|
+
export interface DispatchResult {
|
|
43
|
+
ok: boolean;
|
|
44
|
+
code: DispatchResultCode;
|
|
45
|
+
message?: string;
|
|
46
|
+
sceneId?: string;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export type CloseTarget = 'self' | 'presented';
|
|
50
|
+
|
|
51
|
+
export type CoveredPolicy = 'fail' | 'defer';
|
|
52
|
+
|
|
53
|
+
export type SceneExitRestoreReason = DispatchResultCode | 'exit_error';
|
|
54
|
+
|
|
55
|
+
export interface SceneExitHandler {
|
|
56
|
+
onExit: () => void | Promise<void>;
|
|
57
|
+
onRestore?: (reason: SceneExitRestoreReason) => void;
|
|
58
|
+
/** Optional timeout in milliseconds for async onExit(); defaults to 1200ms. */
|
|
59
|
+
exitTimeoutMs?: number;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface CloseSelfOptions<T extends ResultMap = ResultMap> {
|
|
63
|
+
result?: {
|
|
64
|
+
code: number;
|
|
65
|
+
data?: T | null;
|
|
8
66
|
};
|
|
67
|
+
onCovered?: CoveredPolicy;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export type LeaveAction =
|
|
71
|
+
| 'back'
|
|
72
|
+
| 'pop'
|
|
73
|
+
| 'popTo'
|
|
74
|
+
| 'popToRoot'
|
|
75
|
+
| 'dismiss'
|
|
76
|
+
| 'hideModal'
|
|
77
|
+
| 'close'
|
|
78
|
+
| 'redirectTo';
|
|
79
|
+
|
|
80
|
+
export interface BeforeRemoveEvent {
|
|
81
|
+
sceneId: string;
|
|
82
|
+
action: LeaveAction;
|
|
83
|
+
proceed: () => Promise<DispatchResult>;
|
|
9
84
|
}
|
|
10
85
|
|
|
11
|
-
export interface
|
|
86
|
+
export interface BeforeRemoveOptions {
|
|
87
|
+
actions?: LeaveAction[];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export type BeforeRemoveListener = (event: BeforeRemoveEvent) => void | Promise<void>;
|
|
91
|
+
|
|
92
|
+
export interface InitialMetrics {
|
|
93
|
+
insets: {
|
|
94
|
+
top: number;
|
|
95
|
+
right: number;
|
|
96
|
+
bottom: number;
|
|
97
|
+
left: number;
|
|
98
|
+
};
|
|
99
|
+
frame: {
|
|
100
|
+
x: number;
|
|
101
|
+
y: number;
|
|
102
|
+
width: number;
|
|
103
|
+
height: number;
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export interface SetRootOptions {
|
|
108
|
+
stickyAndroid?: boolean;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export type CancelReason = 'dismissed' | 'unmounted' | 'root_reset';
|
|
112
|
+
|
|
113
|
+
export type NavigationResult<T = unknown> =
|
|
114
|
+
| { status: 'ok'; code: number; data: T }
|
|
115
|
+
| { status: 'cancel'; code: number; reason: CancelReason }
|
|
116
|
+
| { status: 'blocked'; code: number; reason: DispatchResultCode };
|
|
117
|
+
|
|
118
|
+
export type ScreenRoute<
|
|
119
|
+
Props extends Record<string, any> = Record<never, never>,
|
|
120
|
+
Result = unknown,
|
|
121
|
+
> = {
|
|
122
|
+
props: Props;
|
|
123
|
+
result: Result;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
export type HasTypedRoutes = keyof NavigationParamList extends never ? false : true;
|
|
127
|
+
|
|
128
|
+
export type AllowUnregisteredRoutes = NavigationTypeConfig extends {
|
|
129
|
+
allowUnregisteredRoutes: true;
|
|
130
|
+
}
|
|
131
|
+
? true
|
|
132
|
+
: false;
|
|
133
|
+
|
|
134
|
+
export type RegisteredRouteName = Extract<keyof NavigationParamList, string>;
|
|
135
|
+
|
|
136
|
+
export type RouteName = HasTypedRoutes extends true
|
|
137
|
+
? AllowUnregisteredRoutes extends true
|
|
138
|
+
? RegisteredRouteName | (string & {})
|
|
139
|
+
: RegisteredRouteName
|
|
140
|
+
: string;
|
|
141
|
+
|
|
142
|
+
type RawRouteEntry<Name extends string> = Name extends keyof NavigationParamList
|
|
143
|
+
? NavigationParamList[Name]
|
|
144
|
+
: ScreenRoute<Record<string, any>, unknown>;
|
|
145
|
+
|
|
146
|
+
export type RoutePropsOf<Name extends string> =
|
|
147
|
+
RawRouteEntry<Name> extends { props: infer P }
|
|
148
|
+
? P
|
|
149
|
+
: RawRouteEntry<Name> extends { props?: infer P }
|
|
150
|
+
? [Exclude<P, undefined>] extends [never]
|
|
151
|
+
? Record<never, never>
|
|
152
|
+
: Exclude<P, undefined>
|
|
153
|
+
: Record<string, any>;
|
|
154
|
+
|
|
155
|
+
export type RouteResultOf<Name extends string> =
|
|
156
|
+
RawRouteEntry<Name> extends { result: infer R }
|
|
157
|
+
? R
|
|
158
|
+
: RawRouteEntry<Name> extends { result?: infer R }
|
|
159
|
+
? unknown extends R
|
|
160
|
+
? unknown
|
|
161
|
+
: [Exclude<R, undefined>] extends [never]
|
|
162
|
+
? unknown
|
|
163
|
+
: Exclude<R, undefined>
|
|
164
|
+
: unknown;
|
|
165
|
+
|
|
166
|
+
export type ResultMap = Record<string, any> & { [Symbol.iterator]?: never };
|
|
167
|
+
|
|
168
|
+
type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
169
|
+
|
|
170
|
+
export type SetResultData<Name extends string> =
|
|
171
|
+
IsAny<Name> extends true
|
|
172
|
+
? any
|
|
173
|
+
: unknown extends RouteResultOf<Name>
|
|
174
|
+
? ResultMap
|
|
175
|
+
: Extract<RouteResultOf<Name>, ResultMap>;
|
|
176
|
+
|
|
177
|
+
type RequiredKeysOf<T> = {
|
|
178
|
+
[K in keyof T]-?: {} extends Pick<T, K> ? never : K;
|
|
179
|
+
}[keyof T];
|
|
180
|
+
|
|
181
|
+
export type IsPropsRequired<P> = [RequiredKeysOf<P>] extends [never] ? false : true;
|
|
182
|
+
|
|
183
|
+
export type ScreenPropsArgs<Name extends string> = HasTypedRoutes extends true
|
|
184
|
+
? [Name] extends [RegisteredRouteName]
|
|
185
|
+
? IsPropsRequired<RoutePropsOf<Name>> extends true
|
|
186
|
+
? [props: RoutePropsOf<Name>, options?: NavigationItem]
|
|
187
|
+
: [props?: RoutePropsOf<Name>, options?: NavigationItem]
|
|
188
|
+
: [props?: Record<string, any>, options?: NavigationItem]
|
|
189
|
+
: [props?: Record<string, any>, options?: NavigationItem];
|
|
190
|
+
|
|
191
|
+
export type Screen<Name extends RouteName = RouteName> = HasTypedRoutes extends true
|
|
192
|
+
? Name extends RouteName
|
|
193
|
+
? {
|
|
194
|
+
screen: {
|
|
195
|
+
moduleName: Name;
|
|
196
|
+
props?: RoutePropsOf<Name>;
|
|
197
|
+
options?: NavigationItem;
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
: never
|
|
201
|
+
: {
|
|
202
|
+
screen: {
|
|
203
|
+
moduleName: Name;
|
|
204
|
+
props?: Record<string, any>;
|
|
205
|
+
options?: NavigationItem;
|
|
206
|
+
};
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
export type TypedScreen = Screen<RouteName>;
|
|
210
|
+
|
|
211
|
+
export interface Stack {
|
|
12
212
|
stack: {
|
|
13
|
-
children: Array<
|
|
213
|
+
children: Array<Layout>;
|
|
14
214
|
options?: {};
|
|
15
215
|
};
|
|
16
216
|
}
|
|
17
217
|
|
|
18
|
-
export interface Tabs
|
|
218
|
+
export interface Tabs {
|
|
19
219
|
tabs: {
|
|
20
|
-
children: Array<
|
|
220
|
+
children: Array<Layout>;
|
|
21
221
|
options?: {
|
|
22
222
|
selectedIndex?: number;
|
|
223
|
+
renderer?: string;
|
|
23
224
|
};
|
|
24
225
|
};
|
|
25
226
|
}
|
|
26
227
|
|
|
27
|
-
export interface Drawer
|
|
228
|
+
export interface Drawer {
|
|
28
229
|
drawer: {
|
|
29
|
-
children: [
|
|
230
|
+
children: [Layout, Layout];
|
|
30
231
|
options?: {
|
|
31
232
|
maxDrawerWidth?: number;
|
|
32
233
|
minDrawerMargin?: number;
|
|
@@ -35,11 +236,17 @@ export interface Drawer extends Layout {
|
|
|
35
236
|
};
|
|
36
237
|
}
|
|
37
238
|
|
|
38
|
-
export type
|
|
239
|
+
export type HasCustomLayouts = keyof CustomLayoutMap extends never ? false : true;
|
|
39
240
|
|
|
40
|
-
export
|
|
41
|
-
|
|
42
|
-
|
|
241
|
+
export type CustomLayout = HasCustomLayouts extends true
|
|
242
|
+
? {
|
|
243
|
+
[K in Extract<keyof CustomLayoutMap, string>]: Record<K, CustomLayoutMap[K]>;
|
|
244
|
+
}[Extract<keyof CustomLayoutMap, string>]
|
|
245
|
+
: never;
|
|
246
|
+
|
|
247
|
+
export type BuiltInLayout = TypedScreen | Stack | Tabs | Drawer;
|
|
248
|
+
export type BuildInLayout = BuiltInLayout;
|
|
249
|
+
export type Layout = BuiltInLayout | CustomLayout;
|
|
43
250
|
|
|
44
251
|
export type RouteMode = 'modal' | 'present' | 'push';
|
|
45
252
|
export type LayoutMode = 'modal' | 'present' | 'normal';
|
|
@@ -63,6 +270,8 @@ export interface RouteConfig {
|
|
|
63
270
|
path?: string;
|
|
64
271
|
dependency?: string;
|
|
65
272
|
mode?: RouteMode;
|
|
273
|
+
options?: NavigationItem;
|
|
274
|
+
lazy?: boolean;
|
|
66
275
|
}
|
|
67
276
|
|
|
68
277
|
export interface RouteData {
|
|
@@ -81,13 +290,15 @@ export interface RouteInfo {
|
|
|
81
290
|
options: object;
|
|
82
291
|
}
|
|
83
292
|
|
|
293
|
+
export type RouteHandleResult = [boolean, RouteGraph | null, DispatchResult?];
|
|
294
|
+
|
|
84
295
|
export interface RouteHandler {
|
|
85
296
|
/**
|
|
86
297
|
* @param graph - current RouteGraph to process
|
|
87
298
|
* @param target - route may add to the graph
|
|
88
|
-
* @returns [boolean, RouteGraph] - if the route is handled, return true and
|
|
299
|
+
* @returns [boolean, RouteGraph | null, DispatchResult?] - if the route is handled, return true and childGraph for next Handler to process, [false, graph] otherwise
|
|
89
300
|
*/
|
|
90
|
-
process: (graph: RouteGraph, target: RouteInfo) => Promise<
|
|
301
|
+
process: (graph: RouteGraph, target: RouteInfo) => Promise<RouteHandleResult>;
|
|
91
302
|
}
|
|
92
303
|
|
|
93
304
|
export type RouteInterceptor = (path: string) => boolean | Promise<boolean>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { ComponentType } from 'react';
|
|
2
|
+
import type { NavigationItem } from './Options';
|
|
3
|
+
import type { RouteMode, ScreenRoute } from './Route';
|
|
4
|
+
|
|
5
|
+
export interface RouteDefinition<
|
|
6
|
+
Name extends string = string,
|
|
7
|
+
Props extends Record<string, any> = Record<never, never>,
|
|
8
|
+
Result = unknown,
|
|
9
|
+
> {
|
|
10
|
+
readonly name: Name;
|
|
11
|
+
readonly load: () => ComponentType<any>;
|
|
12
|
+
readonly options?: NavigationItem;
|
|
13
|
+
readonly path?: string;
|
|
14
|
+
readonly dependency?: string;
|
|
15
|
+
readonly mode?: RouteMode;
|
|
16
|
+
readonly lazy?: boolean;
|
|
17
|
+
readonly __types?: ScreenRoute<Props, Result>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export type RouteDefinitionInput<
|
|
21
|
+
Name extends string,
|
|
22
|
+
Props extends Record<string, any> = Record<never, never>,
|
|
23
|
+
Result = unknown,
|
|
24
|
+
> = Omit<RouteDefinition<Name, Props, Result>, '__types'>;
|
|
25
|
+
|
|
26
|
+
export function defineRoute<
|
|
27
|
+
const Name extends string,
|
|
28
|
+
Props extends Record<string, any> = Record<never, never>,
|
|
29
|
+
Result = unknown,
|
|
30
|
+
>(
|
|
31
|
+
definition: RouteDefinitionInput<Name, Props, Result>,
|
|
32
|
+
): RouteDefinition<Name, Props, Result> {
|
|
33
|
+
return definition;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function defineRoutes<const T extends readonly RouteDefinition<any, any, any>[]>(
|
|
37
|
+
routes: T,
|
|
38
|
+
): T {
|
|
39
|
+
return routes;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export type RouteParamListOf<T extends readonly RouteDefinition<any, any, any>[]> = {
|
|
43
|
+
[R in T[number] as R['name']]: R extends RouteDefinition<any, infer P, infer Res>
|
|
44
|
+
? ScreenRoute<P, Res>
|
|
45
|
+
: ScreenRoute<Record<string, any>, unknown>;
|
|
46
|
+
};
|
|
@@ -1,21 +1,80 @@
|
|
|
1
|
-
import NativeNavigation from '../NativeNavigation';
|
|
1
|
+
import NativeNavigation, { DispatchResultWire } from '../NativeNavigation';
|
|
2
2
|
import { NavigationItem } from '../Options';
|
|
3
|
-
import {
|
|
3
|
+
import type {
|
|
4
|
+
BuildInLayout,
|
|
5
|
+
CloseTarget,
|
|
6
|
+
CoveredPolicy,
|
|
7
|
+
DispatchResult,
|
|
8
|
+
DispatchResultCode,
|
|
9
|
+
Layout,
|
|
10
|
+
} from '../Route';
|
|
11
|
+
import { resultHandler } from './ResultEventHandler';
|
|
12
|
+
|
|
13
|
+
const INTERCEPT_CHECKED_PROP = '__hbdInterceptChecked';
|
|
14
|
+
const INTERNAL_DISPATCH_PROPS = [
|
|
15
|
+
INTERCEPT_CHECKED_PROP,
|
|
16
|
+
'onCovered',
|
|
17
|
+
'bypassBeforeRemove',
|
|
18
|
+
'__hbdBypassBeforeRemove',
|
|
19
|
+
'__hbdApprovedBeforeRemoveScenes',
|
|
20
|
+
] as const;
|
|
21
|
+
|
|
22
|
+
const VALID_DISPATCH_CODES = new Set<DispatchResultCode>([
|
|
23
|
+
'ok',
|
|
24
|
+
'intercepted',
|
|
25
|
+
'scene_not_found',
|
|
26
|
+
'already_presenting',
|
|
27
|
+
'covered',
|
|
28
|
+
'not_ready',
|
|
29
|
+
'superseded',
|
|
30
|
+
'invalid_action',
|
|
31
|
+
'host_unavailable',
|
|
32
|
+
]);
|
|
33
|
+
|
|
34
|
+
export function normalizeDispatchResult(
|
|
35
|
+
wire: DispatchResultWire | null | undefined,
|
|
36
|
+
): DispatchResult {
|
|
37
|
+
if (!wire) {
|
|
38
|
+
return { ok: false, code: 'invalid_action' };
|
|
39
|
+
}
|
|
40
|
+
const code: DispatchResultCode = VALID_DISPATCH_CODES.has(wire.code as DispatchResultCode)
|
|
41
|
+
? (wire.code as DispatchResultCode)
|
|
42
|
+
: wire.ok
|
|
43
|
+
? 'ok'
|
|
44
|
+
: 'invalid_action';
|
|
45
|
+
const result: DispatchResult = { ok: Boolean(wire.ok), code };
|
|
46
|
+
if (wire.message) {
|
|
47
|
+
result.message = wire.message;
|
|
48
|
+
}
|
|
49
|
+
if (wire.sceneId) {
|
|
50
|
+
result.sceneId = wire.sceneId;
|
|
51
|
+
}
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
4
54
|
|
|
5
55
|
export interface DispatchParams {
|
|
6
56
|
animated?: boolean;
|
|
57
|
+
enabled?: boolean;
|
|
7
58
|
moduleName?: string;
|
|
8
59
|
from?: string | number;
|
|
9
60
|
to?: string | number;
|
|
10
61
|
layout?: BuildInLayout | Layout;
|
|
11
62
|
popToRoot?: boolean;
|
|
63
|
+
tabKey?: string;
|
|
12
64
|
requestCode?: number;
|
|
65
|
+
target?: CloseTarget;
|
|
66
|
+
onCovered?: CoveredPolicy;
|
|
67
|
+
result?: {
|
|
68
|
+
code: number;
|
|
69
|
+
data?: any;
|
|
70
|
+
};
|
|
71
|
+
bypassBeforeRemove?: boolean;
|
|
13
72
|
props?: object;
|
|
14
73
|
options?: NavigationItem;
|
|
15
74
|
[index: string]: any;
|
|
16
75
|
}
|
|
17
76
|
|
|
18
|
-
interface InterceptParams {
|
|
77
|
+
export interface InterceptParams {
|
|
19
78
|
sceneId: string;
|
|
20
79
|
from?: number | string;
|
|
21
80
|
to?: number | string;
|
|
@@ -27,10 +86,26 @@ export type NavigationInterceptor = (
|
|
|
27
86
|
params: InterceptParams,
|
|
28
87
|
) => boolean | Promise<boolean>;
|
|
29
88
|
|
|
89
|
+
export type DispatchMiddleware = (
|
|
90
|
+
sceneId: string,
|
|
91
|
+
action: string,
|
|
92
|
+
params: DispatchParams,
|
|
93
|
+
next: (sceneId: string, action: string, params: DispatchParams) => Promise<DispatchResult>,
|
|
94
|
+
) => Promise<DispatchResult>;
|
|
95
|
+
|
|
30
96
|
export default class DispatchCommandHandler {
|
|
31
|
-
private
|
|
97
|
+
private interceptors: NavigationInterceptor[] = [];
|
|
98
|
+
private systemMiddlewares: DispatchMiddleware[] = [];
|
|
99
|
+
|
|
100
|
+
addMiddleware(middleware: DispatchMiddleware) {
|
|
101
|
+
this.systemMiddlewares.push(middleware);
|
|
102
|
+
}
|
|
32
103
|
|
|
33
|
-
|
|
104
|
+
removeMiddleware(middleware: DispatchMiddleware) {
|
|
105
|
+
this.systemMiddlewares = this.systemMiddlewares.filter(item => item !== middleware);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
interceptorMiddleware: DispatchMiddleware = async (sceneId, action, params, next) => {
|
|
34
109
|
const { from, to, props } = params;
|
|
35
110
|
const intercepted = await this.intercept(action, {
|
|
36
111
|
sceneId,
|
|
@@ -38,30 +113,88 @@ export default class DispatchCommandHandler {
|
|
|
38
113
|
to,
|
|
39
114
|
props,
|
|
40
115
|
});
|
|
41
|
-
|
|
42
116
|
if (intercepted) {
|
|
43
|
-
return false;
|
|
117
|
+
return { ok: false, code: 'intercepted' };
|
|
44
118
|
}
|
|
45
|
-
return
|
|
46
|
-
|
|
47
|
-
|
|
119
|
+
return next(sceneId, action, { ...params, [INTERCEPT_CHECKED_PROP]: true });
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
async dispatchRaw(
|
|
123
|
+
sceneId: string,
|
|
124
|
+
action: string,
|
|
125
|
+
params: DispatchParams,
|
|
126
|
+
): Promise<DispatchResult> {
|
|
127
|
+
if (!params[INTERCEPT_CHECKED_PROP]) {
|
|
128
|
+
const { from, to, props } = params;
|
|
129
|
+
const intercepted = await this.intercept(action, {
|
|
130
|
+
sceneId,
|
|
131
|
+
from,
|
|
132
|
+
to,
|
|
133
|
+
props,
|
|
48
134
|
});
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
135
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
136
|
+
if (intercepted) {
|
|
137
|
+
return { ok: false, code: 'intercepted' };
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const nativeParams: DispatchParams = { ...params };
|
|
142
|
+
for (const key of INTERNAL_DISPATCH_PROPS) {
|
|
143
|
+
delete nativeParams[key];
|
|
55
144
|
}
|
|
145
|
+
if (nativeParams.result !== undefined) {
|
|
146
|
+
nativeParams.result = resultHandler.normalizePendingResult(nativeParams.result);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const wire = await NativeNavigation.dispatch(sceneId, action, nativeParams);
|
|
150
|
+
return normalizeDispatchResult(wire);
|
|
151
|
+
}
|
|
56
152
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
153
|
+
async dispatch(
|
|
154
|
+
sceneId: string,
|
|
155
|
+
action: string,
|
|
156
|
+
params: DispatchParams,
|
|
157
|
+
): Promise<DispatchResult> {
|
|
158
|
+
const chain = this.systemMiddlewares.slice();
|
|
159
|
+
const invoke = (
|
|
160
|
+
cursor: number,
|
|
161
|
+
currentSceneId: string,
|
|
162
|
+
currentAction: string,
|
|
163
|
+
currentParams: DispatchParams,
|
|
164
|
+
): Promise<DispatchResult> => {
|
|
165
|
+
if (cursor < chain.length) {
|
|
166
|
+
const middleware = chain[cursor];
|
|
167
|
+
return middleware(currentSceneId, currentAction, currentParams, (s, a, p) =>
|
|
168
|
+
invoke(cursor + 1, s, a, p),
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
return this.dispatchRaw(currentSceneId, currentAction, currentParams);
|
|
172
|
+
};
|
|
173
|
+
return invoke(0, sceneId, action, params);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
private async intercept(action: string, params: InterceptParams): Promise<boolean> {
|
|
177
|
+
for (const interceptor of this.interceptors.slice()) {
|
|
178
|
+
const result = interceptor(action, params);
|
|
179
|
+
const intercepted = result instanceof Promise ? await result : result;
|
|
180
|
+
if (intercepted) {
|
|
181
|
+
return true;
|
|
182
|
+
}
|
|
60
183
|
}
|
|
61
|
-
return
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
addInterceptor(interceptor: NavigationInterceptor) {
|
|
188
|
+
this.interceptors.push(interceptor);
|
|
62
189
|
}
|
|
63
190
|
|
|
64
|
-
|
|
65
|
-
this.
|
|
191
|
+
removeInterceptor(interceptor: NavigationInterceptor) {
|
|
192
|
+
this.interceptors = this.interceptors.filter(item => item !== interceptor);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
clearInterceptors() {
|
|
196
|
+
this.interceptors = [];
|
|
66
197
|
}
|
|
67
198
|
}
|
|
199
|
+
|
|
200
|
+
export const dispatchHandler = new DispatchCommandHandler();
|
|
@@ -1,32 +1,55 @@
|
|
|
1
|
-
import { BuildInLayout, Layout } from '../Route';
|
|
1
|
+
import type { BuildInLayout, DispatchResult, Layout, SetRootOptions } from '../Route';
|
|
2
2
|
import NativeEvent from '../NativeEvent';
|
|
3
3
|
import NativeNavigation from '../NativeNavigation';
|
|
4
|
+
import { normalizeDispatchResult } from './DispatchCommandHandler';
|
|
4
5
|
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
export type RootLayoutListener = () => void;
|
|
7
|
+
|
|
8
|
+
type RootLayoutSubscriptionRecord = {
|
|
9
|
+
willSetRoot?: RootLayoutListener;
|
|
10
|
+
didSetRoot?: RootLayoutListener;
|
|
11
|
+
};
|
|
8
12
|
|
|
9
|
-
|
|
13
|
+
export default class LayoutCommandHandler {
|
|
14
|
+
private listeners: RootLayoutSubscriptionRecord[] = [];
|
|
10
15
|
|
|
11
|
-
handleRootLayoutChange() {
|
|
16
|
+
handleRootLayoutChange(onWillSetRoot?: () => void) {
|
|
12
17
|
NativeEvent.willSetRoot(() => {
|
|
13
|
-
|
|
18
|
+
onWillSetRoot?.();
|
|
19
|
+
for (const listener of this.listeners.slice()) {
|
|
20
|
+
listener.willSetRoot?.();
|
|
21
|
+
}
|
|
14
22
|
});
|
|
15
23
|
NativeEvent.didSetRoot(() => {
|
|
16
|
-
this.
|
|
24
|
+
for (const listener of this.listeners.slice()) {
|
|
25
|
+
listener.didSetRoot?.();
|
|
26
|
+
}
|
|
17
27
|
});
|
|
18
28
|
}
|
|
19
29
|
|
|
20
|
-
setRoot(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
30
|
+
async setRoot(
|
|
31
|
+
layout: BuildInLayout | Layout,
|
|
32
|
+
options?: SetRootOptions,
|
|
33
|
+
): Promise<DispatchResult> {
|
|
34
|
+
const sticky = Boolean(options?.stickyAndroid);
|
|
35
|
+
const wire = await NativeNavigation.setRoot(layout, sticky);
|
|
36
|
+
return normalizeDispatchResult(wire);
|
|
26
37
|
}
|
|
27
38
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
39
|
+
addRootLayoutUpdateListener(
|
|
40
|
+
willSetRoot?: RootLayoutListener,
|
|
41
|
+
didSetRoot?: RootLayoutListener,
|
|
42
|
+
): () => void {
|
|
43
|
+
const record: RootLayoutSubscriptionRecord = { willSetRoot, didSetRoot };
|
|
44
|
+
this.listeners.push(record);
|
|
45
|
+
return () => {
|
|
46
|
+
this.listeners = this.listeners.filter(item => item !== record);
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
clearListeners() {
|
|
51
|
+
this.listeners = [];
|
|
31
52
|
}
|
|
32
53
|
}
|
|
54
|
+
|
|
55
|
+
export const layoutHandler = new LayoutCommandHandler();
|