hybrid-navigation 4.0.8 → 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 +5 -4
- package/android/proguard-rules.pro +3 -0
- package/android/src/main/java/com/navigation/androidx/AwesomeActivity.java +114 -23
- package/android/src/main/java/com/navigation/androidx/AwesomeFragment.java +116 -13
- package/android/src/main/java/com/navigation/androidx/DrawableUtils.java +83 -18
- package/android/src/main/java/com/navigation/androidx/DrawerFragment.java +192 -28
- 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 +47 -15
- 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 -87
- 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/ReactSurfaceCleanup.java +3 -1
- 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 -27
- 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 +37 -19
- package/ios/React/HBDReactBridgeManager.mm +490 -96
- 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 +127 -6
- 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 -147
- 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/dist/Navigation.js
CHANGED
|
@@ -1,29 +1,30 @@
|
|
|
1
1
|
import { AppRegistry } from 'react-native';
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import NativeEvent from './NativeEvent';
|
|
2
|
+
import { layoutHandler } from './handler/LayoutCommandHandler';
|
|
3
|
+
import { dispatchHandler } from './handler/DispatchCommandHandler';
|
|
4
|
+
import { RESULT_BLOCK, RESULT_CANCEL, RESULT_OK, resultHandler, } from './handler/ResultEventHandler';
|
|
5
|
+
import { lifecycleHandler, } from './handler/LifecycleEventHandler';
|
|
7
6
|
import NativeNavigation from './NativeNavigation';
|
|
8
|
-
import
|
|
9
|
-
|
|
7
|
+
import store from './store';
|
|
8
|
+
import { withNavigation } from './NavigationComponentWrap';
|
|
9
|
+
import { bumpRouteConfigVersion, clearRouteConfigs, setRouteConfig, } from './routeConfigRegistry';
|
|
10
|
+
export { RESULT_CANCEL, RESULT_OK, RESULT_BLOCK };
|
|
10
11
|
class NavigationImpl {
|
|
11
|
-
dispatchHandler = new DispatchCommandHandler();
|
|
12
|
-
resultHandler = new ResultEventHandler();
|
|
13
|
-
layoutHandler = new LayoutCommandHandler();
|
|
14
|
-
visibilityHandler = new VisibilityEventHandler();
|
|
15
12
|
constructor() {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
13
|
+
layoutHandler.handleRootLayoutChange(() => {
|
|
14
|
+
resultHandler.invalidateAll('root_reset');
|
|
15
|
+
});
|
|
16
|
+
lifecycleHandler.handleSceneLifecycle(sceneId => {
|
|
17
|
+
resultHandler.invalidateResultEventListener(sceneId, 'unmounted');
|
|
18
|
+
store.removeNavigator(sceneId);
|
|
19
|
+
});
|
|
20
|
+
resultHandler.handleComponentResult();
|
|
20
21
|
}
|
|
21
|
-
wrap;
|
|
22
22
|
hoc;
|
|
23
23
|
registerEnded = false;
|
|
24
24
|
startRegisterComponent(hoc) {
|
|
25
25
|
this.hoc = hoc;
|
|
26
26
|
this.registerEnded = false;
|
|
27
|
+
clearRouteConfigs();
|
|
27
28
|
NativeNavigation.startRegisterReactComponent();
|
|
28
29
|
}
|
|
29
30
|
endRegisterComponent() {
|
|
@@ -32,127 +33,120 @@ class NavigationImpl {
|
|
|
32
33
|
return;
|
|
33
34
|
}
|
|
34
35
|
this.registerEnded = true;
|
|
36
|
+
bumpRouteConfigVersion();
|
|
35
37
|
NativeNavigation.endRegisterReactComponent();
|
|
36
38
|
}
|
|
37
39
|
registerComponent(appKey, getComponentFunc, routeConfig) {
|
|
38
|
-
if (routeConfig) {
|
|
39
|
-
|
|
40
|
+
if (routeConfig && (routeConfig.path || routeConfig.dependency || routeConfig.mode)) {
|
|
41
|
+
setRouteConfig(appKey, routeConfig);
|
|
42
|
+
}
|
|
43
|
+
const hoc = this.hoc;
|
|
44
|
+
if (routeConfig?.options !== undefined || routeConfig?.lazy === true) {
|
|
45
|
+
NativeNavigation.registerReactComponent(appKey, routeConfig.options ?? {});
|
|
46
|
+
let CachedRootComponent;
|
|
47
|
+
AppRegistry.registerComponent(appKey, () => {
|
|
48
|
+
if (!CachedRootComponent) {
|
|
49
|
+
let WrappedComponent = getComponentFunc();
|
|
50
|
+
if (__DEV__ && WrappedComponent?.navigationItem) {
|
|
51
|
+
console.warn(`[hybrid-navigation] "${appKey}" enabled lazy registration via registerComponent(), so withNavigationItem() on the component is ignored.`);
|
|
52
|
+
}
|
|
53
|
+
if (hoc) {
|
|
54
|
+
WrappedComponent = hoc(WrappedComponent);
|
|
55
|
+
}
|
|
56
|
+
CachedRootComponent = withNavigation(appKey)(WrappedComponent);
|
|
57
|
+
}
|
|
58
|
+
return CachedRootComponent;
|
|
59
|
+
});
|
|
60
|
+
return;
|
|
40
61
|
}
|
|
41
62
|
let WrappedComponent = getComponentFunc();
|
|
42
|
-
if (
|
|
43
|
-
WrappedComponent =
|
|
63
|
+
if (hoc) {
|
|
64
|
+
WrappedComponent = hoc(WrappedComponent);
|
|
44
65
|
}
|
|
45
66
|
const options = WrappedComponent.navigationItem || {};
|
|
46
67
|
NativeNavigation.registerReactComponent(appKey, options);
|
|
47
|
-
|
|
68
|
+
const RootComponent = withNavigation(appKey)(WrappedComponent);
|
|
48
69
|
AppRegistry.registerComponent(appKey, () => RootComponent);
|
|
49
70
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
71
|
+
addLifecycleListener(sceneId, listener) {
|
|
72
|
+
lifecycleHandler.addLifecycleListener(sceneId, listener);
|
|
73
|
+
return {
|
|
74
|
+
remove: () => lifecycleHandler.removeLifecycleListener(sceneId, listener),
|
|
75
|
+
};
|
|
53
76
|
}
|
|
54
|
-
|
|
55
|
-
|
|
77
|
+
addGlobalLifecycleListener(listener) {
|
|
78
|
+
lifecycleHandler.addGlobalLifecycleListener(listener);
|
|
79
|
+
return {
|
|
80
|
+
remove: () => lifecycleHandler.removeGlobalLifecycleListener(listener),
|
|
81
|
+
};
|
|
56
82
|
}
|
|
57
|
-
|
|
58
|
-
|
|
83
|
+
getSceneState(sceneId) {
|
|
84
|
+
return lifecycleHandler.getSceneState(sceneId);
|
|
59
85
|
}
|
|
60
86
|
addGlobalVisibilityEventListener(listener) {
|
|
61
|
-
|
|
87
|
+
lifecycleHandler.addGlobalVisibilityEventListener(listener);
|
|
62
88
|
return {
|
|
63
|
-
remove: () =>
|
|
89
|
+
remove: () => lifecycleHandler.removeGlobalVisibilityEventListener(listener),
|
|
64
90
|
};
|
|
65
91
|
}
|
|
66
92
|
addVisibilityEventListener(sceneId, listener) {
|
|
67
|
-
|
|
93
|
+
lifecycleHandler.addVisibilityEventListener(sceneId, listener);
|
|
68
94
|
return {
|
|
69
|
-
remove: () =>
|
|
95
|
+
remove: () => lifecycleHandler.removeVisibilityEventListener(sceneId, listener),
|
|
70
96
|
};
|
|
71
97
|
}
|
|
72
98
|
dispatch(sceneId, action, params = {}) {
|
|
73
|
-
return
|
|
74
|
-
}
|
|
75
|
-
handleTabSwitch() {
|
|
76
|
-
NativeEvent.onSwitchTab(({ sceneId, from, to }) => {
|
|
77
|
-
this.dispatch(sceneId, 'switchTab', { from, to });
|
|
78
|
-
});
|
|
99
|
+
return dispatchHandler.dispatch(sceneId, action, params);
|
|
79
100
|
}
|
|
80
|
-
|
|
81
|
-
|
|
101
|
+
addInterceptor(interceptor) {
|
|
102
|
+
dispatchHandler.addInterceptor(interceptor);
|
|
103
|
+
return {
|
|
104
|
+
remove: () => dispatchHandler.removeInterceptor(interceptor),
|
|
105
|
+
};
|
|
82
106
|
}
|
|
83
107
|
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);
|
|
108
|
+
resultHandler.setResult(sceneId, resultCode, data);
|
|
88
109
|
};
|
|
89
|
-
result(sceneId,
|
|
90
|
-
return
|
|
110
|
+
result(sceneId, requestCode) {
|
|
111
|
+
return resultHandler.waitResult(sceneId, requestCode);
|
|
91
112
|
}
|
|
92
|
-
|
|
93
|
-
|
|
113
|
+
setRoot(layout, options) {
|
|
114
|
+
return layoutHandler.setRoot(layout, options);
|
|
94
115
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
setRootLayoutUpdateListener(willSetRoot = () => { }, didSetRoot = () => { }) {
|
|
99
|
-
this.layoutHandler.setRootLayoutUpdateListener(willSetRoot, didSetRoot);
|
|
116
|
+
addRootLayoutUpdateListener(willSetRoot, didSetRoot) {
|
|
117
|
+
const remove = layoutHandler.addRootLayoutUpdateListener(willSetRoot, didSetRoot);
|
|
118
|
+
return { remove };
|
|
100
119
|
}
|
|
101
120
|
currentTab(sceneId) {
|
|
102
|
-
return
|
|
103
|
-
NativeNavigation.currentTab(sceneId, (_, index) => {
|
|
104
|
-
resolve(index);
|
|
105
|
-
});
|
|
106
|
-
});
|
|
121
|
+
return NativeNavigation.currentTab(sceneId);
|
|
107
122
|
}
|
|
108
123
|
findSceneIdByModuleName(moduleName) {
|
|
109
|
-
return
|
|
110
|
-
NativeNavigation.findSceneIdByModuleName(moduleName, (_, sceneId) => {
|
|
111
|
-
resolve(sceneId);
|
|
112
|
-
});
|
|
113
|
-
});
|
|
124
|
+
return NativeNavigation.findSceneIdByModuleName(moduleName);
|
|
114
125
|
}
|
|
115
126
|
isStackRoot(sceneId) {
|
|
116
|
-
return
|
|
117
|
-
NativeNavigation.isStackRoot(sceneId, (_, result) => {
|
|
118
|
-
resolve(result);
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
signalFirstRenderComplete(sceneId) {
|
|
123
|
-
NativeNavigation.signalFirstRenderComplete(sceneId);
|
|
127
|
+
return NativeNavigation.isStackRoot(sceneId);
|
|
124
128
|
}
|
|
125
129
|
currentRoute() {
|
|
126
|
-
return
|
|
127
|
-
NativeNavigation.currentRoute((_, route) => {
|
|
128
|
-
resolve(route);
|
|
129
|
-
});
|
|
130
|
-
});
|
|
130
|
+
return NativeNavigation.currentRoute();
|
|
131
131
|
}
|
|
132
132
|
routeGraph() {
|
|
133
|
-
return
|
|
134
|
-
NativeNavigation.routeGraph((_, graph) => {
|
|
135
|
-
resolve(graph);
|
|
136
|
-
});
|
|
137
|
-
});
|
|
133
|
+
return NativeNavigation.routeGraph();
|
|
138
134
|
}
|
|
139
135
|
setDefaultOptions(options) {
|
|
140
|
-
|
|
136
|
+
NativeNavigation.setDefaultOptions(options);
|
|
141
137
|
}
|
|
142
138
|
updateOptions(sceneId, options) {
|
|
143
|
-
|
|
139
|
+
NativeNavigation.updateOptions(sceneId, options);
|
|
144
140
|
}
|
|
145
141
|
updateTabBar(sceneId, options) {
|
|
146
|
-
|
|
142
|
+
NativeNavigation.updateTabBar(sceneId, options);
|
|
147
143
|
}
|
|
148
144
|
setTabItem(sceneId, item) {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
}
|
|
152
|
-
NativeGarden.setTabItem(sceneId, item);
|
|
145
|
+
const items = Array.isArray(item) ? item : [item];
|
|
146
|
+
NativeNavigation.setTabItem(sceneId, items);
|
|
153
147
|
}
|
|
154
148
|
setMenuInteractive(sceneId, enabled) {
|
|
155
|
-
|
|
149
|
+
return this.dispatch(sceneId, 'setMenuInteractive', { enabled });
|
|
156
150
|
}
|
|
157
151
|
}
|
|
158
152
|
export default new NavigationImpl();
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { NavigationItem } from './Options';
|
|
3
|
+
import type { HasTypedRoutes, RouteName, RoutePropsOf } from './Route';
|
|
3
4
|
import { Navigator } from './Navigator';
|
|
4
|
-
export
|
|
5
|
-
navigator: Navigator
|
|
5
|
+
export type NavigationProps<Name extends RouteName = RouteName> = (HasTypedRoutes extends true ? RoutePropsOf<Name> : Record<string, any>) & {
|
|
6
|
+
navigator: Navigator<Name>;
|
|
6
7
|
sceneId: string;
|
|
7
|
-
}
|
|
8
|
+
};
|
|
8
9
|
interface NativeProps {
|
|
9
10
|
sceneId: string;
|
|
10
11
|
}
|
|
@@ -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,36 @@
|
|
|
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, 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
|
+
showModal: <Name extends RouteName = RouteName, T = RouteResultOf<Name>>(moduleName: Name, ...args: ScreenPropsArgs<Name>) => Promise<NavigationResult<T>>;
|
|
24
|
+
showModalLayout: <T = unknown>(layout: BuildInLayout | Layout) => Promise<NavigationResult<T>>;
|
|
25
|
+
hideModal: () => Promise<DispatchResult>;
|
|
26
|
+
setResult: (resultCode: number, data?: SetResultData<CurrentRoute> | null) => void;
|
|
27
|
+
switchTab: (index: number, popToRoot?: boolean) => Promise<DispatchResult>;
|
|
28
|
+
toggleMenu: () => Promise<DispatchResult>;
|
|
29
|
+
openMenu: () => Promise<DispatchResult>;
|
|
30
|
+
closeMenu: () => Promise<DispatchResult>;
|
|
31
|
+
setMenuInteractive: (enabled: boolean) => Promise<DispatchResult>;
|
|
32
|
+
updateOptions: (options: NavigationOption) => void;
|
|
33
|
+
updateTabBar: (options: TabBarStyle) => void;
|
|
34
|
+
setTabItem: (item: TabItemInfo | TabItemInfo[]) => void;
|
|
45
35
|
isStackRoot: () => Promise<boolean>;
|
|
46
36
|
}
|
|
47
|
-
export {};
|
package/dist/Navigator.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
import { createContext } from 'react';
|
|
2
2
|
import store from './store';
|
|
3
|
-
import
|
|
3
|
+
import NativeNavigation from './NativeNavigation';
|
|
4
|
+
import { dispatchHandler } from './handler/DispatchCommandHandler';
|
|
5
|
+
import { lifecycleHandler } from './handler/LifecycleEventHandler';
|
|
6
|
+
import { RESULT_BLOCK, resultHandler } from './handler/ResultEventHandler';
|
|
4
7
|
export const NavigationContext = createContext(null);
|
|
5
8
|
let tagGenerator = 0;
|
|
6
|
-
Navigation.addGlobalVisibilityEventListener((sceneId, visibility) => {
|
|
7
|
-
const navigator = store.getNavigator(sceneId);
|
|
8
|
-
if (navigator) {
|
|
9
|
-
navigator.visibility = visibility;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
9
|
export class Navigator {
|
|
13
10
|
sceneId;
|
|
14
11
|
moduleName;
|
|
@@ -16,146 +13,156 @@ export class Navigator {
|
|
|
16
13
|
let navigator = store.getNavigator(sceneId);
|
|
17
14
|
if (!navigator) {
|
|
18
15
|
navigator = new Navigator(sceneId);
|
|
19
|
-
|
|
16
|
+
if (lifecycleHandler.getSceneState(sceneId) !== 'destroyed') {
|
|
17
|
+
store.addNavigator(sceneId, navigator);
|
|
18
|
+
}
|
|
20
19
|
}
|
|
21
20
|
return navigator;
|
|
22
21
|
}
|
|
23
|
-
static unmount = (sceneId) => {
|
|
24
|
-
store.removeNavigator(sceneId);
|
|
25
|
-
Navigation.unmount(sceneId);
|
|
26
|
-
};
|
|
27
22
|
static async find(moduleName) {
|
|
28
|
-
const sceneId = await
|
|
23
|
+
const sceneId = await NativeNavigation.findSceneIdByModuleName(moduleName);
|
|
29
24
|
if (sceneId) {
|
|
30
25
|
return Navigator.of(sceneId);
|
|
31
26
|
}
|
|
32
27
|
}
|
|
33
28
|
static async current() {
|
|
34
|
-
const route = await
|
|
29
|
+
const route = await NativeNavigation.currentRoute();
|
|
30
|
+
if (!route) {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
35
33
|
return Navigator.of(route.sceneId);
|
|
36
34
|
}
|
|
37
35
|
constructor(sceneId, moduleName) {
|
|
38
36
|
this.sceneId = sceneId;
|
|
39
37
|
this.moduleName = moduleName;
|
|
40
38
|
}
|
|
41
|
-
visibility
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
39
|
+
get visibility() {
|
|
40
|
+
const state = lifecycleHandler.getSceneState(this.sceneId);
|
|
41
|
+
if (state === 'visible') {
|
|
42
|
+
return 'visible';
|
|
43
|
+
}
|
|
44
|
+
if (state === 'invisible' || state === 'destroyed') {
|
|
45
|
+
return 'invisible';
|
|
46
|
+
}
|
|
47
|
+
return 'pending';
|
|
48
|
+
}
|
|
49
|
+
get lifecycleState() {
|
|
50
|
+
return lifecycleHandler.getSceneState(this.sceneId);
|
|
51
|
+
}
|
|
52
|
+
dispatchForResult = async (action, params, warnOnFailure) => {
|
|
53
|
+
const requestCode = --tagGenerator;
|
|
54
|
+
const { promise, cancel } = resultHandler.prepareResult(this.sceneId, requestCode);
|
|
55
|
+
let result;
|
|
56
|
+
try {
|
|
57
|
+
result = await dispatchHandler.dispatch(this.sceneId, action, {
|
|
58
|
+
...params,
|
|
59
|
+
requestCode,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
cancel();
|
|
64
|
+
throw error;
|
|
65
|
+
}
|
|
66
|
+
if (!result.ok) {
|
|
67
|
+
cancel();
|
|
68
|
+
if (warnOnFailure) {
|
|
69
|
+
console.warn(warnOnFailure(result.code));
|
|
70
|
+
}
|
|
71
|
+
return { status: 'blocked', code: RESULT_BLOCK, reason: result.code };
|
|
72
|
+
}
|
|
73
|
+
return promise;
|
|
47
74
|
};
|
|
48
|
-
push = async (moduleName,
|
|
49
|
-
const
|
|
75
|
+
push = async (moduleName, ...args) => {
|
|
76
|
+
const [props = {}, options = {}] = args;
|
|
77
|
+
return this.dispatchForResult('push', {
|
|
50
78
|
moduleName,
|
|
51
79
|
from: this.moduleName,
|
|
52
80
|
to: moduleName,
|
|
53
|
-
props,
|
|
81
|
+
props: props,
|
|
54
82
|
options,
|
|
55
83
|
});
|
|
56
|
-
if (!success) {
|
|
57
|
-
return [RESULT_BLOCK, null];
|
|
58
|
-
}
|
|
59
|
-
return Navigation.result(this.sceneId, 0);
|
|
60
84
|
};
|
|
61
85
|
pushLayout = async (layout) => {
|
|
62
|
-
|
|
86
|
+
return this.dispatchForResult('pushLayout', {
|
|
63
87
|
from: this.moduleName,
|
|
64
88
|
layout,
|
|
65
89
|
});
|
|
66
|
-
if (!success) {
|
|
67
|
-
return [RESULT_BLOCK, null];
|
|
68
|
-
}
|
|
69
|
-
return Navigation.result(this.sceneId, 0);
|
|
70
90
|
};
|
|
71
|
-
pop = () =>
|
|
72
|
-
popTo = (moduleName, inclusive = false) =>
|
|
91
|
+
pop = () => dispatchHandler.dispatch(this.sceneId, 'pop', { from: this.moduleName });
|
|
92
|
+
popTo = (moduleName, inclusive = false) => dispatchHandler.dispatch(this.sceneId, 'popTo', {
|
|
73
93
|
moduleName,
|
|
74
94
|
inclusive,
|
|
75
95
|
from: this.moduleName,
|
|
76
96
|
to: moduleName,
|
|
77
97
|
});
|
|
78
|
-
popToRoot = () =>
|
|
79
|
-
redirectTo = (moduleName,
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
to: moduleName,
|
|
83
|
-
props,
|
|
84
|
-
options,
|
|
85
|
-
});
|
|
86
|
-
present = async (moduleName, props = {}, options = {}) => {
|
|
87
|
-
const requestCode = --tagGenerator;
|
|
88
|
-
const success = await Navigation.dispatch(this.sceneId, 'present', {
|
|
98
|
+
popToRoot = () => dispatchHandler.dispatch(this.sceneId, 'popToRoot', { from: this.moduleName });
|
|
99
|
+
redirectTo = (moduleName, ...args) => {
|
|
100
|
+
const [props = {}, options = {}] = args;
|
|
101
|
+
return dispatchHandler.dispatch(this.sceneId, 'redirectTo', {
|
|
89
102
|
moduleName,
|
|
90
103
|
from: this.moduleName,
|
|
91
104
|
to: moduleName,
|
|
92
|
-
props,
|
|
105
|
+
props: props,
|
|
93
106
|
options,
|
|
94
|
-
requestCode,
|
|
95
107
|
});
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
108
|
+
};
|
|
109
|
+
present = async (moduleName, ...args) => {
|
|
110
|
+
const [props = {}, options = {}] = args;
|
|
111
|
+
return this.dispatchForResult('present', {
|
|
112
|
+
moduleName,
|
|
113
|
+
from: this.moduleName,
|
|
114
|
+
to: moduleName,
|
|
115
|
+
props: props,
|
|
116
|
+
options,
|
|
117
|
+
}, code => `present from:${this.moduleName} to:${moduleName} failed (${code}).`);
|
|
101
118
|
};
|
|
102
119
|
presentLayout = async (layout) => {
|
|
103
|
-
|
|
104
|
-
const success = await Navigation.dispatch(this.sceneId, 'presentLayout', {
|
|
120
|
+
return this.dispatchForResult('presentLayout', {
|
|
105
121
|
layout,
|
|
106
122
|
from: this.moduleName,
|
|
107
|
-
|
|
108
|
-
});
|
|
109
|
-
if (!success) {
|
|
110
|
-
console.warn(`presentLayout from:${this.moduleName} failed. Maybe the screen (${this.moduleName}) already shows or present another screen.`);
|
|
111
|
-
return [RESULT_BLOCK, null];
|
|
112
|
-
}
|
|
113
|
-
return Navigation.result(this.sceneId, requestCode);
|
|
123
|
+
}, code => `presentLayout from:${this.moduleName} failed (${code}).`);
|
|
114
124
|
};
|
|
115
|
-
dismiss = () =>
|
|
116
|
-
showModal = async (moduleName,
|
|
117
|
-
const
|
|
118
|
-
|
|
125
|
+
dismiss = () => dispatchHandler.dispatch(this.sceneId, 'dismiss', { from: this.moduleName });
|
|
126
|
+
showModal = async (moduleName, ...args) => {
|
|
127
|
+
const [props = {}, options = {}] = args;
|
|
128
|
+
return this.dispatchForResult('showModal', {
|
|
119
129
|
moduleName,
|
|
120
130
|
from: this.moduleName,
|
|
121
131
|
to: moduleName,
|
|
122
|
-
props,
|
|
132
|
+
props: props,
|
|
123
133
|
options,
|
|
124
|
-
|
|
125
|
-
});
|
|
126
|
-
if (!success) {
|
|
127
|
-
console.warn(`showModal from:${this.moduleName} to:${moduleName} failed. Maybe the screen (${this.moduleName}) already shows or present another screen.`);
|
|
128
|
-
return [RESULT_BLOCK, null];
|
|
129
|
-
}
|
|
130
|
-
return Navigation.result(this.sceneId, requestCode);
|
|
134
|
+
}, code => `showModal from:${this.moduleName} to:${moduleName} failed (${code}).`);
|
|
131
135
|
};
|
|
132
136
|
showModalLayout = async (layout) => {
|
|
133
|
-
|
|
134
|
-
const success = await Navigation.dispatch(this.sceneId, 'showModalLayout', {
|
|
137
|
+
return this.dispatchForResult('showModalLayout', {
|
|
135
138
|
from: this.moduleName,
|
|
136
139
|
layout,
|
|
137
|
-
|
|
138
|
-
});
|
|
139
|
-
if (!success) {
|
|
140
|
-
console.warn(`showModal from:${this.moduleName} failed. Maybe the screen (${this.moduleName}) already shows or present another screen.`);
|
|
141
|
-
return [RESULT_BLOCK, null];
|
|
142
|
-
}
|
|
143
|
-
return Navigation.result(this.sceneId, requestCode);
|
|
140
|
+
}, code => `showModalLayout from:${this.moduleName} failed (${code}).`);
|
|
144
141
|
};
|
|
145
|
-
hideModal = () =>
|
|
146
|
-
setResult = (resultCode, data = null) =>
|
|
142
|
+
hideModal = () => dispatchHandler.dispatch(this.sceneId, 'hideModal', { from: this.moduleName });
|
|
143
|
+
setResult = (resultCode, data = null) => resultHandler.setResult(this.sceneId, resultCode, data);
|
|
147
144
|
switchTab = async (index, popToRoot = false) => {
|
|
148
|
-
const from = await
|
|
149
|
-
return
|
|
145
|
+
const from = await NativeNavigation.currentTab(this.sceneId);
|
|
146
|
+
return dispatchHandler.dispatch(this.sceneId, 'switchTab', {
|
|
150
147
|
from,
|
|
151
148
|
to: index,
|
|
152
149
|
popToRoot,
|
|
153
150
|
});
|
|
154
151
|
};
|
|
155
|
-
toggleMenu = () =>
|
|
152
|
+
toggleMenu = () => dispatchHandler.dispatch(this.sceneId, 'toggleMenu', {
|
|
153
|
+
from: this.moduleName,
|
|
154
|
+
});
|
|
155
|
+
openMenu = () => dispatchHandler.dispatch(this.sceneId, 'openMenu', { from: this.moduleName });
|
|
156
|
+
closeMenu = () => dispatchHandler.dispatch(this.sceneId, 'closeMenu', { from: this.moduleName });
|
|
157
|
+
setMenuInteractive = (enabled) => dispatchHandler.dispatch(this.sceneId, 'setMenuInteractive', {
|
|
158
|
+
enabled,
|
|
156
159
|
from: this.moduleName,
|
|
157
160
|
});
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
+
updateOptions = (options) => NativeNavigation.updateOptions(this.sceneId, options);
|
|
162
|
+
updateTabBar = (options) => NativeNavigation.updateTabBar(this.sceneId, options);
|
|
163
|
+
setTabItem = (item) => {
|
|
164
|
+
const items = Array.isArray(item) ? item : [item];
|
|
165
|
+
NativeNavigation.setTabItem(this.sceneId, items);
|
|
166
|
+
};
|
|
167
|
+
isStackRoot = () => NativeNavigation.isStackRoot(this.sceneId);
|
|
161
168
|
}
|
package/dist/Options.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export type BarStyleLightContent = typeof BarStyleLightContent;
|
|
|
10
10
|
export declare const BarStyleDarkContent = "dark-content";
|
|
11
11
|
export type BarStyleDarkContent = typeof BarStyleDarkContent;
|
|
12
12
|
export type BarStyle = BarStyleLightContent | BarStyleDarkContent;
|
|
13
|
+
export type ScreenOrientation = 'portrait' | 'landscape' | 'auto';
|
|
13
14
|
export interface NavigationOption {
|
|
14
15
|
screenBackgroundColor?: Color;
|
|
15
16
|
statusBarHidden?: boolean;
|
|
@@ -19,10 +20,10 @@ export interface NavigationOption {
|
|
|
19
20
|
displayCutoutWhenLandscapeAndroid?: boolean;
|
|
20
21
|
homeIndicatorAutoHiddenIOS?: boolean;
|
|
21
22
|
backInteractive?: boolean;
|
|
23
|
+
orientation?: ScreenOrientation;
|
|
22
24
|
}
|
|
23
25
|
export interface NavigationItem extends NavigationOption {
|
|
24
26
|
animatedTransition?: boolean;
|
|
25
|
-
forceScreenLandscape?: boolean;
|
|
26
27
|
tabItem?: TabItem;
|
|
27
28
|
}
|
|
28
29
|
export interface TabItem {
|
|
@@ -39,6 +40,7 @@ export interface DefaultOptions {
|
|
|
39
40
|
statusBarStyle?: BarStyle;
|
|
40
41
|
navigationBarColorAndroid?: Color;
|
|
41
42
|
displayCutoutWhenLandscapeAndroid?: boolean;
|
|
43
|
+
orientation?: ScreenOrientation;
|
|
42
44
|
tabBarBackgroundColor?: Color;
|
|
43
45
|
tabBarShadowImage?: ShadowImage;
|
|
44
46
|
tabBarItemSelectedColor?: Color;
|