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/Navigation.ts
CHANGED
|
@@ -2,25 +2,77 @@ import type React from 'react';
|
|
|
2
2
|
import { AppRegistry, ComponentProvider } from 'react-native';
|
|
3
3
|
|
|
4
4
|
import type { DefaultOptions, NavigationOption, TabBarStyle, TabItemInfo } from './Options';
|
|
5
|
-
import type {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
import type {
|
|
6
|
+
BeforeRemoveListener,
|
|
7
|
+
BeforeRemoveOptions,
|
|
8
|
+
BuildInLayout,
|
|
9
|
+
CloseSelfOptions,
|
|
10
|
+
DispatchResult,
|
|
11
|
+
Layout,
|
|
12
|
+
NavigationResult,
|
|
13
|
+
NavigationSnapshot,
|
|
14
|
+
ResultMap,
|
|
15
|
+
Route,
|
|
16
|
+
RouteConfig,
|
|
17
|
+
RouteGraph,
|
|
18
|
+
RouteName,
|
|
19
|
+
SceneExitHandler,
|
|
20
|
+
SceneInfo,
|
|
21
|
+
SceneLifecycleState,
|
|
22
|
+
SetRootOptions,
|
|
23
|
+
TabPressListener,
|
|
24
|
+
} from './Route';
|
|
25
|
+
|
|
26
|
+
import { layoutHandler, RootLayoutListener } from './handler/LayoutCommandHandler';
|
|
27
|
+
import { dispatchHandler } from './handler/DispatchCommandHandler';
|
|
28
|
+
import { leaveGuardHandler } from './handler/LeaveGuardHandler';
|
|
29
|
+
import { presentationCoordinator } from './handler/PresentationCoordinator';
|
|
30
|
+
import { tabEventHandler } from './handler/TabEventHandler';
|
|
31
|
+
import { executeReveal, type RevealOptions, type RevealResult, type RevealTarget } from './reveal';
|
|
32
|
+
import type { RouteDefinition } from './defineRoutes';
|
|
33
|
+
import {
|
|
34
|
+
RESULT_BLOCK,
|
|
35
|
+
RESULT_CANCEL,
|
|
36
|
+
RESULT_OK,
|
|
37
|
+
resultHandler,
|
|
38
|
+
} from './handler/ResultEventHandler';
|
|
39
|
+
import {
|
|
40
|
+
GlobalSceneLifecycleListener,
|
|
11
41
|
GlobalVisibilityEventListener,
|
|
42
|
+
lifecycleHandler,
|
|
43
|
+
SceneLifecycleListener,
|
|
12
44
|
VisibilityEventListener,
|
|
13
|
-
} from './handler/
|
|
45
|
+
} from './handler/LifecycleEventHandler';
|
|
14
46
|
|
|
15
|
-
import NativeEvent from './NativeEvent';
|
|
16
47
|
import NativeNavigation from './NativeNavigation';
|
|
17
|
-
import
|
|
48
|
+
import store from './store';
|
|
49
|
+
import { withNavigation } from './NavigationComponentWrap';
|
|
50
|
+
import {
|
|
51
|
+
bumpRouteConfigVersion,
|
|
52
|
+
clearRouteConfigs,
|
|
53
|
+
getRouteConfigs,
|
|
54
|
+
setRouteConfig,
|
|
55
|
+
} from './routeConfigRegistry';
|
|
18
56
|
|
|
19
57
|
export type { ResultType } from './handler/ResultEventHandler';
|
|
20
|
-
import type {
|
|
21
|
-
|
|
58
|
+
import type {
|
|
59
|
+
DispatchParams,
|
|
60
|
+
NavigationInterceptor,
|
|
61
|
+
} from './handler/DispatchCommandHandler';
|
|
62
|
+
export type {
|
|
63
|
+
DispatchParams,
|
|
64
|
+
InterceptParams,
|
|
65
|
+
NavigationInterceptor,
|
|
66
|
+
} from './handler/DispatchCommandHandler';
|
|
67
|
+
export type {
|
|
68
|
+
GlobalSceneLifecycleListener,
|
|
69
|
+
GlobalVisibilityEventListener,
|
|
70
|
+
SceneLifecycleListener,
|
|
71
|
+
VisibilityEventListener,
|
|
72
|
+
} from './handler/LifecycleEventHandler';
|
|
73
|
+
export type { RootLayoutListener } from './handler/LayoutCommandHandler';
|
|
22
74
|
|
|
23
|
-
export
|
|
75
|
+
export { RESULT_CANCEL, RESULT_OK, RESULT_BLOCK };
|
|
24
76
|
|
|
25
77
|
export type NavigationSubscription = {
|
|
26
78
|
remove: () => void;
|
|
@@ -31,14 +83,18 @@ export type HOC = (WrappedComponent: React.ComponentType<any>) => React.Componen
|
|
|
31
83
|
export interface Navigation {
|
|
32
84
|
startRegisterComponent(hoc?: HOC): void;
|
|
33
85
|
endRegisterComponent(): void;
|
|
34
|
-
registerComponent(
|
|
35
|
-
appKey:
|
|
86
|
+
registerComponent<Name extends RouteName = RouteName>(
|
|
87
|
+
appKey: Name,
|
|
36
88
|
getComponentFunc: ComponentProvider,
|
|
37
89
|
routeConfig?: RouteConfig,
|
|
38
90
|
): void;
|
|
91
|
+
registerRoutes(routes: readonly RouteDefinition<any, any, any>[]): void;
|
|
92
|
+
preloadRoute(moduleName: RouteName): void;
|
|
39
93
|
|
|
40
|
-
|
|
41
|
-
|
|
94
|
+
addLifecycleListener(sceneId: string, listener: SceneLifecycleListener): NavigationSubscription;
|
|
95
|
+
addGlobalLifecycleListener(listener: GlobalSceneLifecycleListener): NavigationSubscription;
|
|
96
|
+
getSceneState(sceneId: string): SceneLifecycleState;
|
|
97
|
+
getSceneInfo(sceneId: string): SceneInfo | undefined;
|
|
42
98
|
addGlobalVisibilityEventListener(
|
|
43
99
|
listener: GlobalVisibilityEventListener,
|
|
44
100
|
): NavigationSubscription;
|
|
@@ -46,46 +102,91 @@ export interface Navigation {
|
|
|
46
102
|
sceneId: string,
|
|
47
103
|
listener: VisibilityEventListener,
|
|
48
104
|
): NavigationSubscription;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
105
|
+
addTabPressListener(listener: TabPressListener): NavigationSubscription;
|
|
106
|
+
|
|
107
|
+
dispatch(sceneId: string, action: string, params?: DispatchParams): Promise<DispatchResult>;
|
|
108
|
+
addInterceptor(interceptor: NavigationInterceptor): NavigationSubscription;
|
|
109
|
+
registerSceneExitHandler(
|
|
110
|
+
sceneId: string,
|
|
111
|
+
handler: SceneExitHandler,
|
|
112
|
+
): NavigationSubscription;
|
|
113
|
+
addBeforeRemoveListener(
|
|
114
|
+
sceneId: string,
|
|
115
|
+
listener: BeforeRemoveListener,
|
|
116
|
+
options?: BeforeRemoveOptions,
|
|
117
|
+
): NavigationSubscription;
|
|
118
|
+
closeScene<T extends ResultMap = ResultMap>(
|
|
119
|
+
sceneId: string,
|
|
120
|
+
options?: CloseSelfOptions<T>,
|
|
121
|
+
): Promise<DispatchResult>;
|
|
122
|
+
reveal(target: RevealTarget, options?: RevealOptions): Promise<RevealResult>;
|
|
123
|
+
setResult<T extends ResultMap = ResultMap>(
|
|
124
|
+
sceneId: string,
|
|
125
|
+
resultCode: number,
|
|
126
|
+
data?: T | null,
|
|
127
|
+
): void;
|
|
128
|
+
result<T = unknown>(sceneId: string, requestCode: number): Promise<NavigationResult<T>>;
|
|
129
|
+
setRoot(layout: BuildInLayout | Layout, options?: SetRootOptions): Promise<DispatchResult>;
|
|
130
|
+
addRootLayoutUpdateListener(
|
|
131
|
+
willSetRoot?: RootLayoutListener,
|
|
132
|
+
didSetRoot?: RootLayoutListener,
|
|
133
|
+
): NavigationSubscription;
|
|
134
|
+
|
|
56
135
|
currentTab(sceneId: string): Promise<number>;
|
|
57
|
-
findSceneIdByModuleName(moduleName:
|
|
136
|
+
findSceneIdByModuleName(moduleName: RouteName): Promise<string | null>;
|
|
58
137
|
isStackRoot(sceneId: string): Promise<boolean>;
|
|
59
|
-
|
|
60
|
-
currentRoute(): Promise<Route>;
|
|
138
|
+
currentRoute(): Promise<Route | null>;
|
|
61
139
|
routeGraph(): Promise<RouteGraph[]>;
|
|
140
|
+
navigationSnapshot(): Promise<NavigationSnapshot>;
|
|
141
|
+
|
|
62
142
|
setDefaultOptions(options: DefaultOptions): void;
|
|
63
143
|
updateOptions(sceneId: string, options: NavigationOption): void;
|
|
144
|
+
updateTabBar(options: TabBarStyle): void;
|
|
64
145
|
updateTabBar(sceneId: string, options: TabBarStyle): void;
|
|
146
|
+
setTabItem(item: TabItemInfo | TabItemInfo[]): void;
|
|
65
147
|
setTabItem(sceneId: string, item: TabItemInfo | TabItemInfo[]): void;
|
|
66
|
-
setMenuInteractive(sceneId: string, enabled: boolean):
|
|
148
|
+
setMenuInteractive(sceneId: string, enabled: boolean): Promise<DispatchResult>;
|
|
67
149
|
}
|
|
68
150
|
|
|
69
151
|
class NavigationImpl implements Navigation {
|
|
70
|
-
private dispatchHandler = new DispatchCommandHandler();
|
|
71
|
-
private resultHandler = new ResultEventHandler();
|
|
72
|
-
private layoutHandler = new LayoutCommandHandler();
|
|
73
|
-
private visibilityHandler = new VisibilityEventHandler();
|
|
74
|
-
|
|
75
152
|
constructor() {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
153
|
+
leaveGuardHandler.setDispatcher((sceneId, action, params) =>
|
|
154
|
+
dispatchHandler.dispatch(sceneId, action, params),
|
|
155
|
+
);
|
|
156
|
+
dispatchHandler.addMiddleware(leaveGuardHandler.middleware);
|
|
157
|
+
dispatchHandler.addMiddleware(dispatchHandler.interceptorMiddleware);
|
|
158
|
+
dispatchHandler.addMiddleware(presentationCoordinator.middleware);
|
|
159
|
+
layoutHandler.handleRootLayoutChange(() => {
|
|
160
|
+
lifecycleHandler.onRootReset();
|
|
161
|
+
leaveGuardHandler.onRootReset();
|
|
162
|
+
presentationCoordinator.onRootReset();
|
|
163
|
+
resultHandler.invalidateAll('root_reset');
|
|
164
|
+
});
|
|
165
|
+
lifecycleHandler.handleSceneLifecycle(sceneId => {
|
|
166
|
+
leaveGuardHandler.onSceneDestroyed(sceneId);
|
|
167
|
+
presentationCoordinator.onSceneDestroyed(sceneId);
|
|
168
|
+
resultHandler.invalidateResultEventListener(sceneId, 'unmounted');
|
|
169
|
+
store.removeNavigator(sceneId);
|
|
170
|
+
});
|
|
171
|
+
resultHandler.handleComponentResult();
|
|
172
|
+
leaveGuardHandler.handleNativeBeforeRemoveRequests();
|
|
173
|
+
tabEventHandler.handleTabPress();
|
|
80
174
|
}
|
|
81
175
|
|
|
82
|
-
private wrap?: (moduleName: string) => HOC;
|
|
83
176
|
private hoc?: HOC;
|
|
84
177
|
private registerEnded = false;
|
|
178
|
+
private registeredNames = new Set<string>();
|
|
179
|
+
private registeredPaths = new Map<string, string>();
|
|
180
|
+
private routeLoaders = new Map<string, () => React.ComponentType<any>>();
|
|
181
|
+
private revealQueue: Promise<unknown> = Promise.resolve();
|
|
85
182
|
|
|
86
183
|
startRegisterComponent(hoc?: HOC) {
|
|
87
184
|
this.hoc = hoc;
|
|
88
185
|
this.registerEnded = false;
|
|
186
|
+
this.registeredNames.clear();
|
|
187
|
+
this.registeredPaths.clear();
|
|
188
|
+
this.routeLoaders.clear();
|
|
189
|
+
clearRouteConfigs();
|
|
89
190
|
NativeNavigation.startRegisterReactComponent();
|
|
90
191
|
}
|
|
91
192
|
|
|
@@ -95,50 +196,173 @@ class NavigationImpl implements Navigation {
|
|
|
95
196
|
return;
|
|
96
197
|
}
|
|
97
198
|
this.registerEnded = true;
|
|
199
|
+
if (__DEV__) {
|
|
200
|
+
this.validateRouteDependencies();
|
|
201
|
+
}
|
|
202
|
+
bumpRouteConfigVersion();
|
|
98
203
|
NativeNavigation.endRegisterReactComponent();
|
|
99
204
|
}
|
|
100
205
|
|
|
101
|
-
|
|
102
|
-
|
|
206
|
+
private validateRouteDependencies() {
|
|
207
|
+
const configs = getRouteConfigs();
|
|
208
|
+
const state = new Map<string, 'visiting' | 'visited'>();
|
|
209
|
+
const stack: string[] = [];
|
|
210
|
+
|
|
211
|
+
const visit = (name: string) => {
|
|
212
|
+
state.set(name, 'visiting');
|
|
213
|
+
stack.push(name);
|
|
214
|
+
const dependency = configs.get(name)?.dependency;
|
|
215
|
+
if (dependency) {
|
|
216
|
+
const depState = state.get(dependency);
|
|
217
|
+
if (depState === 'visiting') {
|
|
218
|
+
const cycleStart = stack.indexOf(dependency);
|
|
219
|
+
const cycle = [...stack.slice(cycleStart), dependency].join(' -> ');
|
|
220
|
+
console.warn(`[hybrid-navigation] Circular route dependency detected: ${cycle}`);
|
|
221
|
+
} else if (!depState && configs.has(dependency)) {
|
|
222
|
+
visit(dependency);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
stack.pop();
|
|
226
|
+
state.set(name, 'visited');
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
for (const name of configs.keys()) {
|
|
230
|
+
if (!state.has(name)) {
|
|
231
|
+
visit(name);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
registerComponent<Name extends RouteName = RouteName>(
|
|
237
|
+
appKey: Name,
|
|
103
238
|
getComponentFunc: ComponentProvider,
|
|
104
239
|
routeConfig?: RouteConfig,
|
|
105
240
|
) {
|
|
106
|
-
if (
|
|
107
|
-
this.
|
|
241
|
+
if (__DEV__) {
|
|
242
|
+
if (this.registeredNames.has(appKey)) {
|
|
243
|
+
console.warn(
|
|
244
|
+
`[hybrid-navigation] Duplicate route registration for "${appKey}". Later registration overrides earlier one.`,
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
if (routeConfig?.path) {
|
|
248
|
+
const existing = this.registeredPaths.get(routeConfig.path);
|
|
249
|
+
if (existing && existing !== appKey) {
|
|
250
|
+
console.warn(
|
|
251
|
+
`[hybrid-navigation] Duplicate route path "${routeConfig.path}" registered by "${appKey}" and "${existing}".`,
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
this.registeredPaths.set(routeConfig.path, appKey);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
this.registeredNames.add(appKey);
|
|
258
|
+
|
|
259
|
+
if (routeConfig && (routeConfig.path || routeConfig.dependency || routeConfig.mode)) {
|
|
260
|
+
setRouteConfig(appKey, routeConfig);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
const hoc = this.hoc;
|
|
264
|
+
|
|
265
|
+
const isLazy = routeConfig?.lazy === true;
|
|
266
|
+
|
|
267
|
+
if (isLazy) {
|
|
268
|
+
NativeNavigation.registerReactComponent(appKey, routeConfig?.options ?? {});
|
|
269
|
+
let CachedRootComponent: React.ComponentType<any> | undefined;
|
|
270
|
+
const loader = () => {
|
|
271
|
+
if (!CachedRootComponent) {
|
|
272
|
+
let WrappedComponent = getComponentFunc();
|
|
273
|
+
if (__DEV__ && (WrappedComponent as any)?.navigationItem) {
|
|
274
|
+
console.warn(
|
|
275
|
+
`[hybrid-navigation] "${appKey}" enabled lazy registration via registerComponent(), so withNavigationItem() on the component is ignored.`,
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
if (hoc) {
|
|
279
|
+
WrappedComponent = hoc(WrappedComponent);
|
|
280
|
+
}
|
|
281
|
+
CachedRootComponent = withNavigation(appKey)(WrappedComponent);
|
|
282
|
+
}
|
|
283
|
+
return CachedRootComponent;
|
|
284
|
+
};
|
|
285
|
+
this.routeLoaders.set(appKey, loader);
|
|
286
|
+
AppRegistry.registerComponent(appKey, loader);
|
|
287
|
+
return;
|
|
108
288
|
}
|
|
109
289
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
290
|
+
const RawComponent = getComponentFunc();
|
|
291
|
+
let WrappedComponent = RawComponent;
|
|
292
|
+
if (hoc) {
|
|
293
|
+
WrappedComponent = hoc(WrappedComponent);
|
|
113
294
|
}
|
|
114
295
|
|
|
115
|
-
const options: object =
|
|
296
|
+
const options: object =
|
|
297
|
+
routeConfig?.options ??
|
|
298
|
+
(RawComponent as any)?.navigationItem ??
|
|
299
|
+
(WrappedComponent as any)?.navigationItem ??
|
|
300
|
+
{};
|
|
116
301
|
NativeNavigation.registerReactComponent(appKey, options);
|
|
117
302
|
|
|
118
|
-
|
|
303
|
+
const RootComponent = withNavigation(appKey)(WrappedComponent);
|
|
119
304
|
AppRegistry.registerComponent(appKey, () => RootComponent);
|
|
120
305
|
}
|
|
121
306
|
|
|
122
|
-
|
|
307
|
+
registerRoutes(routes: readonly RouteDefinition<any, any, any>[]) {
|
|
308
|
+
for (const route of routes) {
|
|
309
|
+
const hasConfig =
|
|
310
|
+
route.path !== undefined ||
|
|
311
|
+
route.dependency !== undefined ||
|
|
312
|
+
route.mode !== undefined ||
|
|
313
|
+
route.options !== undefined ||
|
|
314
|
+
route.lazy !== undefined;
|
|
315
|
+
const config: RouteConfig | undefined = hasConfig
|
|
316
|
+
? {
|
|
317
|
+
path: route.path,
|
|
318
|
+
dependency: route.dependency as RouteName | undefined,
|
|
319
|
+
mode: route.mode,
|
|
320
|
+
options: route.options,
|
|
321
|
+
lazy: route.lazy,
|
|
322
|
+
}
|
|
323
|
+
: undefined;
|
|
324
|
+
this.registerComponent(route.name as RouteName, route.load, config);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
preloadRoute(moduleName: RouteName) {
|
|
329
|
+
const loader = this.routeLoaders.get(moduleName);
|
|
330
|
+
if (loader) {
|
|
331
|
+
loader();
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
addLifecycleListener(
|
|
336
|
+
sceneId: string,
|
|
337
|
+
listener: SceneLifecycleListener,
|
|
338
|
+
): NavigationSubscription {
|
|
339
|
+
lifecycleHandler.addLifecycleListener(sceneId, listener);
|
|
340
|
+
return {
|
|
341
|
+
remove: () => lifecycleHandler.removeLifecycleListener(sceneId, listener),
|
|
342
|
+
};
|
|
343
|
+
}
|
|
123
344
|
|
|
124
|
-
|
|
125
|
-
|
|
345
|
+
addGlobalLifecycleListener(listener: GlobalSceneLifecycleListener): NavigationSubscription {
|
|
346
|
+
lifecycleHandler.addGlobalLifecycleListener(listener);
|
|
347
|
+
return {
|
|
348
|
+
remove: () => lifecycleHandler.removeGlobalLifecycleListener(listener),
|
|
349
|
+
};
|
|
126
350
|
}
|
|
127
351
|
|
|
128
|
-
|
|
129
|
-
return
|
|
352
|
+
getSceneState(sceneId: string): SceneLifecycleState {
|
|
353
|
+
return lifecycleHandler.getSceneState(sceneId);
|
|
130
354
|
}
|
|
131
355
|
|
|
132
|
-
|
|
133
|
-
|
|
356
|
+
getSceneInfo(sceneId: string): SceneInfo | undefined {
|
|
357
|
+
return lifecycleHandler.getSceneInfo(sceneId);
|
|
134
358
|
}
|
|
135
359
|
|
|
136
360
|
addGlobalVisibilityEventListener(
|
|
137
361
|
listener: GlobalVisibilityEventListener,
|
|
138
362
|
): NavigationSubscription {
|
|
139
|
-
|
|
363
|
+
lifecycleHandler.addGlobalVisibilityEventListener(listener);
|
|
140
364
|
return {
|
|
141
|
-
remove: () =>
|
|
365
|
+
remove: () => lifecycleHandler.removeGlobalVisibilityEventListener(listener),
|
|
142
366
|
};
|
|
143
367
|
}
|
|
144
368
|
|
|
@@ -146,120 +370,153 @@ class NavigationImpl implements Navigation {
|
|
|
146
370
|
sceneId: string,
|
|
147
371
|
listener: VisibilityEventListener,
|
|
148
372
|
): NavigationSubscription {
|
|
149
|
-
|
|
373
|
+
lifecycleHandler.addVisibilityEventListener(sceneId, listener);
|
|
150
374
|
return {
|
|
151
|
-
remove: () =>
|
|
375
|
+
remove: () => lifecycleHandler.removeVisibilityEventListener(sceneId, listener),
|
|
152
376
|
};
|
|
153
377
|
}
|
|
154
378
|
|
|
379
|
+
addTabPressListener(listener: TabPressListener): NavigationSubscription {
|
|
380
|
+
const remove = tabEventHandler.addListener(listener);
|
|
381
|
+
return { remove };
|
|
382
|
+
}
|
|
383
|
+
|
|
155
384
|
dispatch(sceneId: string, action: string, params: DispatchParams = {}) {
|
|
156
|
-
return
|
|
385
|
+
return dispatchHandler.dispatch(sceneId, action, params);
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
addInterceptor(interceptor: NavigationInterceptor): NavigationSubscription {
|
|
389
|
+
dispatchHandler.addInterceptor(interceptor);
|
|
390
|
+
return {
|
|
391
|
+
remove: () => dispatchHandler.removeInterceptor(interceptor),
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
registerSceneExitHandler(
|
|
396
|
+
sceneId: string,
|
|
397
|
+
handler: SceneExitHandler,
|
|
398
|
+
): NavigationSubscription {
|
|
399
|
+
const remove = presentationCoordinator.registerExitHandler(sceneId, handler);
|
|
400
|
+
return { remove };
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
addBeforeRemoveListener(
|
|
404
|
+
sceneId: string,
|
|
405
|
+
listener: BeforeRemoveListener,
|
|
406
|
+
options?: BeforeRemoveOptions,
|
|
407
|
+
): NavigationSubscription {
|
|
408
|
+
const remove = leaveGuardHandler.addListener(sceneId, listener, options);
|
|
409
|
+
return { remove };
|
|
157
410
|
}
|
|
158
411
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
412
|
+
closeScene<T extends ResultMap = ResultMap>(
|
|
413
|
+
sceneId: string,
|
|
414
|
+
options?: CloseSelfOptions<T>,
|
|
415
|
+
): Promise<DispatchResult> {
|
|
416
|
+
return this.dispatch(sceneId, 'close', {
|
|
417
|
+
target: 'self',
|
|
418
|
+
onCovered: options?.onCovered,
|
|
419
|
+
...(options?.result !== undefined ? { result: options.result } : {}),
|
|
162
420
|
});
|
|
163
421
|
}
|
|
164
422
|
|
|
165
|
-
|
|
166
|
-
this.
|
|
423
|
+
reveal(target: RevealTarget, options?: RevealOptions): Promise<RevealResult> {
|
|
424
|
+
const task = this.revealQueue.then(
|
|
425
|
+
() => executeReveal(this, target, options),
|
|
426
|
+
() => executeReveal(this, target, options),
|
|
427
|
+
);
|
|
428
|
+
this.revealQueue = task.then(
|
|
429
|
+
() => undefined,
|
|
430
|
+
() => undefined,
|
|
431
|
+
);
|
|
432
|
+
return task;
|
|
167
433
|
}
|
|
168
434
|
|
|
169
|
-
setResult = <T extends
|
|
435
|
+
setResult = <T extends ResultMap = ResultMap>(
|
|
170
436
|
sceneId: string,
|
|
171
437
|
resultCode: number,
|
|
172
|
-
data: T
|
|
438
|
+
data: T | null = null,
|
|
173
439
|
): void => {
|
|
174
|
-
|
|
175
|
-
console.warn(
|
|
176
|
-
'`resultCode` can only be `RESULT_OK`, `RESULT_CANCEL` or an integer greater than 0.',
|
|
177
|
-
);
|
|
178
|
-
}
|
|
179
|
-
NativeNavigation.setResult(sceneId, resultCode, data as object);
|
|
440
|
+
resultHandler.setResult(sceneId, resultCode, data);
|
|
180
441
|
};
|
|
181
442
|
|
|
182
|
-
result<T
|
|
183
|
-
return
|
|
443
|
+
result<T = unknown>(sceneId: string, requestCode: number) {
|
|
444
|
+
return resultHandler.waitResult<T>(sceneId, requestCode);
|
|
184
445
|
}
|
|
185
446
|
|
|
186
|
-
|
|
187
|
-
|
|
447
|
+
setRoot(layout: BuildInLayout | Layout, options?: SetRootOptions) {
|
|
448
|
+
return layoutHandler.setRoot(layout, options);
|
|
188
449
|
}
|
|
189
450
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
451
|
+
addRootLayoutUpdateListener(
|
|
452
|
+
willSetRoot?: RootLayoutListener,
|
|
453
|
+
didSetRoot?: RootLayoutListener,
|
|
454
|
+
): NavigationSubscription {
|
|
455
|
+
const remove = layoutHandler.addRootLayoutUpdateListener(willSetRoot, didSetRoot);
|
|
456
|
+
return { remove };
|
|
196
457
|
}
|
|
197
458
|
|
|
198
459
|
currentTab(sceneId: string) {
|
|
199
|
-
return
|
|
200
|
-
NativeNavigation.currentTab(sceneId, (_, index) => {
|
|
201
|
-
resolve(index);
|
|
202
|
-
});
|
|
203
|
-
});
|
|
460
|
+
return NativeNavigation.currentTab(sceneId);
|
|
204
461
|
}
|
|
205
462
|
|
|
206
|
-
findSceneIdByModuleName(moduleName:
|
|
207
|
-
return
|
|
208
|
-
NativeNavigation.findSceneIdByModuleName(moduleName, (_, sceneId) => {
|
|
209
|
-
resolve(sceneId);
|
|
210
|
-
});
|
|
211
|
-
});
|
|
463
|
+
findSceneIdByModuleName(moduleName: RouteName) {
|
|
464
|
+
return NativeNavigation.findSceneIdByModuleName(moduleName);
|
|
212
465
|
}
|
|
213
466
|
|
|
214
467
|
isStackRoot(sceneId: string) {
|
|
215
|
-
return
|
|
216
|
-
NativeNavigation.isStackRoot(sceneId, (_, result) => {
|
|
217
|
-
resolve(result);
|
|
218
|
-
});
|
|
219
|
-
});
|
|
468
|
+
return NativeNavigation.isStackRoot(sceneId);
|
|
220
469
|
}
|
|
221
470
|
|
|
222
|
-
|
|
223
|
-
NativeNavigation.
|
|
471
|
+
currentRoute(): Promise<Route | null> {
|
|
472
|
+
return NativeNavigation.currentRoute();
|
|
224
473
|
}
|
|
225
474
|
|
|
226
|
-
|
|
227
|
-
return
|
|
228
|
-
NativeNavigation.currentRoute((_, route) => {
|
|
229
|
-
resolve(route);
|
|
230
|
-
});
|
|
231
|
-
});
|
|
475
|
+
routeGraph(): Promise<RouteGraph[]> {
|
|
476
|
+
return NativeNavigation.routeGraph();
|
|
232
477
|
}
|
|
233
478
|
|
|
234
|
-
|
|
235
|
-
return
|
|
236
|
-
NativeNavigation.routeGraph((_, graph) => {
|
|
237
|
-
resolve(graph);
|
|
238
|
-
});
|
|
239
|
-
});
|
|
479
|
+
navigationSnapshot(): Promise<NavigationSnapshot> {
|
|
480
|
+
return NativeNavigation.navigationSnapshot();
|
|
240
481
|
}
|
|
241
482
|
|
|
242
483
|
setDefaultOptions(options: DefaultOptions) {
|
|
243
|
-
|
|
484
|
+
NativeNavigation.setDefaultOptions(options);
|
|
244
485
|
}
|
|
245
486
|
|
|
246
487
|
updateOptions(sceneId: string, options: NavigationOption) {
|
|
247
|
-
|
|
488
|
+
NativeNavigation.updateOptions(sceneId, options);
|
|
248
489
|
}
|
|
249
490
|
|
|
250
|
-
updateTabBar(
|
|
251
|
-
|
|
491
|
+
updateTabBar(options: TabBarStyle): void;
|
|
492
|
+
updateTabBar(sceneId: string, options: TabBarStyle): void;
|
|
493
|
+
updateTabBar(sceneIdOrOptions: string | TabBarStyle, options?: TabBarStyle) {
|
|
494
|
+
if (typeof sceneIdOrOptions === 'string') {
|
|
495
|
+
NativeNavigation.updateTabBar(sceneIdOrOptions, options ?? {});
|
|
496
|
+
} else {
|
|
497
|
+
NativeNavigation.updateTabBar('', sceneIdOrOptions);
|
|
498
|
+
}
|
|
252
499
|
}
|
|
253
500
|
|
|
254
|
-
setTabItem(
|
|
255
|
-
|
|
256
|
-
|
|
501
|
+
setTabItem(item: TabItemInfo | TabItemInfo[]): void;
|
|
502
|
+
setTabItem(sceneId: string, item: TabItemInfo | TabItemInfo[]): void;
|
|
503
|
+
setTabItem(
|
|
504
|
+
sceneIdOrItem: string | TabItemInfo | TabItemInfo[],
|
|
505
|
+
item?: TabItemInfo | TabItemInfo[],
|
|
506
|
+
) {
|
|
507
|
+
if (typeof sceneIdOrItem === 'string') {
|
|
508
|
+
const items = Array.isArray(item) ? item : item ? [item] : [];
|
|
509
|
+
if (items.length > 0) {
|
|
510
|
+
NativeNavigation.setTabItem(sceneIdOrItem, items);
|
|
511
|
+
}
|
|
512
|
+
} else {
|
|
513
|
+
const items = Array.isArray(sceneIdOrItem) ? sceneIdOrItem : [sceneIdOrItem];
|
|
514
|
+
NativeNavigation.setTabItem('', items);
|
|
257
515
|
}
|
|
258
|
-
NativeGarden.setTabItem(sceneId, item);
|
|
259
516
|
}
|
|
260
517
|
|
|
261
518
|
setMenuInteractive(sceneId: string, enabled: boolean) {
|
|
262
|
-
|
|
519
|
+
return this.dispatch(sceneId, 'setMenuInteractive', { enabled });
|
|
263
520
|
}
|
|
264
521
|
}
|
|
265
522
|
|
|
@@ -1,12 +1,24 @@
|
|
|
1
1
|
import React, { useEffect } from 'react';
|
|
2
2
|
import type { NavigationItem } from './Options';
|
|
3
|
+
import type {
|
|
4
|
+
HasTypedRoutes,
|
|
5
|
+
InitialMetrics,
|
|
6
|
+
RegisteredRouteName,
|
|
7
|
+
RouteName,
|
|
8
|
+
RoutePropsOf,
|
|
9
|
+
} from './Route';
|
|
3
10
|
import { Navigator, NavigationContext } from './Navigator';
|
|
4
|
-
import
|
|
11
|
+
import NativeNavigation from './NativeNavigation';
|
|
5
12
|
|
|
6
|
-
export
|
|
7
|
-
|
|
13
|
+
export type NavigationProps<Name extends RouteName = RouteName> = (HasTypedRoutes extends true
|
|
14
|
+
? [Name] extends [RegisteredRouteName]
|
|
15
|
+
? RoutePropsOf<Name>
|
|
16
|
+
: Record<string, any>
|
|
17
|
+
: Record<string, any>) & {
|
|
18
|
+
navigator: Navigator<Name>;
|
|
8
19
|
sceneId: string;
|
|
9
|
-
|
|
20
|
+
initialMetrics?: InitialMetrics;
|
|
21
|
+
};
|
|
10
22
|
|
|
11
23
|
interface NativeProps {
|
|
12
24
|
sceneId: string;
|
|
@@ -28,10 +40,7 @@ export function withNavigation(moduleName: string) {
|
|
|
28
40
|
}
|
|
29
41
|
|
|
30
42
|
useEffect(() => {
|
|
31
|
-
|
|
32
|
-
return () => {
|
|
33
|
-
Navigator.unmount(sceneId);
|
|
34
|
-
};
|
|
43
|
+
NativeNavigation.signalFirstRenderComplete(sceneId);
|
|
35
44
|
}, [sceneId]);
|
|
36
45
|
|
|
37
46
|
const injected = {
|
|
@@ -53,7 +62,7 @@ export function withNavigation(moduleName: string) {
|
|
|
53
62
|
|
|
54
63
|
export function withNavigationItem(item: NavigationItem) {
|
|
55
64
|
return function (WrappedComponent: React.ComponentType<any>): React.ComponentType<any> {
|
|
56
|
-
|
|
65
|
+
const navigationItem = (WrappedComponent as any).navigationItem;
|
|
57
66
|
if (navigationItem) {
|
|
58
67
|
(WrappedComponent as any).navigationItem = {
|
|
59
68
|
...navigationItem,
|