hybrid-navigation 4.1.0 → 5.0.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 +114 -23
- package/android/src/main/java/com/navigation/androidx/AwesomeFragment.java +115 -12
- 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 +11 -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 +8 -3
- package/android/src/main/java/com/navigation/androidx/StackDelegate.java +29 -9
- package/android/src/main/java/com/navigation/androidx/StackFragment.java +28 -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 +24 -7
- package/android/src/main/java/com/navigation/androidx/TabView.java +11 -2
- package/android/src/main/java/com/reactnative/hybridnavigation/DispatchResult.java +59 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/Garden.java +18 -10
- package/android/src/main/java/com/reactnative/hybridnavigation/GlobalStyle.java +15 -2
- package/android/src/main/java/com/reactnative/hybridnavigation/HBDRootView.java +3 -8
- package/android/src/main/java/com/reactnative/hybridnavigation/HybridFragment.java +113 -6
- 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 +196 -194
- package/android/src/main/java/com/reactnative/hybridnavigation/NavigationCommandQueue.java +499 -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 +50 -89
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactManager.java +156 -77
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactStackFragment.java +6 -6
- 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 +62 -22
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/StackNavigator.java +35 -16
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/TabNavigator.java +16 -13
- package/dist/DeepLink.d.ts +3 -2
- package/dist/DeepLink.js +37 -14
- package/dist/NativeEvent.d.ts +4 -12
- package/dist/NativeNavigation.d.ts +17 -19
- package/dist/Navigation.d.ts +21 -19
- package/dist/Navigation.js +83 -89
- package/dist/NavigationComponentWrap.d.ts +4 -3
- package/dist/NavigationComponentWrap.js +3 -6
- package/dist/Navigator.d.ts +31 -42
- package/dist/Navigator.js +97 -90
- package/dist/Options.d.ts +3 -1
- package/dist/Route.d.ts +85 -18
- package/dist/handler/DispatchCommandHandler.d.ts +10 -6
- package/dist/handler/DispatchCommandHandler.js +41 -17
- package/dist/handler/LayoutCommandHandler.d.ts +7 -7
- package/dist/handler/LayoutCommandHandler.js +21 -15
- package/dist/handler/LifecycleEventHandler.d.ts +26 -0
- package/dist/handler/LifecycleEventHandler.js +136 -0
- package/dist/handler/ResultEventHandler.d.ts +14 -9
- package/dist/handler/ResultEventHandler.js +88 -13
- package/dist/hooks.d.ts +5 -2
- package/dist/hooks.js +26 -4
- package/dist/index.d.ts +13 -0
- package/dist/index.js +0 -2
- package/dist/routeConfigRegistry.d.ts +6 -0
- package/dist/routeConfigRegistry.js +19 -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 +127 -43
- 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 +2 -2
- package/dist/router/tabs.js +4 -1
- package/dist/store.d.ts +2 -2
- package/ios/HBDGlobalStyle.h +26 -0
- package/ios/{GlobalStyle.mm → HBDGlobalStyle.mm} +30 -29
- package/ios/HybridNavigation.h +4 -1
- package/ios/Navigator/HBDDrawerNavigator.mm +24 -8
- package/ios/Navigator/HBDNavigatorRegistry.mm +1 -0
- package/ios/Navigator/HBDScreenNavigator.mm +106 -52
- package/ios/Navigator/HBDStackNavigator.mm +109 -61
- package/ios/Navigator/HBDTabNavigator.mm +32 -14
- package/ios/React/HBDNativeNavigation.mm +109 -131
- package/ios/React/HBDNavigator.h +29 -5
- package/ios/React/HBDOrientationCoordinator.h +27 -0
- package/ios/React/HBDOrientationCoordinator.mm +282 -0
- package/ios/React/HBDReactBridgeManager.h +36 -20
- package/ios/React/HBDReactBridgeManager.mm +450 -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 +17 -4
- package/ios/ViewController/HBDReactViewController.mm +59 -121
- package/ios/ViewController/HBDTabBarController.h +4 -0
- package/ios/ViewController/HBDTabBarController.mm +59 -44
- package/ios/ViewController/HBDViewController.h +10 -3
- package/ios/ViewController/HBDViewController.mm +161 -159
- package/ios/ViewController/UINavigationController+HBD.h +2 -2
- package/ios/ViewController/UINavigationController+HBD.mm +3 -3
- package/ios/ViewController/UIViewController+HBD.h +17 -10
- package/ios/ViewController/UIViewController+HBD.mm +85 -69
- package/package.json +1 -1
- package/src/DeepLink.ts +41 -14
- package/src/NativeEvent.ts +4 -14
- package/src/NativeNavigation.ts +22 -33
- package/src/Navigation.ts +162 -121
- package/src/NavigationComponentWrap.tsx +9 -9
- package/src/Navigator.ts +191 -153
- package/src/Options.ts +3 -1
- package/src/Route.ts +134 -19
- package/src/handler/DispatchCommandHandler.ts +55 -21
- package/src/handler/LayoutCommandHandler.ts +36 -17
- package/src/handler/LifecycleEventHandler.ts +172 -0
- package/src/handler/ResultEventHandler.ts +112 -19
- package/src/hooks.ts +39 -7
- package/src/index.ts +26 -2
- package/src/routeConfigRegistry.ts +26 -0
- package/src/router/drawer.ts +8 -5
- package/src/router/index.ts +161 -50
- package/src/router/screen.ts +3 -3
- package/src/router/stack.ts +80 -29
- package/src/router/tabs.ts +15 -7
- package/src/store.ts +1 -1
- 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,61 @@ 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
|
+
BuildInLayout,
|
|
7
|
+
DispatchResult,
|
|
8
|
+
Layout,
|
|
9
|
+
NavigationResult,
|
|
10
|
+
ResultMap,
|
|
11
|
+
Route,
|
|
12
|
+
RouteConfig,
|
|
13
|
+
RouteGraph,
|
|
14
|
+
RouteName,
|
|
15
|
+
SceneLifecycleState,
|
|
16
|
+
SetRootOptions,
|
|
17
|
+
} from './Route';
|
|
18
|
+
|
|
19
|
+
import { layoutHandler, RootLayoutListener } from './handler/LayoutCommandHandler';
|
|
20
|
+
import { dispatchHandler } from './handler/DispatchCommandHandler';
|
|
21
|
+
import {
|
|
22
|
+
RESULT_BLOCK,
|
|
23
|
+
RESULT_CANCEL,
|
|
24
|
+
RESULT_OK,
|
|
25
|
+
resultHandler,
|
|
26
|
+
} from './handler/ResultEventHandler';
|
|
27
|
+
import {
|
|
28
|
+
GlobalSceneLifecycleListener,
|
|
11
29
|
GlobalVisibilityEventListener,
|
|
30
|
+
lifecycleHandler,
|
|
31
|
+
SceneLifecycleListener,
|
|
12
32
|
VisibilityEventListener,
|
|
13
|
-
} from './handler/
|
|
33
|
+
} from './handler/LifecycleEventHandler';
|
|
14
34
|
|
|
15
|
-
import NativeEvent from './NativeEvent';
|
|
16
35
|
import NativeNavigation from './NativeNavigation';
|
|
17
|
-
import
|
|
36
|
+
import store from './store';
|
|
37
|
+
import { withNavigation } from './NavigationComponentWrap';
|
|
38
|
+
import {
|
|
39
|
+
bumpRouteConfigVersion,
|
|
40
|
+
clearRouteConfigs,
|
|
41
|
+
setRouteConfig,
|
|
42
|
+
} from './routeConfigRegistry';
|
|
18
43
|
|
|
19
44
|
export type { ResultType } from './handler/ResultEventHandler';
|
|
20
45
|
import type { DispatchParams, NavigationInterceptor } from './handler/DispatchCommandHandler';
|
|
21
|
-
export type {
|
|
46
|
+
export type {
|
|
47
|
+
DispatchParams,
|
|
48
|
+
InterceptParams,
|
|
49
|
+
NavigationInterceptor,
|
|
50
|
+
} from './handler/DispatchCommandHandler';
|
|
51
|
+
export type {
|
|
52
|
+
GlobalSceneLifecycleListener,
|
|
53
|
+
GlobalVisibilityEventListener,
|
|
54
|
+
SceneLifecycleListener,
|
|
55
|
+
VisibilityEventListener,
|
|
56
|
+
} from './handler/LifecycleEventHandler';
|
|
57
|
+
export type { RootLayoutListener } from './handler/LayoutCommandHandler';
|
|
22
58
|
|
|
23
|
-
export
|
|
59
|
+
export { RESULT_CANCEL, RESULT_OK, RESULT_BLOCK };
|
|
24
60
|
|
|
25
61
|
export type NavigationSubscription = {
|
|
26
62
|
remove: () => void;
|
|
@@ -31,14 +67,15 @@ export type HOC = (WrappedComponent: React.ComponentType<any>) => React.Componen
|
|
|
31
67
|
export interface Navigation {
|
|
32
68
|
startRegisterComponent(hoc?: HOC): void;
|
|
33
69
|
endRegisterComponent(): void;
|
|
34
|
-
registerComponent(
|
|
35
|
-
appKey:
|
|
70
|
+
registerComponent<Name extends RouteName = RouteName>(
|
|
71
|
+
appKey: Name,
|
|
36
72
|
getComponentFunc: ComponentProvider,
|
|
37
73
|
routeConfig?: RouteConfig,
|
|
38
74
|
): void;
|
|
39
75
|
|
|
40
|
-
|
|
41
|
-
|
|
76
|
+
addLifecycleListener(sceneId: string, listener: SceneLifecycleListener): NavigationSubscription;
|
|
77
|
+
addGlobalLifecycleListener(listener: GlobalSceneLifecycleListener): NavigationSubscription;
|
|
78
|
+
getSceneState(sceneId: string): SceneLifecycleState;
|
|
42
79
|
addGlobalVisibilityEventListener(
|
|
43
80
|
listener: GlobalVisibilityEventListener,
|
|
44
81
|
): NavigationSubscription;
|
|
@@ -46,46 +83,53 @@ export interface Navigation {
|
|
|
46
83
|
sceneId: string,
|
|
47
84
|
listener: VisibilityEventListener,
|
|
48
85
|
): NavigationSubscription;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
86
|
+
|
|
87
|
+
dispatch(sceneId: string, action: string, params?: DispatchParams): Promise<DispatchResult>;
|
|
88
|
+
addInterceptor(interceptor: NavigationInterceptor): NavigationSubscription;
|
|
89
|
+
setResult<T extends ResultMap = ResultMap>(
|
|
90
|
+
sceneId: string,
|
|
91
|
+
resultCode: number,
|
|
92
|
+
data?: T | null,
|
|
93
|
+
): void;
|
|
94
|
+
result<T = unknown>(sceneId: string, requestCode: number): Promise<NavigationResult<T>>;
|
|
95
|
+
setRoot(layout: BuildInLayout | Layout, options?: SetRootOptions): Promise<DispatchResult>;
|
|
96
|
+
addRootLayoutUpdateListener(
|
|
97
|
+
willSetRoot?: RootLayoutListener,
|
|
98
|
+
didSetRoot?: RootLayoutListener,
|
|
99
|
+
): NavigationSubscription;
|
|
100
|
+
|
|
56
101
|
currentTab(sceneId: string): Promise<number>;
|
|
57
|
-
findSceneIdByModuleName(moduleName:
|
|
102
|
+
findSceneIdByModuleName(moduleName: RouteName): Promise<string | null>;
|
|
58
103
|
isStackRoot(sceneId: string): Promise<boolean>;
|
|
59
|
-
|
|
60
|
-
currentRoute(): Promise<Route>;
|
|
104
|
+
currentRoute(): Promise<Route | null>;
|
|
61
105
|
routeGraph(): Promise<RouteGraph[]>;
|
|
106
|
+
|
|
62
107
|
setDefaultOptions(options: DefaultOptions): void;
|
|
63
108
|
updateOptions(sceneId: string, options: NavigationOption): void;
|
|
64
109
|
updateTabBar(sceneId: string, options: TabBarStyle): void;
|
|
65
110
|
setTabItem(sceneId: string, item: TabItemInfo | TabItemInfo[]): void;
|
|
66
|
-
setMenuInteractive(sceneId: string, enabled: boolean):
|
|
111
|
+
setMenuInteractive(sceneId: string, enabled: boolean): Promise<DispatchResult>;
|
|
67
112
|
}
|
|
68
113
|
|
|
69
114
|
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
115
|
constructor() {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
116
|
+
layoutHandler.handleRootLayoutChange(() => {
|
|
117
|
+
resultHandler.invalidateAll('root_reset');
|
|
118
|
+
});
|
|
119
|
+
lifecycleHandler.handleSceneLifecycle(sceneId => {
|
|
120
|
+
resultHandler.invalidateResultEventListener(sceneId, 'unmounted');
|
|
121
|
+
store.removeNavigator(sceneId);
|
|
122
|
+
});
|
|
123
|
+
resultHandler.handleComponentResult();
|
|
80
124
|
}
|
|
81
125
|
|
|
82
|
-
private wrap?: (moduleName: string) => HOC;
|
|
83
126
|
private hoc?: HOC;
|
|
84
127
|
private registerEnded = false;
|
|
85
128
|
|
|
86
129
|
startRegisterComponent(hoc?: HOC) {
|
|
87
130
|
this.hoc = hoc;
|
|
88
131
|
this.registerEnded = false;
|
|
132
|
+
clearRouteConfigs();
|
|
89
133
|
NativeNavigation.startRegisterReactComponent();
|
|
90
134
|
}
|
|
91
135
|
|
|
@@ -95,50 +139,81 @@ class NavigationImpl implements Navigation {
|
|
|
95
139
|
return;
|
|
96
140
|
}
|
|
97
141
|
this.registerEnded = true;
|
|
142
|
+
bumpRouteConfigVersion();
|
|
98
143
|
NativeNavigation.endRegisterReactComponent();
|
|
99
144
|
}
|
|
100
145
|
|
|
101
|
-
registerComponent(
|
|
102
|
-
appKey:
|
|
146
|
+
registerComponent<Name extends RouteName = RouteName>(
|
|
147
|
+
appKey: Name,
|
|
103
148
|
getComponentFunc: ComponentProvider,
|
|
104
149
|
routeConfig?: RouteConfig,
|
|
105
150
|
) {
|
|
106
|
-
if (routeConfig) {
|
|
107
|
-
|
|
151
|
+
if (routeConfig && (routeConfig.path || routeConfig.dependency || routeConfig.mode)) {
|
|
152
|
+
setRouteConfig(appKey, routeConfig);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const hoc = this.hoc;
|
|
156
|
+
|
|
157
|
+
if (routeConfig?.options !== undefined || routeConfig?.lazy === true) {
|
|
158
|
+
NativeNavigation.registerReactComponent(appKey, routeConfig.options ?? {});
|
|
159
|
+
let CachedRootComponent: React.ComponentType<any> | undefined;
|
|
160
|
+
AppRegistry.registerComponent(appKey, () => {
|
|
161
|
+
if (!CachedRootComponent) {
|
|
162
|
+
let WrappedComponent = getComponentFunc();
|
|
163
|
+
if (__DEV__ && (WrappedComponent as any)?.navigationItem) {
|
|
164
|
+
console.warn(
|
|
165
|
+
`[hybrid-navigation] "${appKey}" enabled lazy registration via registerComponent(), so withNavigationItem() on the component is ignored.`,
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
if (hoc) {
|
|
169
|
+
WrappedComponent = hoc(WrappedComponent);
|
|
170
|
+
}
|
|
171
|
+
CachedRootComponent = withNavigation(appKey)(WrappedComponent);
|
|
172
|
+
}
|
|
173
|
+
return CachedRootComponent;
|
|
174
|
+
});
|
|
175
|
+
return;
|
|
108
176
|
}
|
|
109
177
|
|
|
110
178
|
let WrappedComponent = getComponentFunc();
|
|
111
|
-
if (
|
|
112
|
-
WrappedComponent =
|
|
179
|
+
if (hoc) {
|
|
180
|
+
WrappedComponent = hoc(WrappedComponent);
|
|
113
181
|
}
|
|
114
182
|
|
|
115
183
|
const options: object = (WrappedComponent as any).navigationItem || {};
|
|
116
184
|
NativeNavigation.registerReactComponent(appKey, options);
|
|
117
185
|
|
|
118
|
-
|
|
186
|
+
const RootComponent = withNavigation(appKey)(WrappedComponent);
|
|
119
187
|
AppRegistry.registerComponent(appKey, () => RootComponent);
|
|
120
188
|
}
|
|
121
189
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
190
|
+
addLifecycleListener(
|
|
191
|
+
sceneId: string,
|
|
192
|
+
listener: SceneLifecycleListener,
|
|
193
|
+
): NavigationSubscription {
|
|
194
|
+
lifecycleHandler.addLifecycleListener(sceneId, listener);
|
|
195
|
+
return {
|
|
196
|
+
remove: () => lifecycleHandler.removeLifecycleListener(sceneId, listener),
|
|
197
|
+
};
|
|
126
198
|
}
|
|
127
199
|
|
|
128
|
-
|
|
129
|
-
|
|
200
|
+
addGlobalLifecycleListener(listener: GlobalSceneLifecycleListener): NavigationSubscription {
|
|
201
|
+
lifecycleHandler.addGlobalLifecycleListener(listener);
|
|
202
|
+
return {
|
|
203
|
+
remove: () => lifecycleHandler.removeGlobalLifecycleListener(listener),
|
|
204
|
+
};
|
|
130
205
|
}
|
|
131
206
|
|
|
132
|
-
|
|
133
|
-
|
|
207
|
+
getSceneState(sceneId: string): SceneLifecycleState {
|
|
208
|
+
return lifecycleHandler.getSceneState(sceneId);
|
|
134
209
|
}
|
|
135
210
|
|
|
136
211
|
addGlobalVisibilityEventListener(
|
|
137
212
|
listener: GlobalVisibilityEventListener,
|
|
138
213
|
): NavigationSubscription {
|
|
139
|
-
|
|
214
|
+
lifecycleHandler.addGlobalVisibilityEventListener(listener);
|
|
140
215
|
return {
|
|
141
|
-
remove: () =>
|
|
216
|
+
remove: () => lifecycleHandler.removeGlobalVisibilityEventListener(listener),
|
|
142
217
|
};
|
|
143
218
|
}
|
|
144
219
|
|
|
@@ -146,120 +221,86 @@ class NavigationImpl implements Navigation {
|
|
|
146
221
|
sceneId: string,
|
|
147
222
|
listener: VisibilityEventListener,
|
|
148
223
|
): NavigationSubscription {
|
|
149
|
-
|
|
224
|
+
lifecycleHandler.addVisibilityEventListener(sceneId, listener);
|
|
150
225
|
return {
|
|
151
|
-
remove: () =>
|
|
226
|
+
remove: () => lifecycleHandler.removeVisibilityEventListener(sceneId, listener),
|
|
152
227
|
};
|
|
153
228
|
}
|
|
154
229
|
|
|
155
230
|
dispatch(sceneId: string, action: string, params: DispatchParams = {}) {
|
|
156
|
-
return
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
private handleTabSwitch() {
|
|
160
|
-
NativeEvent.onSwitchTab(({ sceneId, from, to }) => {
|
|
161
|
-
this.dispatch(sceneId, 'switchTab', { from, to });
|
|
162
|
-
});
|
|
231
|
+
return dispatchHandler.dispatch(sceneId, action, params);
|
|
163
232
|
}
|
|
164
233
|
|
|
165
|
-
|
|
166
|
-
|
|
234
|
+
addInterceptor(interceptor: NavigationInterceptor): NavigationSubscription {
|
|
235
|
+
dispatchHandler.addInterceptor(interceptor);
|
|
236
|
+
return {
|
|
237
|
+
remove: () => dispatchHandler.removeInterceptor(interceptor),
|
|
238
|
+
};
|
|
167
239
|
}
|
|
168
240
|
|
|
169
|
-
setResult = <T extends
|
|
241
|
+
setResult = <T extends ResultMap = ResultMap>(
|
|
170
242
|
sceneId: string,
|
|
171
243
|
resultCode: number,
|
|
172
|
-
data: T
|
|
244
|
+
data: T | null = null,
|
|
173
245
|
): 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);
|
|
246
|
+
resultHandler.setResult(sceneId, resultCode, data);
|
|
180
247
|
};
|
|
181
248
|
|
|
182
|
-
result<T
|
|
183
|
-
return
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
unmount(sceneId: string) {
|
|
187
|
-
this.resultHandler.invalidateResultEventListener(sceneId);
|
|
249
|
+
result<T = unknown>(sceneId: string, requestCode: number) {
|
|
250
|
+
return resultHandler.waitResult<T>(sceneId, requestCode);
|
|
188
251
|
}
|
|
189
252
|
|
|
190
|
-
setRoot(layout: BuildInLayout | Layout,
|
|
191
|
-
return
|
|
253
|
+
setRoot(layout: BuildInLayout | Layout, options?: SetRootOptions) {
|
|
254
|
+
return layoutHandler.setRoot(layout, options);
|
|
192
255
|
}
|
|
193
256
|
|
|
194
|
-
|
|
195
|
-
|
|
257
|
+
addRootLayoutUpdateListener(
|
|
258
|
+
willSetRoot?: RootLayoutListener,
|
|
259
|
+
didSetRoot?: RootLayoutListener,
|
|
260
|
+
): NavigationSubscription {
|
|
261
|
+
const remove = layoutHandler.addRootLayoutUpdateListener(willSetRoot, didSetRoot);
|
|
262
|
+
return { remove };
|
|
196
263
|
}
|
|
197
264
|
|
|
198
265
|
currentTab(sceneId: string) {
|
|
199
|
-
return
|
|
200
|
-
NativeNavigation.currentTab(sceneId, (_, index) => {
|
|
201
|
-
resolve(index);
|
|
202
|
-
});
|
|
203
|
-
});
|
|
266
|
+
return NativeNavigation.currentTab(sceneId);
|
|
204
267
|
}
|
|
205
268
|
|
|
206
|
-
findSceneIdByModuleName(moduleName:
|
|
207
|
-
return
|
|
208
|
-
NativeNavigation.findSceneIdByModuleName(moduleName, (_, sceneId) => {
|
|
209
|
-
resolve(sceneId);
|
|
210
|
-
});
|
|
211
|
-
});
|
|
269
|
+
findSceneIdByModuleName(moduleName: RouteName) {
|
|
270
|
+
return NativeNavigation.findSceneIdByModuleName(moduleName);
|
|
212
271
|
}
|
|
213
272
|
|
|
214
273
|
isStackRoot(sceneId: string) {
|
|
215
|
-
return
|
|
216
|
-
NativeNavigation.isStackRoot(sceneId, (_, result) => {
|
|
217
|
-
resolve(result);
|
|
218
|
-
});
|
|
219
|
-
});
|
|
274
|
+
return NativeNavigation.isStackRoot(sceneId);
|
|
220
275
|
}
|
|
221
276
|
|
|
222
|
-
|
|
223
|
-
NativeNavigation.
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
currentRoute(): Promise<Route> {
|
|
227
|
-
return new Promise<Route>(resolve => {
|
|
228
|
-
NativeNavigation.currentRoute((_, route) => {
|
|
229
|
-
resolve(route);
|
|
230
|
-
});
|
|
231
|
-
});
|
|
277
|
+
currentRoute(): Promise<Route | null> {
|
|
278
|
+
return NativeNavigation.currentRoute();
|
|
232
279
|
}
|
|
233
280
|
|
|
234
281
|
routeGraph(): Promise<RouteGraph[]> {
|
|
235
|
-
return
|
|
236
|
-
NativeNavigation.routeGraph((_, graph) => {
|
|
237
|
-
resolve(graph);
|
|
238
|
-
});
|
|
239
|
-
});
|
|
282
|
+
return NativeNavigation.routeGraph();
|
|
240
283
|
}
|
|
241
284
|
|
|
242
285
|
setDefaultOptions(options: DefaultOptions) {
|
|
243
|
-
|
|
286
|
+
NativeNavigation.setDefaultOptions(options);
|
|
244
287
|
}
|
|
245
288
|
|
|
246
289
|
updateOptions(sceneId: string, options: NavigationOption) {
|
|
247
|
-
|
|
290
|
+
NativeNavigation.updateOptions(sceneId, options);
|
|
248
291
|
}
|
|
249
292
|
|
|
250
293
|
updateTabBar(sceneId: string, options: TabBarStyle) {
|
|
251
|
-
|
|
294
|
+
NativeNavigation.updateTabBar(sceneId, options);
|
|
252
295
|
}
|
|
253
296
|
|
|
254
297
|
setTabItem(sceneId: string, item: TabItemInfo | TabItemInfo[]) {
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
}
|
|
258
|
-
NativeGarden.setTabItem(sceneId, item);
|
|
298
|
+
const items = Array.isArray(item) ? item : [item];
|
|
299
|
+
NativeNavigation.setTabItem(sceneId, items);
|
|
259
300
|
}
|
|
260
301
|
|
|
261
302
|
setMenuInteractive(sceneId: string, enabled: boolean) {
|
|
262
|
-
|
|
303
|
+
return this.dispatch(sceneId, 'setMenuInteractive', { enabled });
|
|
263
304
|
}
|
|
264
305
|
}
|
|
265
306
|
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import React, { useEffect } from 'react';
|
|
2
2
|
import type { NavigationItem } from './Options';
|
|
3
|
+
import type { HasTypedRoutes, RouteName, RoutePropsOf } from './Route';
|
|
3
4
|
import { Navigator, NavigationContext } from './Navigator';
|
|
4
|
-
import
|
|
5
|
+
import NativeNavigation from './NativeNavigation';
|
|
5
6
|
|
|
6
|
-
export
|
|
7
|
-
|
|
7
|
+
export type NavigationProps<Name extends RouteName = RouteName> = (HasTypedRoutes extends true
|
|
8
|
+
? RoutePropsOf<Name>
|
|
9
|
+
: Record<string, any>) & {
|
|
10
|
+
navigator: Navigator<Name>;
|
|
8
11
|
sceneId: string;
|
|
9
|
-
}
|
|
12
|
+
};
|
|
10
13
|
|
|
11
14
|
interface NativeProps {
|
|
12
15
|
sceneId: string;
|
|
@@ -28,10 +31,7 @@ export function withNavigation(moduleName: string) {
|
|
|
28
31
|
}
|
|
29
32
|
|
|
30
33
|
useEffect(() => {
|
|
31
|
-
|
|
32
|
-
return () => {
|
|
33
|
-
Navigator.unmount(sceneId);
|
|
34
|
-
};
|
|
34
|
+
NativeNavigation.signalFirstRenderComplete(sceneId);
|
|
35
35
|
}, [sceneId]);
|
|
36
36
|
|
|
37
37
|
const injected = {
|
|
@@ -53,7 +53,7 @@ export function withNavigation(moduleName: string) {
|
|
|
53
53
|
|
|
54
54
|
export function withNavigationItem(item: NavigationItem) {
|
|
55
55
|
return function (WrappedComponent: React.ComponentType<any>): React.ComponentType<any> {
|
|
56
|
-
|
|
56
|
+
const navigationItem = (WrappedComponent as any).navigationItem;
|
|
57
57
|
if (navigationItem) {
|
|
58
58
|
(WrappedComponent as any).navigationItem = {
|
|
59
59
|
...navigationItem,
|