hybrid-navigation 4.1.0 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/HybridNavigation.podspec +9 -1
- package/README.md +12 -4
- package/android/build.gradle +4 -4
- package/android/proguard-rules.pro +0 -14
- package/android/src/main/java/com/navigation/androidx/AwesomeActivity.java +116 -27
- package/android/src/main/java/com/navigation/androidx/AwesomeFragment.java +162 -13
- package/android/src/main/java/com/navigation/androidx/DefaultTabBarProvider.java +2 -2
- package/android/src/main/java/com/navigation/androidx/DrawableUtils.java +83 -18
- package/android/src/main/java/com/navigation/androidx/DrawerFragment.java +185 -25
- package/android/src/main/java/com/navigation/androidx/FragmentHelper.java +18 -0
- package/android/src/main/java/com/navigation/androidx/HybridDrawerLayout.java +563 -143
- package/android/src/main/java/com/navigation/androidx/LifecycleDelegate.java +39 -12
- package/android/src/main/java/com/navigation/androidx/PresentableActivity.java +3 -0
- package/android/src/main/java/com/navigation/androidx/PresentationDelegate.java +10 -7
- package/android/src/main/java/com/navigation/androidx/StackDelegate.java +29 -9
- package/android/src/main/java/com/navigation/androidx/StackFragment.java +31 -3
- package/android/src/main/java/com/navigation/androidx/SystemUI.java +59 -90
- package/android/src/main/java/com/navigation/androidx/TabBar.java +21 -2
- package/android/src/main/java/com/navigation/androidx/TabBarFragment.java +74 -7
- package/android/src/main/java/com/navigation/androidx/TabBarItem.java +4 -0
- package/android/src/main/java/com/navigation/androidx/TabView.java +11 -2
- package/android/src/main/java/com/reactnative/hybridnavigation/DispatchResult.java +71 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/Garden.java +18 -10
- package/android/src/main/java/com/reactnative/hybridnavigation/GlobalStyle.java +34 -2
- package/android/src/main/java/com/reactnative/hybridnavigation/HBDRootView.java +20 -10
- package/android/src/main/java/com/reactnative/hybridnavigation/HybridFragment.java +179 -13
- package/android/src/main/java/com/reactnative/hybridnavigation/HybridNavigationPackage.java +13 -24
- package/android/src/main/java/com/reactnative/hybridnavigation/NativeEvent.java +5 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/NativeNavigation.java +283 -183
- package/android/src/main/java/com/reactnative/hybridnavigation/NavigationCommandQueue.java +507 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/Navigator.java +4 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/OrientationCoordinator.java +162 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactAppCompatActivity.java +103 -66
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactFragment.java +421 -92
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactManager.java +227 -78
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactStackFragment.java +6 -6
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarFragment.java +26 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarProvider.java +8 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/SceneLifecycleState.java +21 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/SceneLifecycleStateMachine.java +116 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/ScreenOrientation.java +42 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/Utils.java +17 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/DrawerNavigator.java +14 -6
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/ScreenNavigator.java +188 -26
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/StackNavigator.java +67 -16
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/TabNavigator.java +42 -14
- package/dist/DeepLink.d.ts +3 -2
- package/dist/DeepLink.js +37 -14
- package/dist/NativeEvent.d.ts +17 -10
- package/dist/NativeNavigation.d.ts +24 -18
- package/dist/Navigation.d.ts +34 -19
- package/dist/Navigation.js +225 -90
- package/dist/NavigationComponentWrap.d.ts +5 -3
- package/dist/NavigationComponentWrap.js +3 -6
- package/dist/Navigator.d.ts +32 -42
- package/dist/Navigator.js +117 -91
- package/dist/Options.d.ts +15 -3
- package/dist/Route.d.ts +149 -17
- package/dist/defineRoutes.d.ts +19 -0
- package/dist/defineRoutes.js +6 -0
- package/dist/handler/DispatchCommandHandler.d.ts +25 -6
- package/dist/handler/DispatchCommandHandler.js +99 -17
- package/dist/handler/LayoutCommandHandler.d.ts +8 -7
- package/dist/handler/LayoutCommandHandler.js +24 -15
- package/dist/handler/LeaveGuardHandler.d.ts +17 -0
- package/dist/handler/LeaveGuardHandler.js +350 -0
- package/dist/handler/LifecycleEventHandler.d.ts +30 -0
- package/dist/handler/LifecycleEventHandler.js +169 -0
- package/dist/handler/PresentationCoordinator.d.ts +24 -0
- package/dist/handler/PresentationCoordinator.js +449 -0
- package/dist/handler/ResultEventHandler.d.ts +21 -9
- package/dist/handler/ResultEventHandler.js +96 -13
- package/dist/handler/TabEventHandler.d.ts +8 -0
- package/dist/handler/TabEventHandler.js +25 -0
- package/dist/hooks.d.ts +7 -2
- package/dist/hooks.js +46 -4
- package/dist/index.d.ts +24 -0
- package/dist/index.js +3 -2
- package/dist/reveal.d.ts +46 -0
- package/dist/reveal.js +431 -0
- package/dist/routeConfigRegistry.d.ts +6 -0
- package/dist/routeConfigRegistry.js +19 -0
- package/dist/routeGraph.d.ts +12 -0
- package/dist/routeGraph.js +68 -0
- package/dist/router/drawer.d.ts +2 -2
- package/dist/router/drawer.js +6 -3
- package/dist/router/index.d.ts +8 -5
- package/dist/router/index.js +106 -58
- package/dist/router/screen.d.ts +2 -2
- package/dist/router/screen.js +1 -1
- package/dist/router/stack.d.ts +2 -2
- package/dist/router/stack.js +59 -30
- package/dist/router/tabs.d.ts +3 -2
- package/dist/router/tabs.js +4 -1
- package/dist/store.d.ts +4 -2
- package/dist/store.js +4 -0
- package/dist/testing.d.ts +79 -0
- package/dist/testing.js +251 -0
- package/ios/HBDGlobalStyle.h +29 -0
- package/ios/{GlobalStyle.mm → HBDGlobalStyle.mm} +43 -29
- package/ios/HybridNavigation.h +5 -1
- package/ios/Navigator/HBDDrawerNavigator.mm +24 -8
- package/ios/Navigator/HBDNavigatorRegistry.mm +1 -0
- package/ios/Navigator/HBDScreenNavigator.mm +278 -58
- package/ios/Navigator/HBDStackNavigator.mm +152 -61
- package/ios/Navigator/HBDTabNavigator.mm +60 -14
- package/ios/React/HBDNativeNavigation.mm +162 -123
- package/ios/React/HBDNavigator.h +37 -5
- package/ios/React/HBDOrientationCoordinator.h +29 -0
- package/ios/React/HBDOrientationCoordinator.mm +309 -0
- package/ios/React/HBDReactBridgeManager.h +46 -20
- package/ios/React/HBDReactBridgeManager.mm +496 -108
- package/ios/React/HBDSceneLifecycleStateMachine.h +38 -0
- package/ios/React/HBDSceneLifecycleStateMachine.mm +180 -0
- package/ios/View/HBDRootView.h +2 -0
- package/ios/View/HBDRootView.mm +148 -0
- package/ios/View/UIImage+WithBadge.h +3 -3
- package/ios/View/UIImage+WithBadge.mm +10 -15
- package/ios/ViewController/HBDDrawerController.mm +126 -5
- package/ios/ViewController/HBDNavigationController.mm +31 -4
- package/ios/ViewController/HBDReactViewController.h +6 -0
- package/ios/ViewController/HBDReactViewController.mm +220 -106
- package/ios/ViewController/HBDTabBarController.h +15 -0
- package/ios/ViewController/HBDTabBarController.mm +227 -45
- package/ios/ViewController/HBDTabBarRenderer.h +28 -0
- package/ios/ViewController/HBDViewController.h +11 -3
- package/ios/ViewController/HBDViewController.mm +209 -159
- package/ios/ViewController/UINavigationController+HBD.h +2 -2
- package/ios/ViewController/UINavigationController+HBD.mm +3 -3
- package/ios/ViewController/UIViewController+HBD.h +18 -10
- package/ios/ViewController/UIViewController+HBD.mm +90 -65
- package/package.json +3 -1
- package/src/DeepLink.ts +41 -14
- package/src/NativeEvent.ts +18 -11
- package/src/NativeNavigation.ts +29 -31
- package/src/Navigation.ts +377 -120
- package/src/NavigationComponentWrap.tsx +18 -9
- package/src/Navigator.ts +219 -152
- package/src/Options.ts +12 -3
- package/src/Route.ts +228 -17
- package/src/defineRoutes.ts +46 -0
- package/src/handler/DispatchCommandHandler.ts +154 -21
- package/src/handler/LayoutCommandHandler.ts +40 -17
- package/src/handler/LeaveGuardHandler.ts +436 -0
- package/src/handler/LifecycleEventHandler.ts +219 -0
- package/src/handler/PresentationCoordinator.ts +560 -0
- package/src/handler/ResultEventHandler.ts +126 -19
- package/src/handler/TabEventHandler.ts +31 -0
- package/src/hooks.ts +75 -7
- package/src/index.ts +37 -2
- package/src/reveal.ts +565 -0
- package/src/routeConfigRegistry.ts +26 -0
- package/src/routeGraph.ts +87 -0
- package/src/router/drawer.ts +8 -5
- package/src/router/index.ts +139 -63
- package/src/router/screen.ts +3 -3
- package/src/router/stack.ts +80 -29
- package/src/router/tabs.ts +16 -7
- package/src/store.ts +6 -1
- package/src/testing.ts +395 -0
- package/testing.d.ts +1 -0
- package/testing.js +3 -0
- package/android/src/main/java/androidx/fragment/app/InternalFragment.java +0 -22
- package/android/src/main/java/com/navigation/androidx/SystemUI30.java +0 -87
- package/android/src/main/java/com/reactnative/hybridnavigation/NativeGarden.java +0 -176
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBar.java +0 -130
- package/android/src/main/res/layout/nav_tab_bar_react.xml +0 -32
- package/android/src/main/res/layout/nav_tab_bar_react_indeterminate.xml +0 -32
- package/dist/NativeGarden.d.ts +0 -13
- package/dist/NativeGarden.js +0 -2
- package/dist/handler/VisibilityEventHandler.d.ts +0 -13
- package/dist/handler/VisibilityEventHandler.js +0 -39
- package/ios/GlobalStyle.h +0 -15
- package/ios/React/HBDNativeGarden.h +0 -10
- package/ios/React/HBDNativeGarden.mm +0 -111
- package/src/NativeGarden.ts +0 -16
- package/src/handler/VisibilityEventHandler.ts +0 -52
package/src/Navigator.ts
CHANGED
|
@@ -1,226 +1,293 @@
|
|
|
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
|
+
CloseSelfOptions,
|
|
12
|
+
DispatchResult,
|
|
13
|
+
Layout,
|
|
14
|
+
NavigationResult,
|
|
15
|
+
RouteName,
|
|
16
|
+
RouteResultOf,
|
|
17
|
+
SceneLifecycleState,
|
|
18
|
+
ScreenPropsArgs,
|
|
19
|
+
SetResultData,
|
|
20
|
+
Visibility,
|
|
21
|
+
} from './Route';
|
|
22
|
+
|
|
23
|
+
export const NavigationContext = createContext<Navigator<any> | null>(null);
|
|
17
24
|
|
|
18
25
|
let tagGenerator = 0;
|
|
19
26
|
|
|
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) {
|
|
27
|
+
export class Navigator<CurrentRoute extends RouteName = RouteName> {
|
|
28
|
+
static of<Name extends RouteName = RouteName>(sceneId: string): Navigator<Name> {
|
|
31
29
|
let navigator = store.getNavigator(sceneId);
|
|
32
30
|
if (!navigator) {
|
|
33
31
|
navigator = new Navigator(sceneId);
|
|
34
|
-
|
|
32
|
+
if (lifecycleHandler.getSceneState(sceneId) !== 'destroyed') {
|
|
33
|
+
store.addNavigator(sceneId, navigator);
|
|
34
|
+
}
|
|
35
35
|
}
|
|
36
|
-
return navigator
|
|
36
|
+
return navigator as unknown as Navigator<Name>;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
static
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
static async find(moduleName: string) {
|
|
45
|
-
const sceneId = await Navigation.findSceneIdByModuleName(moduleName);
|
|
39
|
+
static async find<Name extends RouteName = RouteName>(
|
|
40
|
+
moduleName: Name,
|
|
41
|
+
): Promise<Navigator<Name> | undefined> {
|
|
42
|
+
const sceneId = await NativeNavigation.findSceneIdByModuleName(moduleName);
|
|
46
43
|
if (sceneId) {
|
|
47
|
-
return Navigator.of(sceneId);
|
|
44
|
+
return Navigator.of<Name>(sceneId);
|
|
48
45
|
}
|
|
49
46
|
}
|
|
50
47
|
|
|
51
|
-
static async current(): Promise<Navigator> {
|
|
52
|
-
const route = await
|
|
48
|
+
static async current(): Promise<Navigator | undefined> {
|
|
49
|
+
const route = await NativeNavigation.currentRoute();
|
|
50
|
+
if (!route) {
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
53
|
return Navigator.of(route.sceneId);
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
constructor(public sceneId: string, public moduleName?: string) {}
|
|
57
57
|
|
|
58
|
-
visibility: Visibility
|
|
58
|
+
get visibility(): Visibility {
|
|
59
|
+
const state = lifecycleHandler.getSceneState(this.sceneId);
|
|
60
|
+
if (state === 'visible') {
|
|
61
|
+
return 'visible';
|
|
62
|
+
}
|
|
63
|
+
if (state === 'invisible' || state === 'destroyed') {
|
|
64
|
+
return 'invisible';
|
|
65
|
+
}
|
|
66
|
+
return 'pending';
|
|
67
|
+
}
|
|
59
68
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
69
|
+
get lifecycleState(): SceneLifecycleState {
|
|
70
|
+
return lifecycleHandler.getSceneState(this.sceneId);
|
|
71
|
+
}
|
|
63
72
|
|
|
64
|
-
|
|
65
|
-
|
|
73
|
+
private dispatchForResult = async <T = unknown>(
|
|
74
|
+
action: string,
|
|
75
|
+
params: Record<string, any>,
|
|
76
|
+
warnOnFailure?: (code: DispatchResult['code']) => string,
|
|
77
|
+
): Promise<NavigationResult<T>> => {
|
|
78
|
+
const requestCode = --tagGenerator;
|
|
79
|
+
const { promise: resultPromise, cancel } = resultHandler.prepareResult<T>(
|
|
80
|
+
this.sceneId,
|
|
81
|
+
requestCode,
|
|
82
|
+
);
|
|
83
|
+
let dispatchResult: DispatchResult;
|
|
84
|
+
try {
|
|
85
|
+
dispatchResult = await dispatchHandler.dispatch(this.sceneId, action, {
|
|
86
|
+
...params,
|
|
87
|
+
requestCode,
|
|
88
|
+
});
|
|
89
|
+
} catch (error) {
|
|
90
|
+
cancel();
|
|
91
|
+
throw error;
|
|
92
|
+
}
|
|
93
|
+
if (!dispatchResult.ok) {
|
|
94
|
+
cancel();
|
|
95
|
+
if (warnOnFailure) {
|
|
96
|
+
console.warn(warnOnFailure(dispatchResult.code));
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
status: 'blocked',
|
|
100
|
+
code: RESULT_BLOCK,
|
|
101
|
+
reason: dispatchResult.code,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
return resultPromise;
|
|
66
105
|
};
|
|
67
106
|
|
|
68
|
-
push = async <
|
|
69
|
-
moduleName:
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
107
|
+
push = async <Name extends RouteName = RouteName, T = RouteResultOf<Name>>(
|
|
108
|
+
moduleName: Name,
|
|
109
|
+
...args: ScreenPropsArgs<Name>
|
|
110
|
+
): Promise<NavigationResult<T>> => {
|
|
111
|
+
const [props = {}, options = {}] = args;
|
|
112
|
+
return this.dispatchForResult<T>('push', {
|
|
74
113
|
moduleName,
|
|
75
114
|
from: this.moduleName,
|
|
76
115
|
to: moduleName,
|
|
77
|
-
props,
|
|
116
|
+
props: props as object,
|
|
78
117
|
options,
|
|
79
118
|
});
|
|
80
|
-
if (!success) {
|
|
81
|
-
return [RESULT_BLOCK, null] as [number, T];
|
|
82
|
-
}
|
|
83
|
-
return Navigation.result<T>(this.sceneId, 0);
|
|
84
119
|
};
|
|
85
120
|
|
|
86
|
-
pushLayout = async <T
|
|
87
|
-
|
|
121
|
+
pushLayout = async <T = unknown>(
|
|
122
|
+
layout: BuildInLayout | Layout,
|
|
123
|
+
): Promise<NavigationResult<T>> => {
|
|
124
|
+
return this.dispatchForResult<T>('pushLayout', {
|
|
88
125
|
from: this.moduleName,
|
|
89
126
|
layout,
|
|
90
127
|
});
|
|
91
|
-
if (!success) {
|
|
92
|
-
return [RESULT_BLOCK, null] as [number, T];
|
|
93
|
-
}
|
|
94
|
-
return Navigation.result<T>(this.sceneId, 0);
|
|
95
128
|
};
|
|
96
129
|
|
|
97
|
-
pop = ()
|
|
130
|
+
pop = (): Promise<DispatchResult> =>
|
|
131
|
+
dispatchHandler.dispatch(this.sceneId, 'pop', { from: this.moduleName });
|
|
98
132
|
|
|
99
|
-
popTo = (
|
|
100
|
-
|
|
133
|
+
popTo = (
|
|
134
|
+
moduleName: RouteName | (string & {}),
|
|
135
|
+
inclusive: boolean = false,
|
|
136
|
+
): Promise<DispatchResult> =>
|
|
137
|
+
dispatchHandler.dispatch(this.sceneId, 'popTo', {
|
|
101
138
|
moduleName,
|
|
102
139
|
inclusive,
|
|
103
140
|
from: this.moduleName,
|
|
104
141
|
to: moduleName,
|
|
105
142
|
});
|
|
106
143
|
|
|
107
|
-
popToRoot = ()
|
|
144
|
+
popToRoot = (): Promise<DispatchResult> =>
|
|
145
|
+
dispatchHandler.dispatch(this.sceneId, 'popToRoot', { from: this.moduleName });
|
|
108
146
|
|
|
109
|
-
redirectTo = <
|
|
110
|
-
moduleName:
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
147
|
+
redirectTo = <Name extends RouteName = RouteName>(
|
|
148
|
+
moduleName: Name,
|
|
149
|
+
...args: ScreenPropsArgs<Name>
|
|
150
|
+
): Promise<DispatchResult> => {
|
|
151
|
+
const [props = {}, options = {}] = args;
|
|
152
|
+
return dispatchHandler.dispatch(this.sceneId, 'redirectTo', {
|
|
115
153
|
moduleName,
|
|
116
154
|
from: this.moduleName,
|
|
117
155
|
to: moduleName,
|
|
118
|
-
props,
|
|
156
|
+
props: props as object,
|
|
119
157
|
options,
|
|
120
158
|
});
|
|
159
|
+
};
|
|
121
160
|
|
|
122
|
-
present = async <
|
|
123
|
-
moduleName:
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
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);
|
|
161
|
+
present = async <Name extends RouteName = RouteName, T = RouteResultOf<Name>>(
|
|
162
|
+
moduleName: Name,
|
|
163
|
+
...args: ScreenPropsArgs<Name>
|
|
164
|
+
): Promise<NavigationResult<T>> => {
|
|
165
|
+
const [props = {}, options = {}] = args;
|
|
166
|
+
return this.dispatchForResult<T>(
|
|
167
|
+
'present',
|
|
168
|
+
{
|
|
169
|
+
moduleName,
|
|
170
|
+
from: this.moduleName,
|
|
171
|
+
to: moduleName,
|
|
172
|
+
props: props as object,
|
|
173
|
+
options,
|
|
174
|
+
},
|
|
175
|
+
code => `present from:${this.moduleName} to:${moduleName} failed (${code}).`,
|
|
176
|
+
);
|
|
143
177
|
};
|
|
144
178
|
|
|
145
|
-
presentLayout = async <T
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
return [RESULT_BLOCK, null] as [number, T];
|
|
157
|
-
}
|
|
158
|
-
return Navigation.result<T>(this.sceneId, requestCode);
|
|
179
|
+
presentLayout = async <T = unknown>(
|
|
180
|
+
layout: BuildInLayout | Layout,
|
|
181
|
+
): Promise<NavigationResult<T>> => {
|
|
182
|
+
return this.dispatchForResult<T>(
|
|
183
|
+
'presentLayout',
|
|
184
|
+
{
|
|
185
|
+
layout,
|
|
186
|
+
from: this.moduleName,
|
|
187
|
+
},
|
|
188
|
+
code => `presentLayout from:${this.moduleName} failed (${code}).`,
|
|
189
|
+
);
|
|
159
190
|
};
|
|
160
191
|
|
|
161
|
-
dismiss = ()
|
|
192
|
+
dismiss = (): Promise<DispatchResult> =>
|
|
193
|
+
dispatchHandler.dispatch(this.sceneId, 'dismiss', { from: this.moduleName });
|
|
162
194
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
) => {
|
|
168
|
-
const requestCode = --tagGenerator;
|
|
169
|
-
const success = await Navigation.dispatch(this.sceneId, 'showModal', {
|
|
170
|
-
moduleName,
|
|
195
|
+
closeSelf = (
|
|
196
|
+
options?: CloseSelfOptions<SetResultData<CurrentRoute>>,
|
|
197
|
+
): Promise<DispatchResult> => {
|
|
198
|
+
return dispatchHandler.dispatch(this.sceneId, 'close', {
|
|
171
199
|
from: this.moduleName,
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
options,
|
|
175
|
-
requestCode,
|
|
200
|
+
target: 'self',
|
|
201
|
+
onCovered: options?.onCovered,
|
|
202
|
+
...(options?.result !== undefined ? { result: options.result } : {}),
|
|
176
203
|
});
|
|
177
|
-
if (!success) {
|
|
178
|
-
console.warn(
|
|
179
|
-
`showModal from:${this.moduleName} to:${moduleName} failed. Maybe the screen (${this.moduleName}) already shows or present another screen.`,
|
|
180
|
-
);
|
|
181
|
-
return [RESULT_BLOCK, null] as [number, T];
|
|
182
|
-
}
|
|
183
|
-
return Navigation.result<T>(this.sceneId, requestCode);
|
|
184
204
|
};
|
|
185
205
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
206
|
+
showModal = async <Name extends RouteName = RouteName, T = RouteResultOf<Name>>(
|
|
207
|
+
moduleName: Name,
|
|
208
|
+
...args: ScreenPropsArgs<Name>
|
|
209
|
+
): Promise<NavigationResult<T>> => {
|
|
210
|
+
const [props = {}, options = {}] = args;
|
|
211
|
+
return this.dispatchForResult<T>(
|
|
212
|
+
'showModal',
|
|
213
|
+
{
|
|
214
|
+
moduleName,
|
|
215
|
+
from: this.moduleName,
|
|
216
|
+
to: moduleName,
|
|
217
|
+
props: props as object,
|
|
218
|
+
options,
|
|
219
|
+
},
|
|
220
|
+
code => `showModal from:${this.moduleName} to:${moduleName} failed (${code}).`,
|
|
221
|
+
);
|
|
200
222
|
};
|
|
201
223
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
224
|
+
showModalLayout = async <T = unknown>(
|
|
225
|
+
layout: BuildInLayout | Layout,
|
|
226
|
+
): Promise<NavigationResult<T>> => {
|
|
227
|
+
return this.dispatchForResult<T>(
|
|
228
|
+
'showModalLayout',
|
|
229
|
+
{
|
|
230
|
+
from: this.moduleName,
|
|
231
|
+
layout,
|
|
232
|
+
},
|
|
233
|
+
code => `showModalLayout from:${this.moduleName} failed (${code}).`,
|
|
234
|
+
);
|
|
235
|
+
};
|
|
206
236
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
237
|
+
hideModal = (): Promise<DispatchResult> =>
|
|
238
|
+
dispatchHandler.dispatch(this.sceneId, 'hideModal', { from: this.moduleName });
|
|
239
|
+
|
|
240
|
+
setResult = (
|
|
241
|
+
resultCode: number,
|
|
242
|
+
data: SetResultData<CurrentRoute> | null = null,
|
|
243
|
+
): void => resultHandler.setResult(this.sceneId, resultCode, data);
|
|
244
|
+
|
|
245
|
+
switchTab = async (
|
|
246
|
+
target: number | string,
|
|
247
|
+
popToRoot: boolean = false,
|
|
248
|
+
): Promise<DispatchResult> => {
|
|
249
|
+
const from = await NativeNavigation.currentTab(this.sceneId);
|
|
250
|
+
if (typeof target === 'string') {
|
|
251
|
+
return dispatchHandler.dispatch(this.sceneId, 'switchTab', {
|
|
252
|
+
from,
|
|
253
|
+
tabKey: target,
|
|
254
|
+
popToRoot,
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
return dispatchHandler.dispatch(this.sceneId, 'switchTab', {
|
|
210
258
|
from,
|
|
211
|
-
to:
|
|
259
|
+
to: target,
|
|
212
260
|
popToRoot,
|
|
213
261
|
});
|
|
214
262
|
};
|
|
215
263
|
|
|
216
|
-
toggleMenu = () =>
|
|
217
|
-
|
|
264
|
+
toggleMenu = (): Promise<DispatchResult> =>
|
|
265
|
+
dispatchHandler.dispatch(this.sceneId, 'toggleMenu', {
|
|
218
266
|
from: this.moduleName,
|
|
219
267
|
});
|
|
220
268
|
|
|
221
|
-
openMenu = ()
|
|
269
|
+
openMenu = (): Promise<DispatchResult> =>
|
|
270
|
+
dispatchHandler.dispatch(this.sceneId, 'openMenu', { from: this.moduleName });
|
|
222
271
|
|
|
223
|
-
closeMenu = ()
|
|
272
|
+
closeMenu = (): Promise<DispatchResult> =>
|
|
273
|
+
dispatchHandler.dispatch(this.sceneId, 'closeMenu', { from: this.moduleName });
|
|
274
|
+
|
|
275
|
+
setMenuInteractive = (enabled: boolean): Promise<DispatchResult> =>
|
|
276
|
+
dispatchHandler.dispatch(this.sceneId, 'setMenuInteractive', {
|
|
277
|
+
enabled,
|
|
278
|
+
from: this.moduleName,
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
updateOptions = (options: NavigationOption): void =>
|
|
282
|
+
NativeNavigation.updateOptions(this.sceneId, options);
|
|
283
|
+
|
|
284
|
+
updateTabBar = (options: TabBarStyle): void =>
|
|
285
|
+
NativeNavigation.updateTabBar(this.sceneId, options);
|
|
286
|
+
|
|
287
|
+
setTabItem = (item: TabItemInfo | TabItemInfo[]): void => {
|
|
288
|
+
const items = Array.isArray(item) ? item : [item];
|
|
289
|
+
NativeNavigation.setTabItem(this.sceneId, items);
|
|
290
|
+
};
|
|
224
291
|
|
|
225
|
-
isStackRoot = () =>
|
|
292
|
+
isStackRoot = () => NativeNavigation.isStackRoot(this.sceneId);
|
|
226
293
|
}
|
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,15 +22,16 @@ 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
|
|
|
32
33
|
export interface TabItem {
|
|
34
|
+
key?: string;
|
|
33
35
|
title: string;
|
|
34
36
|
icon?: ImageSource;
|
|
35
37
|
unselectedIcon?: ImageSource;
|
|
@@ -42,9 +44,13 @@ export interface ShadowImage {
|
|
|
42
44
|
|
|
43
45
|
export interface DefaultOptions {
|
|
44
46
|
screenBackgroundColor?: Color; // 页面背景,默认是白色
|
|
47
|
+
modalBackgroundColor?: Color; // 弹层默认背景,默认透明
|
|
48
|
+
injectInitialMetrics?: boolean; // 是否为同向全屏场景注入首帧安全区 initialMetrics(默认 false)
|
|
49
|
+
prewarmPush?: boolean; // 是否对有动画的同向全屏主栈 push 启用离屏 Fabric 首帧预热(默认 false)
|
|
45
50
|
statusBarStyle?: BarStyle; // 状态栏样式,可选项有 `BarStyleLightContent` 和 `BarStyleDarkContent`
|
|
46
51
|
navigationBarColorAndroid?: Color; // 底部虚拟键背景颜色,仅对 Android 8.0 以上版本生效
|
|
47
52
|
displayCutoutWhenLandscapeAndroid?: boolean; // 横屏时,是否将界面延伸至刘海区域,默认 true
|
|
53
|
+
orientation?: ScreenOrientation; // 默认全局方向策略,默认为 portrait
|
|
48
54
|
|
|
49
55
|
tabBarBackgroundColor?: Color; // 底部 TabBar 背景颜色,请勿使用带透明度的颜色。
|
|
50
56
|
tabBarShadowImage?: ShadowImage; // 底部 TabBar 阴影图片。对于 iOS, 只有同时设置了 tabBarBackgroundColor 才会生效
|
|
@@ -61,8 +67,7 @@ export type TabBarStyle = Pick<
|
|
|
61
67
|
| 'tabBarItemNormalColor'
|
|
62
68
|
>;
|
|
63
69
|
|
|
64
|
-
export interface
|
|
65
|
-
index: number;
|
|
70
|
+
export interface TabItemInfoBase {
|
|
66
71
|
title?: string;
|
|
67
72
|
badge?: {
|
|
68
73
|
text?: string;
|
|
@@ -74,3 +79,7 @@ export interface TabItemInfo {
|
|
|
74
79
|
unselected?: ImageSource;
|
|
75
80
|
};
|
|
76
81
|
}
|
|
82
|
+
|
|
83
|
+
export type TabItemInfo =
|
|
84
|
+
| (TabItemInfoBase & { index: number; key?: string })
|
|
85
|
+
| (TabItemInfoBase & { key: string; index?: number });
|