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/src/Navigator.ts
CHANGED
|
@@ -1,226 +1,264 @@
|
|
|
1
1
|
import { createContext } from 'react';
|
|
2
2
|
|
|
3
3
|
import store from './store';
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
4
|
+
import NativeNavigation from './NativeNavigation';
|
|
5
|
+
import { dispatchHandler } from './handler/DispatchCommandHandler';
|
|
6
|
+
import { lifecycleHandler } from './handler/LifecycleEventHandler';
|
|
7
|
+
import { RESULT_BLOCK, resultHandler } from './handler/ResultEventHandler';
|
|
8
|
+
import type { NavigationOption, TabBarStyle, TabItemInfo } from './Options';
|
|
9
|
+
import type {
|
|
10
|
+
BuildInLayout,
|
|
11
|
+
DispatchResult,
|
|
12
|
+
Layout,
|
|
13
|
+
NavigationResult,
|
|
14
|
+
RouteName,
|
|
15
|
+
RouteResultOf,
|
|
16
|
+
SceneLifecycleState,
|
|
17
|
+
ScreenPropsArgs,
|
|
18
|
+
SetResultData,
|
|
19
|
+
Visibility,
|
|
20
|
+
} from './Route';
|
|
21
|
+
|
|
22
|
+
export const NavigationContext = createContext<Navigator<any> | null>(null);
|
|
17
23
|
|
|
18
24
|
let tagGenerator = 0;
|
|
19
25
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
if (navigator) {
|
|
23
|
-
navigator.visibility = visibility;
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
export interface Navigator {}
|
|
28
|
-
|
|
29
|
-
export class Navigator implements Navigator {
|
|
30
|
-
static of(sceneId: string) {
|
|
26
|
+
export class Navigator<CurrentRoute extends RouteName = RouteName> {
|
|
27
|
+
static of<Name extends RouteName = RouteName>(sceneId: string): Navigator<Name> {
|
|
31
28
|
let navigator = store.getNavigator(sceneId);
|
|
32
29
|
if (!navigator) {
|
|
33
30
|
navigator = new Navigator(sceneId);
|
|
34
|
-
|
|
31
|
+
if (lifecycleHandler.getSceneState(sceneId) !== 'destroyed') {
|
|
32
|
+
store.addNavigator(sceneId, navigator);
|
|
33
|
+
}
|
|
35
34
|
}
|
|
36
|
-
return navigator
|
|
35
|
+
return navigator as unknown as Navigator<Name>;
|
|
37
36
|
}
|
|
38
37
|
|
|
39
|
-
static
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
static async find(moduleName: string) {
|
|
45
|
-
const sceneId = await Navigation.findSceneIdByModuleName(moduleName);
|
|
38
|
+
static async find<Name extends RouteName = RouteName>(
|
|
39
|
+
moduleName: Name,
|
|
40
|
+
): Promise<Navigator<Name> | undefined> {
|
|
41
|
+
const sceneId = await NativeNavigation.findSceneIdByModuleName(moduleName);
|
|
46
42
|
if (sceneId) {
|
|
47
|
-
return Navigator.of(sceneId);
|
|
43
|
+
return Navigator.of<Name>(sceneId);
|
|
48
44
|
}
|
|
49
45
|
}
|
|
50
46
|
|
|
51
|
-
static async current(): Promise<Navigator> {
|
|
52
|
-
const route = await
|
|
47
|
+
static async current(): Promise<Navigator | undefined> {
|
|
48
|
+
const route = await NativeNavigation.currentRoute();
|
|
49
|
+
if (!route) {
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
53
52
|
return Navigator.of(route.sceneId);
|
|
54
53
|
}
|
|
55
54
|
|
|
56
55
|
constructor(public sceneId: string, public moduleName?: string) {}
|
|
57
56
|
|
|
58
|
-
visibility: Visibility
|
|
57
|
+
get visibility(): Visibility {
|
|
58
|
+
const state = lifecycleHandler.getSceneState(this.sceneId);
|
|
59
|
+
if (state === 'visible') {
|
|
60
|
+
return 'visible';
|
|
61
|
+
}
|
|
62
|
+
if (state === 'invisible' || state === 'destroyed') {
|
|
63
|
+
return 'invisible';
|
|
64
|
+
}
|
|
65
|
+
return 'pending';
|
|
66
|
+
}
|
|
59
67
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
68
|
+
get lifecycleState(): SceneLifecycleState {
|
|
69
|
+
return lifecycleHandler.getSceneState(this.sceneId);
|
|
70
|
+
}
|
|
63
71
|
|
|
64
|
-
|
|
65
|
-
|
|
72
|
+
private dispatchForResult = async <T = unknown>(
|
|
73
|
+
action: string,
|
|
74
|
+
params: Record<string, any>,
|
|
75
|
+
warnOnFailure?: (code: DispatchResult['code']) => string,
|
|
76
|
+
): Promise<NavigationResult<T>> => {
|
|
77
|
+
const requestCode = --tagGenerator;
|
|
78
|
+
const { promise, cancel } = resultHandler.prepareResult<T>(this.sceneId, requestCode);
|
|
79
|
+
let result: DispatchResult;
|
|
80
|
+
try {
|
|
81
|
+
result = await dispatchHandler.dispatch(this.sceneId, action, {
|
|
82
|
+
...params,
|
|
83
|
+
requestCode,
|
|
84
|
+
});
|
|
85
|
+
} catch (error) {
|
|
86
|
+
cancel();
|
|
87
|
+
throw error;
|
|
88
|
+
}
|
|
89
|
+
if (!result.ok) {
|
|
90
|
+
cancel();
|
|
91
|
+
if (warnOnFailure) {
|
|
92
|
+
console.warn(warnOnFailure(result.code));
|
|
93
|
+
}
|
|
94
|
+
return { status: 'blocked', code: RESULT_BLOCK, reason: result.code };
|
|
95
|
+
}
|
|
96
|
+
return promise;
|
|
66
97
|
};
|
|
67
98
|
|
|
68
|
-
push = async <
|
|
69
|
-
moduleName:
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
99
|
+
push = async <Name extends RouteName = RouteName, T = RouteResultOf<Name>>(
|
|
100
|
+
moduleName: Name,
|
|
101
|
+
...args: ScreenPropsArgs<Name>
|
|
102
|
+
): Promise<NavigationResult<T>> => {
|
|
103
|
+
const [props = {}, options = {}] = args;
|
|
104
|
+
return this.dispatchForResult<T>('push', {
|
|
74
105
|
moduleName,
|
|
75
106
|
from: this.moduleName,
|
|
76
107
|
to: moduleName,
|
|
77
|
-
props,
|
|
108
|
+
props: props as object,
|
|
78
109
|
options,
|
|
79
110
|
});
|
|
80
|
-
if (!success) {
|
|
81
|
-
return [RESULT_BLOCK, null] as [number, T];
|
|
82
|
-
}
|
|
83
|
-
return Navigation.result<T>(this.sceneId, 0);
|
|
84
111
|
};
|
|
85
112
|
|
|
86
|
-
pushLayout = async <T
|
|
87
|
-
|
|
113
|
+
pushLayout = async <T = unknown>(
|
|
114
|
+
layout: BuildInLayout | Layout,
|
|
115
|
+
): Promise<NavigationResult<T>> => {
|
|
116
|
+
return this.dispatchForResult<T>('pushLayout', {
|
|
88
117
|
from: this.moduleName,
|
|
89
118
|
layout,
|
|
90
119
|
});
|
|
91
|
-
if (!success) {
|
|
92
|
-
return [RESULT_BLOCK, null] as [number, T];
|
|
93
|
-
}
|
|
94
|
-
return Navigation.result<T>(this.sceneId, 0);
|
|
95
120
|
};
|
|
96
121
|
|
|
97
|
-
pop = ()
|
|
122
|
+
pop = (): Promise<DispatchResult> =>
|
|
123
|
+
dispatchHandler.dispatch(this.sceneId, 'pop', { from: this.moduleName });
|
|
98
124
|
|
|
99
|
-
popTo = (
|
|
100
|
-
|
|
125
|
+
popTo = (
|
|
126
|
+
moduleName: RouteName | (string & {}),
|
|
127
|
+
inclusive: boolean = false,
|
|
128
|
+
): Promise<DispatchResult> =>
|
|
129
|
+
dispatchHandler.dispatch(this.sceneId, 'popTo', {
|
|
101
130
|
moduleName,
|
|
102
131
|
inclusive,
|
|
103
132
|
from: this.moduleName,
|
|
104
133
|
to: moduleName,
|
|
105
134
|
});
|
|
106
135
|
|
|
107
|
-
popToRoot = ()
|
|
108
|
-
|
|
109
|
-
redirectTo = <P extends PropsType>(
|
|
110
|
-
moduleName: string,
|
|
111
|
-
props: P = {} as P,
|
|
112
|
-
options: NavigationItem = {},
|
|
113
|
-
) =>
|
|
114
|
-
Navigation.dispatch(this.sceneId, 'redirectTo', {
|
|
115
|
-
moduleName,
|
|
116
|
-
from: this.moduleName,
|
|
117
|
-
to: moduleName,
|
|
118
|
-
props,
|
|
119
|
-
options,
|
|
120
|
-
});
|
|
136
|
+
popToRoot = (): Promise<DispatchResult> =>
|
|
137
|
+
dispatchHandler.dispatch(this.sceneId, 'popToRoot', { from: this.moduleName });
|
|
121
138
|
|
|
122
|
-
|
|
123
|
-
moduleName:
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
const success = await Navigation.dispatch(this.sceneId, 'present', {
|
|
139
|
+
redirectTo = <Name extends RouteName = RouteName>(
|
|
140
|
+
moduleName: Name,
|
|
141
|
+
...args: ScreenPropsArgs<Name>
|
|
142
|
+
): Promise<DispatchResult> => {
|
|
143
|
+
const [props = {}, options = {}] = args;
|
|
144
|
+
return dispatchHandler.dispatch(this.sceneId, 'redirectTo', {
|
|
129
145
|
moduleName,
|
|
130
146
|
from: this.moduleName,
|
|
131
147
|
to: moduleName,
|
|
132
|
-
props,
|
|
148
|
+
props: props as object,
|
|
133
149
|
options,
|
|
134
|
-
requestCode,
|
|
135
150
|
});
|
|
136
|
-
if (!success) {
|
|
137
|
-
console.warn(
|
|
138
|
-
`present from:${this.moduleName} to:${moduleName} failed. Maybe the screen (${this.moduleName}) already shows or present another screen.`,
|
|
139
|
-
);
|
|
140
|
-
return [RESULT_BLOCK, null] as [number, T];
|
|
141
|
-
}
|
|
142
|
-
return Navigation.result<T>(this.sceneId, requestCode);
|
|
143
151
|
};
|
|
144
152
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
153
|
+
present = async <Name extends RouteName = RouteName, T = RouteResultOf<Name>>(
|
|
154
|
+
moduleName: Name,
|
|
155
|
+
...args: ScreenPropsArgs<Name>
|
|
156
|
+
): Promise<NavigationResult<T>> => {
|
|
157
|
+
const [props = {}, options = {}] = args;
|
|
158
|
+
return this.dispatchForResult<T>(
|
|
159
|
+
'present',
|
|
160
|
+
{
|
|
161
|
+
moduleName,
|
|
162
|
+
from: this.moduleName,
|
|
163
|
+
to: moduleName,
|
|
164
|
+
props: props as object,
|
|
165
|
+
options,
|
|
166
|
+
},
|
|
167
|
+
code => `present from:${this.moduleName} to:${moduleName} failed (${code}).`,
|
|
168
|
+
);
|
|
159
169
|
};
|
|
160
170
|
|
|
161
|
-
|
|
171
|
+
presentLayout = async <T = unknown>(
|
|
172
|
+
layout: BuildInLayout | Layout,
|
|
173
|
+
): Promise<NavigationResult<T>> => {
|
|
174
|
+
return this.dispatchForResult<T>(
|
|
175
|
+
'presentLayout',
|
|
176
|
+
{
|
|
177
|
+
layout,
|
|
178
|
+
from: this.moduleName,
|
|
179
|
+
},
|
|
180
|
+
code => `presentLayout from:${this.moduleName} failed (${code}).`,
|
|
181
|
+
);
|
|
182
|
+
};
|
|
162
183
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
)
|
|
181
|
-
|
|
182
|
-
}
|
|
183
|
-
return Navigation.result<T>(this.sceneId, requestCode);
|
|
184
|
+
dismiss = (): Promise<DispatchResult> =>
|
|
185
|
+
dispatchHandler.dispatch(this.sceneId, 'dismiss', { from: this.moduleName });
|
|
186
|
+
|
|
187
|
+
showModal = async <Name extends RouteName = RouteName, T = RouteResultOf<Name>>(
|
|
188
|
+
moduleName: Name,
|
|
189
|
+
...args: ScreenPropsArgs<Name>
|
|
190
|
+
): Promise<NavigationResult<T>> => {
|
|
191
|
+
const [props = {}, options = {}] = args;
|
|
192
|
+
return this.dispatchForResult<T>(
|
|
193
|
+
'showModal',
|
|
194
|
+
{
|
|
195
|
+
moduleName,
|
|
196
|
+
from: this.moduleName,
|
|
197
|
+
to: moduleName,
|
|
198
|
+
props: props as object,
|
|
199
|
+
options,
|
|
200
|
+
},
|
|
201
|
+
code => `showModal from:${this.moduleName} to:${moduleName} failed (${code}).`,
|
|
202
|
+
);
|
|
184
203
|
};
|
|
185
204
|
|
|
186
|
-
showModalLayout = async <T
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
return [RESULT_BLOCK, null] as [number, T];
|
|
198
|
-
}
|
|
199
|
-
return Navigation.result<T>(this.sceneId, requestCode);
|
|
205
|
+
showModalLayout = async <T = unknown>(
|
|
206
|
+
layout: BuildInLayout | Layout,
|
|
207
|
+
): Promise<NavigationResult<T>> => {
|
|
208
|
+
return this.dispatchForResult<T>(
|
|
209
|
+
'showModalLayout',
|
|
210
|
+
{
|
|
211
|
+
from: this.moduleName,
|
|
212
|
+
layout,
|
|
213
|
+
},
|
|
214
|
+
code => `showModalLayout from:${this.moduleName} failed (${code}).`,
|
|
215
|
+
);
|
|
200
216
|
};
|
|
201
217
|
|
|
202
|
-
hideModal = ()
|
|
218
|
+
hideModal = (): Promise<DispatchResult> =>
|
|
219
|
+
dispatchHandler.dispatch(this.sceneId, 'hideModal', { from: this.moduleName });
|
|
203
220
|
|
|
204
|
-
setResult =
|
|
205
|
-
|
|
221
|
+
setResult = (
|
|
222
|
+
resultCode: number,
|
|
223
|
+
data: SetResultData<CurrentRoute> | null = null,
|
|
224
|
+
): void => resultHandler.setResult(this.sceneId, resultCode, data);
|
|
206
225
|
|
|
207
|
-
switchTab = async (index: number, popToRoot: boolean = false) => {
|
|
208
|
-
const from = await
|
|
209
|
-
return
|
|
226
|
+
switchTab = async (index: number, popToRoot: boolean = false): Promise<DispatchResult> => {
|
|
227
|
+
const from = await NativeNavigation.currentTab(this.sceneId);
|
|
228
|
+
return dispatchHandler.dispatch(this.sceneId, 'switchTab', {
|
|
210
229
|
from,
|
|
211
230
|
to: index,
|
|
212
231
|
popToRoot,
|
|
213
232
|
});
|
|
214
233
|
};
|
|
215
234
|
|
|
216
|
-
toggleMenu = () =>
|
|
217
|
-
|
|
235
|
+
toggleMenu = (): Promise<DispatchResult> =>
|
|
236
|
+
dispatchHandler.dispatch(this.sceneId, 'toggleMenu', {
|
|
218
237
|
from: this.moduleName,
|
|
219
238
|
});
|
|
220
239
|
|
|
221
|
-
openMenu = ()
|
|
240
|
+
openMenu = (): Promise<DispatchResult> =>
|
|
241
|
+
dispatchHandler.dispatch(this.sceneId, 'openMenu', { from: this.moduleName });
|
|
242
|
+
|
|
243
|
+
closeMenu = (): Promise<DispatchResult> =>
|
|
244
|
+
dispatchHandler.dispatch(this.sceneId, 'closeMenu', { from: this.moduleName });
|
|
222
245
|
|
|
223
|
-
|
|
246
|
+
setMenuInteractive = (enabled: boolean): Promise<DispatchResult> =>
|
|
247
|
+
dispatchHandler.dispatch(this.sceneId, 'setMenuInteractive', {
|
|
248
|
+
enabled,
|
|
249
|
+
from: this.moduleName,
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
updateOptions = (options: NavigationOption): void =>
|
|
253
|
+
NativeNavigation.updateOptions(this.sceneId, options);
|
|
254
|
+
|
|
255
|
+
updateTabBar = (options: TabBarStyle): void =>
|
|
256
|
+
NativeNavigation.updateTabBar(this.sceneId, options);
|
|
257
|
+
|
|
258
|
+
setTabItem = (item: TabItemInfo | TabItemInfo[]): void => {
|
|
259
|
+
const items = Array.isArray(item) ? item : [item];
|
|
260
|
+
NativeNavigation.setTabItem(this.sceneId, items);
|
|
261
|
+
};
|
|
224
262
|
|
|
225
|
-
isStackRoot = () =>
|
|
263
|
+
isStackRoot = () => NativeNavigation.isStackRoot(this.sceneId);
|
|
226
264
|
}
|
package/src/Options.ts
CHANGED
|
@@ -10,6 +10,7 @@ export type BarStyleLightContent = typeof BarStyleLightContent;
|
|
|
10
10
|
export 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
|
|
|
14
15
|
export interface NavigationOption {
|
|
15
16
|
screenBackgroundColor?: Color; // 页面背景,默认是白色
|
|
@@ -21,11 +22,11 @@ export interface NavigationOption {
|
|
|
21
22
|
homeIndicatorAutoHiddenIOS?: boolean; // 是否隐藏 Home 指示器,默认 false
|
|
22
23
|
|
|
23
24
|
backInteractive?: boolean; // 是否允许侧滑返回或通过返回键返回
|
|
25
|
+
orientation?: ScreenOrientation; // 页面方向策略:portrait | landscape | auto
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
export interface NavigationItem extends NavigationOption {
|
|
27
29
|
animatedTransition?: boolean;
|
|
28
|
-
forceScreenLandscape?: boolean; // 是否强制横屏
|
|
29
30
|
tabItem?: TabItem;
|
|
30
31
|
}
|
|
31
32
|
|
|
@@ -45,6 +46,7 @@ export interface DefaultOptions {
|
|
|
45
46
|
statusBarStyle?: BarStyle; // 状态栏样式,可选项有 `BarStyleLightContent` 和 `BarStyleDarkContent`
|
|
46
47
|
navigationBarColorAndroid?: Color; // 底部虚拟键背景颜色,仅对 Android 8.0 以上版本生效
|
|
47
48
|
displayCutoutWhenLandscapeAndroid?: boolean; // 横屏时,是否将界面延伸至刘海区域,默认 true
|
|
49
|
+
orientation?: ScreenOrientation; // 默认全局方向策略,默认为 portrait
|
|
48
50
|
|
|
49
51
|
tabBarBackgroundColor?: Color; // 底部 TabBar 背景颜色,请勿使用带透明度的颜色。
|
|
50
52
|
tabBarShadowImage?: ShadowImage; // 底部 TabBar 阴影图片。对于 iOS, 只有同时设置了 tabBarBackgroundColor 才会生效
|
package/src/Route.ts
CHANGED
|
@@ -1,32 +1,137 @@
|
|
|
1
|
+
import type { NavigationItem } from './Options';
|
|
2
|
+
import type { CustomLayoutMap, NavigationParamList } from './index';
|
|
3
|
+
|
|
1
4
|
export type Visibility = 'visible' | 'invisible' | 'pending';
|
|
2
5
|
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
export type SceneLifecycleState = 'created' | 'visible' | 'invisible' | 'destroyed';
|
|
7
|
+
|
|
8
|
+
export type DispatchResultCode =
|
|
9
|
+
| 'ok'
|
|
10
|
+
| 'intercepted'
|
|
11
|
+
| 'scene_not_found'
|
|
12
|
+
| 'already_presenting'
|
|
13
|
+
| 'not_ready'
|
|
14
|
+
| 'superseded'
|
|
15
|
+
| 'invalid_action'
|
|
16
|
+
| 'host_unavailable';
|
|
17
|
+
|
|
18
|
+
export interface DispatchResult {
|
|
19
|
+
ok: boolean;
|
|
20
|
+
code: DispatchResultCode;
|
|
21
|
+
message?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface SetRootOptions {
|
|
25
|
+
stickyAndroid?: boolean;
|
|
9
26
|
}
|
|
10
27
|
|
|
11
|
-
export
|
|
28
|
+
export type CancelReason = 'dismissed' | 'unmounted' | 'root_reset';
|
|
29
|
+
|
|
30
|
+
export type NavigationResult<T = unknown> =
|
|
31
|
+
| { status: 'ok'; code: number; data: T }
|
|
32
|
+
| { status: 'cancel'; code: number; reason: CancelReason }
|
|
33
|
+
| { status: 'blocked'; code: number; reason: DispatchResultCode };
|
|
34
|
+
|
|
35
|
+
export type ScreenRoute<
|
|
36
|
+
Props extends Record<string, any> = Record<never, never>,
|
|
37
|
+
Result = unknown,
|
|
38
|
+
> = {
|
|
39
|
+
props: Props;
|
|
40
|
+
result: Result;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export type HasTypedRoutes = keyof NavigationParamList extends never ? false : true;
|
|
44
|
+
|
|
45
|
+
export type RouteName = HasTypedRoutes extends true
|
|
46
|
+
? Extract<keyof NavigationParamList, string>
|
|
47
|
+
: string;
|
|
48
|
+
|
|
49
|
+
type RawRouteEntry<Name extends string> = Name extends keyof NavigationParamList
|
|
50
|
+
? NavigationParamList[Name]
|
|
51
|
+
: ScreenRoute<Record<string, any>, unknown>;
|
|
52
|
+
|
|
53
|
+
export type RoutePropsOf<Name extends string> =
|
|
54
|
+
RawRouteEntry<Name> extends { props: infer P }
|
|
55
|
+
? P
|
|
56
|
+
: RawRouteEntry<Name> extends { props?: infer P }
|
|
57
|
+
? [Exclude<P, undefined>] extends [never]
|
|
58
|
+
? Record<never, never>
|
|
59
|
+
: Exclude<P, undefined>
|
|
60
|
+
: Record<string, any>;
|
|
61
|
+
|
|
62
|
+
export type RouteResultOf<Name extends string> =
|
|
63
|
+
RawRouteEntry<Name> extends { result: infer R }
|
|
64
|
+
? R
|
|
65
|
+
: RawRouteEntry<Name> extends { result?: infer R }
|
|
66
|
+
? unknown extends R
|
|
67
|
+
? unknown
|
|
68
|
+
: [Exclude<R, undefined>] extends [never]
|
|
69
|
+
? unknown
|
|
70
|
+
: Exclude<R, undefined>
|
|
71
|
+
: unknown;
|
|
72
|
+
|
|
73
|
+
export type ResultMap = Record<string, any> & { [Symbol.iterator]?: never };
|
|
74
|
+
|
|
75
|
+
type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
76
|
+
|
|
77
|
+
export type SetResultData<Name extends string> =
|
|
78
|
+
IsAny<Name> extends true
|
|
79
|
+
? any
|
|
80
|
+
: unknown extends RouteResultOf<Name>
|
|
81
|
+
? ResultMap
|
|
82
|
+
: Extract<RouteResultOf<Name>, ResultMap>;
|
|
83
|
+
|
|
84
|
+
type RequiredKeysOf<T> = {
|
|
85
|
+
[K in keyof T]-?: {} extends Pick<T, K> ? never : K;
|
|
86
|
+
}[keyof T];
|
|
87
|
+
|
|
88
|
+
export type IsPropsRequired<P> = [RequiredKeysOf<P>] extends [never] ? false : true;
|
|
89
|
+
|
|
90
|
+
export type ScreenPropsArgs<Name extends string> = HasTypedRoutes extends true
|
|
91
|
+
? IsPropsRequired<RoutePropsOf<Name>> extends true
|
|
92
|
+
? [props: RoutePropsOf<Name>, options?: NavigationItem]
|
|
93
|
+
: [props?: RoutePropsOf<Name>, options?: NavigationItem]
|
|
94
|
+
: [props?: Record<string, any>, options?: NavigationItem];
|
|
95
|
+
|
|
96
|
+
export type Screen<Name extends RouteName = RouteName> = HasTypedRoutes extends true
|
|
97
|
+
? Name extends RouteName
|
|
98
|
+
? {
|
|
99
|
+
screen: {
|
|
100
|
+
moduleName: Name;
|
|
101
|
+
props?: RoutePropsOf<Name>;
|
|
102
|
+
options?: NavigationItem;
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
: never
|
|
106
|
+
: {
|
|
107
|
+
screen: {
|
|
108
|
+
moduleName: Name;
|
|
109
|
+
props?: Record<string, any>;
|
|
110
|
+
options?: NavigationItem;
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
export type TypedScreen = Screen<RouteName>;
|
|
115
|
+
|
|
116
|
+
export interface Stack {
|
|
12
117
|
stack: {
|
|
13
|
-
children: Array<
|
|
118
|
+
children: Array<Layout>;
|
|
14
119
|
options?: {};
|
|
15
120
|
};
|
|
16
121
|
}
|
|
17
122
|
|
|
18
|
-
export interface Tabs
|
|
123
|
+
export interface Tabs {
|
|
19
124
|
tabs: {
|
|
20
|
-
children: Array<
|
|
125
|
+
children: Array<Layout>;
|
|
21
126
|
options?: {
|
|
22
127
|
selectedIndex?: number;
|
|
23
128
|
};
|
|
24
129
|
};
|
|
25
130
|
}
|
|
26
131
|
|
|
27
|
-
export interface Drawer
|
|
132
|
+
export interface Drawer {
|
|
28
133
|
drawer: {
|
|
29
|
-
children: [
|
|
134
|
+
children: [Layout, Layout];
|
|
30
135
|
options?: {
|
|
31
136
|
maxDrawerWidth?: number;
|
|
32
137
|
minDrawerMargin?: number;
|
|
@@ -35,11 +140,17 @@ export interface Drawer extends Layout {
|
|
|
35
140
|
};
|
|
36
141
|
}
|
|
37
142
|
|
|
38
|
-
export type
|
|
143
|
+
export type HasCustomLayouts = keyof CustomLayoutMap extends never ? false : true;
|
|
39
144
|
|
|
40
|
-
export
|
|
41
|
-
|
|
42
|
-
|
|
145
|
+
export type CustomLayout = HasCustomLayouts extends true
|
|
146
|
+
? {
|
|
147
|
+
[K in Extract<keyof CustomLayoutMap, string>]: Record<K, CustomLayoutMap[K]>;
|
|
148
|
+
}[Extract<keyof CustomLayoutMap, string>]
|
|
149
|
+
: never;
|
|
150
|
+
|
|
151
|
+
export type BuiltInLayout = TypedScreen | Stack | Tabs | Drawer;
|
|
152
|
+
export type BuildInLayout = BuiltInLayout;
|
|
153
|
+
export type Layout = BuiltInLayout | CustomLayout;
|
|
43
154
|
|
|
44
155
|
export type RouteMode = 'modal' | 'present' | 'push';
|
|
45
156
|
export type LayoutMode = 'modal' | 'present' | 'normal';
|
|
@@ -61,8 +172,10 @@ export interface RouteGraph {
|
|
|
61
172
|
|
|
62
173
|
export interface RouteConfig {
|
|
63
174
|
path?: string;
|
|
64
|
-
dependency?:
|
|
175
|
+
dependency?: RouteName;
|
|
65
176
|
mode?: RouteMode;
|
|
177
|
+
options?: NavigationItem;
|
|
178
|
+
lazy?: boolean;
|
|
66
179
|
}
|
|
67
180
|
|
|
68
181
|
export interface RouteData {
|
|
@@ -81,13 +194,15 @@ export interface RouteInfo {
|
|
|
81
194
|
options: object;
|
|
82
195
|
}
|
|
83
196
|
|
|
197
|
+
export type RouteHandleResult = [boolean, RouteGraph | null, DispatchResult?];
|
|
198
|
+
|
|
84
199
|
export interface RouteHandler {
|
|
85
200
|
/**
|
|
86
201
|
* @param graph - current RouteGraph to process
|
|
87
202
|
* @param target - route may add to the graph
|
|
88
|
-
* @returns [boolean, RouteGraph] - if the route is handled, return true and
|
|
203
|
+
* @returns [boolean, RouteGraph | null, DispatchResult?] - if the route is handled, return true and childGraph for next Handler to process, [false, graph] otherwise
|
|
89
204
|
*/
|
|
90
|
-
process: (graph: RouteGraph, target: RouteInfo) => Promise<
|
|
205
|
+
process: (graph: RouteGraph, target: RouteInfo) => Promise<RouteHandleResult>;
|
|
91
206
|
}
|
|
92
207
|
|
|
93
208
|
export type RouteInterceptor = (path: string) => boolean | Promise<boolean>;
|