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/dist/Navigation.js
CHANGED
|
@@ -1,29 +1,52 @@
|
|
|
1
1
|
import { AppRegistry } from 'react-native';
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
2
|
+
import { layoutHandler } from './handler/LayoutCommandHandler';
|
|
3
|
+
import { dispatchHandler } from './handler/DispatchCommandHandler';
|
|
4
|
+
import { leaveGuardHandler } from './handler/LeaveGuardHandler';
|
|
5
|
+
import { presentationCoordinator } from './handler/PresentationCoordinator';
|
|
6
|
+
import { tabEventHandler } from './handler/TabEventHandler';
|
|
7
|
+
import { executeReveal } from './reveal';
|
|
8
|
+
import { RESULT_BLOCK, RESULT_CANCEL, RESULT_OK, resultHandler, } from './handler/ResultEventHandler';
|
|
9
|
+
import { lifecycleHandler, } from './handler/LifecycleEventHandler';
|
|
7
10
|
import NativeNavigation from './NativeNavigation';
|
|
8
|
-
import
|
|
9
|
-
|
|
11
|
+
import store from './store';
|
|
12
|
+
import { withNavigation } from './NavigationComponentWrap';
|
|
13
|
+
import { bumpRouteConfigVersion, clearRouteConfigs, getRouteConfigs, setRouteConfig, } from './routeConfigRegistry';
|
|
14
|
+
export { RESULT_CANCEL, RESULT_OK, RESULT_BLOCK };
|
|
10
15
|
class NavigationImpl {
|
|
11
|
-
dispatchHandler = new DispatchCommandHandler();
|
|
12
|
-
resultHandler = new ResultEventHandler();
|
|
13
|
-
layoutHandler = new LayoutCommandHandler();
|
|
14
|
-
visibilityHandler = new VisibilityEventHandler();
|
|
15
16
|
constructor() {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
leaveGuardHandler.setDispatcher((sceneId, action, params) => dispatchHandler.dispatch(sceneId, action, params));
|
|
18
|
+
dispatchHandler.addMiddleware(leaveGuardHandler.middleware);
|
|
19
|
+
dispatchHandler.addMiddleware(dispatchHandler.interceptorMiddleware);
|
|
20
|
+
dispatchHandler.addMiddleware(presentationCoordinator.middleware);
|
|
21
|
+
layoutHandler.handleRootLayoutChange(() => {
|
|
22
|
+
lifecycleHandler.onRootReset();
|
|
23
|
+
leaveGuardHandler.onRootReset();
|
|
24
|
+
presentationCoordinator.onRootReset();
|
|
25
|
+
resultHandler.invalidateAll('root_reset');
|
|
26
|
+
});
|
|
27
|
+
lifecycleHandler.handleSceneLifecycle(sceneId => {
|
|
28
|
+
leaveGuardHandler.onSceneDestroyed(sceneId);
|
|
29
|
+
presentationCoordinator.onSceneDestroyed(sceneId);
|
|
30
|
+
resultHandler.invalidateResultEventListener(sceneId, 'unmounted');
|
|
31
|
+
store.removeNavigator(sceneId);
|
|
32
|
+
});
|
|
33
|
+
resultHandler.handleComponentResult();
|
|
34
|
+
leaveGuardHandler.handleNativeBeforeRemoveRequests();
|
|
35
|
+
tabEventHandler.handleTabPress();
|
|
20
36
|
}
|
|
21
|
-
wrap;
|
|
22
37
|
hoc;
|
|
23
38
|
registerEnded = false;
|
|
39
|
+
registeredNames = new Set();
|
|
40
|
+
registeredPaths = new Map();
|
|
41
|
+
routeLoaders = new Map();
|
|
42
|
+
revealQueue = Promise.resolve();
|
|
24
43
|
startRegisterComponent(hoc) {
|
|
25
44
|
this.hoc = hoc;
|
|
26
45
|
this.registerEnded = false;
|
|
46
|
+
this.registeredNames.clear();
|
|
47
|
+
this.registeredPaths.clear();
|
|
48
|
+
this.routeLoaders.clear();
|
|
49
|
+
clearRouteConfigs();
|
|
27
50
|
NativeNavigation.startRegisterReactComponent();
|
|
28
51
|
}
|
|
29
52
|
endRegisterComponent() {
|
|
@@ -32,127 +55,239 @@ class NavigationImpl {
|
|
|
32
55
|
return;
|
|
33
56
|
}
|
|
34
57
|
this.registerEnded = true;
|
|
58
|
+
if (__DEV__) {
|
|
59
|
+
this.validateRouteDependencies();
|
|
60
|
+
}
|
|
61
|
+
bumpRouteConfigVersion();
|
|
35
62
|
NativeNavigation.endRegisterReactComponent();
|
|
36
63
|
}
|
|
64
|
+
validateRouteDependencies() {
|
|
65
|
+
const configs = getRouteConfigs();
|
|
66
|
+
const state = new Map();
|
|
67
|
+
const stack = [];
|
|
68
|
+
const visit = (name) => {
|
|
69
|
+
state.set(name, 'visiting');
|
|
70
|
+
stack.push(name);
|
|
71
|
+
const dependency = configs.get(name)?.dependency;
|
|
72
|
+
if (dependency) {
|
|
73
|
+
const depState = state.get(dependency);
|
|
74
|
+
if (depState === 'visiting') {
|
|
75
|
+
const cycleStart = stack.indexOf(dependency);
|
|
76
|
+
const cycle = [...stack.slice(cycleStart), dependency].join(' -> ');
|
|
77
|
+
console.warn(`[hybrid-navigation] Circular route dependency detected: ${cycle}`);
|
|
78
|
+
}
|
|
79
|
+
else if (!depState && configs.has(dependency)) {
|
|
80
|
+
visit(dependency);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
stack.pop();
|
|
84
|
+
state.set(name, 'visited');
|
|
85
|
+
};
|
|
86
|
+
for (const name of configs.keys()) {
|
|
87
|
+
if (!state.has(name)) {
|
|
88
|
+
visit(name);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
37
92
|
registerComponent(appKey, getComponentFunc, routeConfig) {
|
|
38
|
-
if (
|
|
39
|
-
this.
|
|
93
|
+
if (__DEV__) {
|
|
94
|
+
if (this.registeredNames.has(appKey)) {
|
|
95
|
+
console.warn(`[hybrid-navigation] Duplicate route registration for "${appKey}". Later registration overrides earlier one.`);
|
|
96
|
+
}
|
|
97
|
+
if (routeConfig?.path) {
|
|
98
|
+
const existing = this.registeredPaths.get(routeConfig.path);
|
|
99
|
+
if (existing && existing !== appKey) {
|
|
100
|
+
console.warn(`[hybrid-navigation] Duplicate route path "${routeConfig.path}" registered by "${appKey}" and "${existing}".`);
|
|
101
|
+
}
|
|
102
|
+
this.registeredPaths.set(routeConfig.path, appKey);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
this.registeredNames.add(appKey);
|
|
106
|
+
if (routeConfig && (routeConfig.path || routeConfig.dependency || routeConfig.mode)) {
|
|
107
|
+
setRouteConfig(appKey, routeConfig);
|
|
108
|
+
}
|
|
109
|
+
const hoc = this.hoc;
|
|
110
|
+
const isLazy = routeConfig?.lazy === true;
|
|
111
|
+
if (isLazy) {
|
|
112
|
+
NativeNavigation.registerReactComponent(appKey, routeConfig?.options ?? {});
|
|
113
|
+
let CachedRootComponent;
|
|
114
|
+
const loader = () => {
|
|
115
|
+
if (!CachedRootComponent) {
|
|
116
|
+
let WrappedComponent = getComponentFunc();
|
|
117
|
+
if (__DEV__ && WrappedComponent?.navigationItem) {
|
|
118
|
+
console.warn(`[hybrid-navigation] "${appKey}" enabled lazy registration via registerComponent(), so withNavigationItem() on the component is ignored.`);
|
|
119
|
+
}
|
|
120
|
+
if (hoc) {
|
|
121
|
+
WrappedComponent = hoc(WrappedComponent);
|
|
122
|
+
}
|
|
123
|
+
CachedRootComponent = withNavigation(appKey)(WrappedComponent);
|
|
124
|
+
}
|
|
125
|
+
return CachedRootComponent;
|
|
126
|
+
};
|
|
127
|
+
this.routeLoaders.set(appKey, loader);
|
|
128
|
+
AppRegistry.registerComponent(appKey, loader);
|
|
129
|
+
return;
|
|
40
130
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
131
|
+
const RawComponent = getComponentFunc();
|
|
132
|
+
let WrappedComponent = RawComponent;
|
|
133
|
+
if (hoc) {
|
|
134
|
+
WrappedComponent = hoc(WrappedComponent);
|
|
44
135
|
}
|
|
45
|
-
const options =
|
|
136
|
+
const options = routeConfig?.options ??
|
|
137
|
+
RawComponent?.navigationItem ??
|
|
138
|
+
WrappedComponent?.navigationItem ??
|
|
139
|
+
{};
|
|
46
140
|
NativeNavigation.registerReactComponent(appKey, options);
|
|
47
|
-
|
|
141
|
+
const RootComponent = withNavigation(appKey)(WrappedComponent);
|
|
48
142
|
AppRegistry.registerComponent(appKey, () => RootComponent);
|
|
49
143
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
144
|
+
registerRoutes(routes) {
|
|
145
|
+
for (const route of routes) {
|
|
146
|
+
const hasConfig = route.path !== undefined ||
|
|
147
|
+
route.dependency !== undefined ||
|
|
148
|
+
route.mode !== undefined ||
|
|
149
|
+
route.options !== undefined ||
|
|
150
|
+
route.lazy !== undefined;
|
|
151
|
+
const config = hasConfig
|
|
152
|
+
? {
|
|
153
|
+
path: route.path,
|
|
154
|
+
dependency: route.dependency,
|
|
155
|
+
mode: route.mode,
|
|
156
|
+
options: route.options,
|
|
157
|
+
lazy: route.lazy,
|
|
158
|
+
}
|
|
159
|
+
: undefined;
|
|
160
|
+
this.registerComponent(route.name, route.load, config);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
preloadRoute(moduleName) {
|
|
164
|
+
const loader = this.routeLoaders.get(moduleName);
|
|
165
|
+
if (loader) {
|
|
166
|
+
loader();
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
addLifecycleListener(sceneId, listener) {
|
|
170
|
+
lifecycleHandler.addLifecycleListener(sceneId, listener);
|
|
171
|
+
return {
|
|
172
|
+
remove: () => lifecycleHandler.removeLifecycleListener(sceneId, listener),
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
addGlobalLifecycleListener(listener) {
|
|
176
|
+
lifecycleHandler.addGlobalLifecycleListener(listener);
|
|
177
|
+
return {
|
|
178
|
+
remove: () => lifecycleHandler.removeGlobalLifecycleListener(listener),
|
|
179
|
+
};
|
|
53
180
|
}
|
|
54
|
-
|
|
55
|
-
return
|
|
181
|
+
getSceneState(sceneId) {
|
|
182
|
+
return lifecycleHandler.getSceneState(sceneId);
|
|
56
183
|
}
|
|
57
|
-
|
|
58
|
-
|
|
184
|
+
getSceneInfo(sceneId) {
|
|
185
|
+
return lifecycleHandler.getSceneInfo(sceneId);
|
|
59
186
|
}
|
|
60
187
|
addGlobalVisibilityEventListener(listener) {
|
|
61
|
-
|
|
188
|
+
lifecycleHandler.addGlobalVisibilityEventListener(listener);
|
|
62
189
|
return {
|
|
63
|
-
remove: () =>
|
|
190
|
+
remove: () => lifecycleHandler.removeGlobalVisibilityEventListener(listener),
|
|
64
191
|
};
|
|
65
192
|
}
|
|
66
193
|
addVisibilityEventListener(sceneId, listener) {
|
|
67
|
-
|
|
194
|
+
lifecycleHandler.addVisibilityEventListener(sceneId, listener);
|
|
68
195
|
return {
|
|
69
|
-
remove: () =>
|
|
196
|
+
remove: () => lifecycleHandler.removeVisibilityEventListener(sceneId, listener),
|
|
70
197
|
};
|
|
71
198
|
}
|
|
199
|
+
addTabPressListener(listener) {
|
|
200
|
+
const remove = tabEventHandler.addListener(listener);
|
|
201
|
+
return { remove };
|
|
202
|
+
}
|
|
72
203
|
dispatch(sceneId, action, params = {}) {
|
|
73
|
-
return
|
|
204
|
+
return dispatchHandler.dispatch(sceneId, action, params);
|
|
205
|
+
}
|
|
206
|
+
addInterceptor(interceptor) {
|
|
207
|
+
dispatchHandler.addInterceptor(interceptor);
|
|
208
|
+
return {
|
|
209
|
+
remove: () => dispatchHandler.removeInterceptor(interceptor),
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
registerSceneExitHandler(sceneId, handler) {
|
|
213
|
+
const remove = presentationCoordinator.registerExitHandler(sceneId, handler);
|
|
214
|
+
return { remove };
|
|
74
215
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
216
|
+
addBeforeRemoveListener(sceneId, listener, options) {
|
|
217
|
+
const remove = leaveGuardHandler.addListener(sceneId, listener, options);
|
|
218
|
+
return { remove };
|
|
219
|
+
}
|
|
220
|
+
closeScene(sceneId, options) {
|
|
221
|
+
return this.dispatch(sceneId, 'close', {
|
|
222
|
+
target: 'self',
|
|
223
|
+
onCovered: options?.onCovered,
|
|
224
|
+
...(options?.result !== undefined ? { result: options.result } : {}),
|
|
78
225
|
});
|
|
79
226
|
}
|
|
80
|
-
|
|
81
|
-
this.
|
|
227
|
+
reveal(target, options) {
|
|
228
|
+
const task = this.revealQueue.then(() => executeReveal(this, target, options), () => executeReveal(this, target, options));
|
|
229
|
+
this.revealQueue = task.then(() => undefined, () => undefined);
|
|
230
|
+
return task;
|
|
82
231
|
}
|
|
83
232
|
setResult = (sceneId, resultCode, data = null) => {
|
|
84
|
-
|
|
85
|
-
console.warn('`resultCode` can only be `RESULT_OK`, `RESULT_CANCEL` or an integer greater than 0.');
|
|
86
|
-
}
|
|
87
|
-
NativeNavigation.setResult(sceneId, resultCode, data);
|
|
233
|
+
resultHandler.setResult(sceneId, resultCode, data);
|
|
88
234
|
};
|
|
89
|
-
result(sceneId,
|
|
90
|
-
return
|
|
235
|
+
result(sceneId, requestCode) {
|
|
236
|
+
return resultHandler.waitResult(sceneId, requestCode);
|
|
91
237
|
}
|
|
92
|
-
|
|
93
|
-
|
|
238
|
+
setRoot(layout, options) {
|
|
239
|
+
return layoutHandler.setRoot(layout, options);
|
|
94
240
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
setRootLayoutUpdateListener(willSetRoot = () => { }, didSetRoot = () => { }) {
|
|
99
|
-
this.layoutHandler.setRootLayoutUpdateListener(willSetRoot, didSetRoot);
|
|
241
|
+
addRootLayoutUpdateListener(willSetRoot, didSetRoot) {
|
|
242
|
+
const remove = layoutHandler.addRootLayoutUpdateListener(willSetRoot, didSetRoot);
|
|
243
|
+
return { remove };
|
|
100
244
|
}
|
|
101
245
|
currentTab(sceneId) {
|
|
102
|
-
return
|
|
103
|
-
NativeNavigation.currentTab(sceneId, (_, index) => {
|
|
104
|
-
resolve(index);
|
|
105
|
-
});
|
|
106
|
-
});
|
|
246
|
+
return NativeNavigation.currentTab(sceneId);
|
|
107
247
|
}
|
|
108
248
|
findSceneIdByModuleName(moduleName) {
|
|
109
|
-
return
|
|
110
|
-
NativeNavigation.findSceneIdByModuleName(moduleName, (_, sceneId) => {
|
|
111
|
-
resolve(sceneId);
|
|
112
|
-
});
|
|
113
|
-
});
|
|
249
|
+
return NativeNavigation.findSceneIdByModuleName(moduleName);
|
|
114
250
|
}
|
|
115
251
|
isStackRoot(sceneId) {
|
|
116
|
-
return
|
|
117
|
-
NativeNavigation.isStackRoot(sceneId, (_, result) => {
|
|
118
|
-
resolve(result);
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
signalFirstRenderComplete(sceneId) {
|
|
123
|
-
NativeNavigation.signalFirstRenderComplete(sceneId);
|
|
252
|
+
return NativeNavigation.isStackRoot(sceneId);
|
|
124
253
|
}
|
|
125
254
|
currentRoute() {
|
|
126
|
-
return
|
|
127
|
-
NativeNavigation.currentRoute((_, route) => {
|
|
128
|
-
resolve(route);
|
|
129
|
-
});
|
|
130
|
-
});
|
|
255
|
+
return NativeNavigation.currentRoute();
|
|
131
256
|
}
|
|
132
257
|
routeGraph() {
|
|
133
|
-
return
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
});
|
|
258
|
+
return NativeNavigation.routeGraph();
|
|
259
|
+
}
|
|
260
|
+
navigationSnapshot() {
|
|
261
|
+
return NativeNavigation.navigationSnapshot();
|
|
138
262
|
}
|
|
139
263
|
setDefaultOptions(options) {
|
|
140
|
-
|
|
264
|
+
NativeNavigation.setDefaultOptions(options);
|
|
141
265
|
}
|
|
142
266
|
updateOptions(sceneId, options) {
|
|
143
|
-
|
|
267
|
+
NativeNavigation.updateOptions(sceneId, options);
|
|
144
268
|
}
|
|
145
|
-
updateTabBar(
|
|
146
|
-
|
|
269
|
+
updateTabBar(sceneIdOrOptions, options) {
|
|
270
|
+
if (typeof sceneIdOrOptions === 'string') {
|
|
271
|
+
NativeNavigation.updateTabBar(sceneIdOrOptions, options ?? {});
|
|
272
|
+
}
|
|
273
|
+
else {
|
|
274
|
+
NativeNavigation.updateTabBar('', sceneIdOrOptions);
|
|
275
|
+
}
|
|
147
276
|
}
|
|
148
|
-
setTabItem(
|
|
149
|
-
if (
|
|
150
|
-
|
|
277
|
+
setTabItem(sceneIdOrItem, item) {
|
|
278
|
+
if (typeof sceneIdOrItem === 'string') {
|
|
279
|
+
const items = Array.isArray(item) ? item : item ? [item] : [];
|
|
280
|
+
if (items.length > 0) {
|
|
281
|
+
NativeNavigation.setTabItem(sceneIdOrItem, items);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
else {
|
|
285
|
+
const items = Array.isArray(sceneIdOrItem) ? sceneIdOrItem : [sceneIdOrItem];
|
|
286
|
+
NativeNavigation.setTabItem('', items);
|
|
151
287
|
}
|
|
152
|
-
NativeGarden.setTabItem(sceneId, item);
|
|
153
288
|
}
|
|
154
289
|
setMenuInteractive(sceneId, enabled) {
|
|
155
|
-
|
|
290
|
+
return this.dispatch(sceneId, 'setMenuInteractive', { enabled });
|
|
156
291
|
}
|
|
157
292
|
}
|
|
158
293
|
export default new NavigationImpl();
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { NavigationItem } from './Options';
|
|
3
|
+
import type { HasTypedRoutes, InitialMetrics, RegisteredRouteName, RouteName, RoutePropsOf } from './Route';
|
|
3
4
|
import { Navigator } from './Navigator';
|
|
4
|
-
export
|
|
5
|
-
navigator: Navigator
|
|
5
|
+
export type NavigationProps<Name extends RouteName = RouteName> = (HasTypedRoutes extends true ? [Name] extends [RegisteredRouteName] ? RoutePropsOf<Name> : Record<string, any> : Record<string, any>) & {
|
|
6
|
+
navigator: Navigator<Name>;
|
|
6
7
|
sceneId: string;
|
|
7
|
-
|
|
8
|
+
initialMetrics?: InitialMetrics;
|
|
9
|
+
};
|
|
8
10
|
interface NativeProps {
|
|
9
11
|
sceneId: string;
|
|
10
12
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { useEffect } from 'react';
|
|
2
2
|
import { Navigator, NavigationContext } from './Navigator';
|
|
3
|
-
import
|
|
3
|
+
import NativeNavigation from './NativeNavigation';
|
|
4
4
|
function getDisplayName(WrappedComponent) {
|
|
5
5
|
return WrappedComponent.displayName || WrappedComponent.name || 'Component';
|
|
6
6
|
}
|
|
@@ -13,10 +13,7 @@ export function withNavigation(moduleName) {
|
|
|
13
13
|
navigator.moduleName = moduleName;
|
|
14
14
|
}
|
|
15
15
|
useEffect(() => {
|
|
16
|
-
|
|
17
|
-
return () => {
|
|
18
|
-
Navigator.unmount(sceneId);
|
|
19
|
-
};
|
|
16
|
+
NativeNavigation.signalFirstRenderComplete(sceneId);
|
|
20
17
|
}, [sceneId]);
|
|
21
18
|
const injected = {
|
|
22
19
|
navigator,
|
|
@@ -31,7 +28,7 @@ export function withNavigation(moduleName) {
|
|
|
31
28
|
}
|
|
32
29
|
export function withNavigationItem(item) {
|
|
33
30
|
return function (WrappedComponent) {
|
|
34
|
-
|
|
31
|
+
const navigationItem = WrappedComponent.navigationItem;
|
|
35
32
|
if (navigationItem) {
|
|
36
33
|
WrappedComponent.navigationItem = {
|
|
37
34
|
...navigationItem,
|
package/dist/Navigator.d.ts
CHANGED
|
@@ -1,47 +1,37 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
export declare
|
|
5
|
-
interface NavigationState {
|
|
6
|
-
params: {
|
|
7
|
-
readonly [index: string]: any;
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
interface PropsType {
|
|
11
|
-
[index: string]: any;
|
|
12
|
-
}
|
|
13
|
-
export interface Navigator {
|
|
14
|
-
}
|
|
15
|
-
export declare class Navigator implements Navigator {
|
|
1
|
+
import type { NavigationOption, TabBarStyle, TabItemInfo } from './Options';
|
|
2
|
+
import type { BuildInLayout, CloseSelfOptions, DispatchResult, Layout, NavigationResult, RouteName, RouteResultOf, SceneLifecycleState, ScreenPropsArgs, SetResultData, Visibility } from './Route';
|
|
3
|
+
export declare const NavigationContext: import("react").Context<Navigator<any> | null>;
|
|
4
|
+
export declare class Navigator<CurrentRoute extends RouteName = RouteName> {
|
|
16
5
|
sceneId: string;
|
|
17
6
|
moduleName?: string | undefined;
|
|
18
|
-
static of(sceneId: string): Navigator
|
|
19
|
-
static
|
|
20
|
-
static
|
|
21
|
-
static current(): Promise<Navigator>;
|
|
7
|
+
static of<Name extends RouteName = RouteName>(sceneId: string): Navigator<Name>;
|
|
8
|
+
static find<Name extends RouteName = RouteName>(moduleName: Name): Promise<Navigator<Name> | undefined>;
|
|
9
|
+
static current(): Promise<Navigator | undefined>;
|
|
22
10
|
constructor(sceneId: string, moduleName?: string | undefined);
|
|
23
|
-
visibility: Visibility;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
11
|
+
get visibility(): Visibility;
|
|
12
|
+
get lifecycleState(): SceneLifecycleState;
|
|
13
|
+
private dispatchForResult;
|
|
14
|
+
push: <Name extends RouteName = RouteName, T = RouteResultOf<Name>>(moduleName: Name, ...args: ScreenPropsArgs<Name>) => Promise<NavigationResult<T>>;
|
|
15
|
+
pushLayout: <T = unknown>(layout: BuildInLayout | Layout) => Promise<NavigationResult<T>>;
|
|
16
|
+
pop: () => Promise<DispatchResult>;
|
|
17
|
+
popTo: (moduleName: RouteName | (string & {}), inclusive?: boolean) => Promise<DispatchResult>;
|
|
18
|
+
popToRoot: () => Promise<DispatchResult>;
|
|
19
|
+
redirectTo: <Name extends RouteName = RouteName>(moduleName: Name, ...args: ScreenPropsArgs<Name>) => Promise<DispatchResult>;
|
|
20
|
+
present: <Name extends RouteName = RouteName, T = RouteResultOf<Name>>(moduleName: Name, ...args: ScreenPropsArgs<Name>) => Promise<NavigationResult<T>>;
|
|
21
|
+
presentLayout: <T = unknown>(layout: BuildInLayout | Layout) => Promise<NavigationResult<T>>;
|
|
22
|
+
dismiss: () => Promise<DispatchResult>;
|
|
23
|
+
closeSelf: (options?: CloseSelfOptions<SetResultData<CurrentRoute>>) => Promise<DispatchResult>;
|
|
24
|
+
showModal: <Name extends RouteName = RouteName, T = RouteResultOf<Name>>(moduleName: Name, ...args: ScreenPropsArgs<Name>) => Promise<NavigationResult<T>>;
|
|
25
|
+
showModalLayout: <T = unknown>(layout: BuildInLayout | Layout) => Promise<NavigationResult<T>>;
|
|
26
|
+
hideModal: () => Promise<DispatchResult>;
|
|
27
|
+
setResult: (resultCode: number, data?: SetResultData<CurrentRoute> | null) => void;
|
|
28
|
+
switchTab: (target: number | string, popToRoot?: boolean) => Promise<DispatchResult>;
|
|
29
|
+
toggleMenu: () => Promise<DispatchResult>;
|
|
30
|
+
openMenu: () => Promise<DispatchResult>;
|
|
31
|
+
closeMenu: () => Promise<DispatchResult>;
|
|
32
|
+
setMenuInteractive: (enabled: boolean) => Promise<DispatchResult>;
|
|
33
|
+
updateOptions: (options: NavigationOption) => void;
|
|
34
|
+
updateTabBar: (options: TabBarStyle) => void;
|
|
35
|
+
setTabItem: (item: TabItemInfo | TabItemInfo[]) => void;
|
|
45
36
|
isStackRoot: () => Promise<boolean>;
|
|
46
37
|
}
|
|
47
|
-
export {};
|