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
|
@@ -1,23 +1,32 @@
|
|
|
1
|
+
import type { CancelReason, NavigationResult, ResultMap } from '../Route';
|
|
1
2
|
import NativeEvent from '../NativeEvent';
|
|
3
|
+
import NativeNavigation from '../NativeNavigation';
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
[index: string]: any;
|
|
5
|
-
}
|
|
5
|
+
export const { RESULT_CANCEL, RESULT_OK, RESULT_BLOCK } = NativeNavigation.getConstants();
|
|
6
6
|
|
|
7
|
-
export type ResultType =
|
|
8
|
-
export type ResultEventListener<T
|
|
7
|
+
export type ResultType = unknown;
|
|
8
|
+
export type ResultEventListener<T = unknown> = (result: NavigationResult<T>) => void;
|
|
9
|
+
export type PreparedResult<T = unknown> = {
|
|
10
|
+
promise: Promise<NavigationResult<T>>;
|
|
11
|
+
cancel: () => void;
|
|
12
|
+
};
|
|
9
13
|
|
|
10
14
|
export default class ResultEventHandler {
|
|
11
15
|
private listenerRecords: Record<string, Record<number, Array<ResultEventListener<any>>>> = {};
|
|
12
16
|
|
|
13
|
-
constructor() {}
|
|
14
|
-
|
|
15
17
|
handleComponentResult() {
|
|
16
18
|
NativeEvent.onResult(({ sceneId, requestCode, resultCode, resultData }) => {
|
|
17
19
|
const listeners = this.listenerRecords[sceneId]?.[requestCode];
|
|
18
20
|
if (listeners) {
|
|
19
21
|
delete this.listenerRecords[sceneId][requestCode];
|
|
20
|
-
|
|
22
|
+
if (Object.keys(this.listenerRecords[sceneId]).length === 0) {
|
|
23
|
+
delete this.listenerRecords[sceneId];
|
|
24
|
+
}
|
|
25
|
+
const result: NavigationResult<any> =
|
|
26
|
+
resultCode === RESULT_CANCEL
|
|
27
|
+
? { status: 'cancel', code: RESULT_CANCEL, reason: 'dismissed' }
|
|
28
|
+
: { status: 'ok', code: resultCode, data: resultData };
|
|
29
|
+
listeners.forEach(l => l(result));
|
|
21
30
|
}
|
|
22
31
|
});
|
|
23
32
|
}
|
|
@@ -38,25 +47,123 @@ export default class ResultEventHandler {
|
|
|
38
47
|
this.listenerRecords[sceneId][requestCode].push(listener);
|
|
39
48
|
}
|
|
40
49
|
|
|
41
|
-
private removeResultEventListener(
|
|
42
|
-
|
|
43
|
-
|
|
50
|
+
private removeResultEventListener(
|
|
51
|
+
sceneId: string,
|
|
52
|
+
requestCode: number,
|
|
53
|
+
listener: ResultEventListener<any>,
|
|
54
|
+
) {
|
|
55
|
+
const sceneRecords = this.listenerRecords[sceneId];
|
|
56
|
+
const listeners = sceneRecords?.[requestCode];
|
|
57
|
+
if (!listeners) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const nextListeners = listeners.filter(l => l !== listener);
|
|
62
|
+
if (nextListeners.length > 0) {
|
|
63
|
+
sceneRecords[requestCode] = nextListeners;
|
|
64
|
+
} else {
|
|
65
|
+
delete sceneRecords[requestCode];
|
|
66
|
+
if (Object.keys(sceneRecords).length === 0) {
|
|
67
|
+
delete this.listenerRecords[sceneId];
|
|
68
|
+
}
|
|
44
69
|
}
|
|
45
70
|
}
|
|
46
71
|
|
|
47
|
-
invalidateResultEventListener(sceneId: string) {
|
|
48
|
-
|
|
49
|
-
|
|
72
|
+
invalidateResultEventListener(sceneId: string, reason: CancelReason = 'unmounted') {
|
|
73
|
+
const sceneRecords = this.listenerRecords[sceneId];
|
|
74
|
+
if (!sceneRecords) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
delete this.listenerRecords[sceneId];
|
|
78
|
+
const cancelled: NavigationResult<never> = {
|
|
79
|
+
status: 'cancel',
|
|
80
|
+
code: RESULT_CANCEL,
|
|
81
|
+
reason,
|
|
82
|
+
};
|
|
83
|
+
for (const listeners of Object.values(sceneRecords)) {
|
|
84
|
+
listeners.forEach(l => l(cancelled));
|
|
50
85
|
}
|
|
51
86
|
}
|
|
52
87
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
88
|
+
invalidateAll(reason: CancelReason = 'root_reset') {
|
|
89
|
+
const allRecords = this.listenerRecords;
|
|
90
|
+
this.listenerRecords = {};
|
|
91
|
+
const cancelled: NavigationResult<never> = {
|
|
92
|
+
status: 'cancel',
|
|
93
|
+
code: RESULT_CANCEL,
|
|
94
|
+
reason,
|
|
95
|
+
};
|
|
96
|
+
for (const sceneRecords of Object.values(allRecords)) {
|
|
97
|
+
for (const listeners of Object.values(sceneRecords)) {
|
|
98
|
+
listeners.forEach(l => l(cancelled));
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
prepareResult<T = unknown>(sceneId: string, requestCode: number): PreparedResult<T> {
|
|
104
|
+
let settled = false;
|
|
105
|
+
let listenerRef: ResultEventListener<T> | undefined;
|
|
106
|
+
const promise = new Promise<NavigationResult<T>>(resolve => {
|
|
107
|
+
const listener: ResultEventListener<T> = result => {
|
|
108
|
+
if (settled) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
settled = true;
|
|
112
|
+
this.removeResultEventListener(sceneId, requestCode, listener);
|
|
113
|
+
resolve(result);
|
|
58
114
|
};
|
|
115
|
+
listenerRef = listener;
|
|
59
116
|
this.addResultEventListener(sceneId, requestCode, listener);
|
|
60
117
|
});
|
|
118
|
+
|
|
119
|
+
const cancel = () => {
|
|
120
|
+
if (settled) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
settled = true;
|
|
124
|
+
if (listenerRef) {
|
|
125
|
+
this.removeResultEventListener(sceneId, requestCode, listenerRef);
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
return { promise, cancel };
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
normalizePendingResult<T extends ResultMap = ResultMap>(pending: {
|
|
133
|
+
code: number;
|
|
134
|
+
data?: T | null;
|
|
135
|
+
}): { code: number; data: T | null } {
|
|
136
|
+
const { code } = pending;
|
|
137
|
+
const data = pending.data ?? null;
|
|
138
|
+
if (code < RESULT_OK) {
|
|
139
|
+
console.warn(
|
|
140
|
+
'`resultCode` can only be `RESULT_OK`, `RESULT_CANCEL` or an integer greater than 0.',
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
if (__DEV__ && code === RESULT_CANCEL && data !== null && data !== undefined) {
|
|
144
|
+
console.warn(
|
|
145
|
+
'[hybrid-navigation] `RESULT_CANCEL` ignores `data` because `RESULT_CANCEL` always resolves as `{ status: "cancel" }`. Pass `null` or use `RESULT_OK` to return data.',
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
if (data !== null && (typeof data !== 'object' || Array.isArray(data))) {
|
|
149
|
+
console.warn('`setResult` data must be a plain object or null.');
|
|
150
|
+
return { code, data: null };
|
|
151
|
+
}
|
|
152
|
+
return { code, data };
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
setResult<T extends ResultMap = ResultMap>(
|
|
156
|
+
sceneId: string,
|
|
157
|
+
resultCode: number,
|
|
158
|
+
data: T | null = null,
|
|
159
|
+
): void {
|
|
160
|
+
const normalized = this.normalizePendingResult({ code: resultCode, data });
|
|
161
|
+
NativeNavigation.setResult(sceneId, normalized.code, normalized.data);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
waitResult<T = unknown>(sceneId: string, requestCode: number): Promise<NavigationResult<T>> {
|
|
165
|
+
return this.prepareResult<T>(sceneId, requestCode).promise;
|
|
61
166
|
}
|
|
62
167
|
}
|
|
168
|
+
|
|
169
|
+
export const resultHandler = new ResultEventHandler();
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import NativeEvent from '../NativeEvent';
|
|
2
|
+
import type { TabPressEvent, TabPressListener } from '../Route';
|
|
3
|
+
|
|
4
|
+
export default class TabEventHandler {
|
|
5
|
+
private listeners: TabPressListener[] = [];
|
|
6
|
+
|
|
7
|
+
handleTabPress() {
|
|
8
|
+
NativeEvent.onTabPress(({ index, tabKey, previousIndex, reselected }) => {
|
|
9
|
+
const event: TabPressEvent = {
|
|
10
|
+
index,
|
|
11
|
+
tabKey,
|
|
12
|
+
previousIndex,
|
|
13
|
+
reselected: Boolean(reselected),
|
|
14
|
+
};
|
|
15
|
+
this.listeners.slice().forEach(listener => listener(event));
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
addListener(listener: TabPressListener): () => void {
|
|
20
|
+
this.listeners.push(listener);
|
|
21
|
+
return () => {
|
|
22
|
+
this.listeners = this.listeners.filter(item => item !== listener);
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
clearListeners() {
|
|
27
|
+
this.listeners = [];
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const tabEventHandler = new TabEventHandler();
|
package/src/hooks.ts
CHANGED
|
@@ -1,17 +1,81 @@
|
|
|
1
|
-
import { useContext, useEffect, useEffectEvent } from 'react';
|
|
1
|
+
import { useContext, useEffect, useEffectEvent, useState } from 'react';
|
|
2
2
|
import Navigation from './Navigation';
|
|
3
3
|
import { Navigator, NavigationContext } from './Navigator';
|
|
4
|
+
import type {
|
|
5
|
+
BeforeRemoveListener,
|
|
6
|
+
BeforeRemoveOptions,
|
|
7
|
+
RouteName,
|
|
8
|
+
SceneLifecycleState,
|
|
9
|
+
} from './Route';
|
|
4
10
|
|
|
5
|
-
export
|
|
6
|
-
|
|
11
|
+
export type VisibleEffectCallback = () => void | (() => void);
|
|
12
|
+
|
|
13
|
+
export function useNavigator<Name extends RouteName = RouteName>(): Navigator<Name> {
|
|
14
|
+
const navigator = useContext<Navigator<Name> | null>(NavigationContext);
|
|
15
|
+
if (!navigator) {
|
|
16
|
+
throw new Error(
|
|
17
|
+
'[hybrid-navigation] useNavigator() must be used inside a screen registered with Navigation.registerComponent().',
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
return navigator;
|
|
7
21
|
}
|
|
8
22
|
|
|
9
|
-
export function
|
|
23
|
+
export function useSceneState(): SceneLifecycleState {
|
|
24
|
+
const navigator = useNavigator();
|
|
25
|
+
const [state, setState] = useState<SceneLifecycleState>(() =>
|
|
26
|
+
Navigation.getSceneState(navigator.sceneId),
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
setState(Navigation.getSceneState(navigator.sceneId));
|
|
31
|
+
const subscription = Navigation.addLifecycleListener(navigator.sceneId, nextState => {
|
|
32
|
+
setState(nextState);
|
|
33
|
+
});
|
|
34
|
+
return () => {
|
|
35
|
+
subscription.remove();
|
|
36
|
+
};
|
|
37
|
+
}, [navigator.sceneId]);
|
|
38
|
+
|
|
39
|
+
return state;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function useIsVisible(): boolean {
|
|
43
|
+
return useSceneState() === 'visible';
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function useBeforeRemove(
|
|
47
|
+
enabled: boolean,
|
|
48
|
+
onBeforeRemove: BeforeRemoveListener,
|
|
49
|
+
options?: BeforeRemoveOptions,
|
|
50
|
+
) {
|
|
51
|
+
const navigator = useNavigator();
|
|
52
|
+
const eventCallback = useEffectEvent(onBeforeRemove);
|
|
53
|
+
const actionsKey = options?.actions ? options.actions.join(',') : '';
|
|
54
|
+
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
if (!enabled) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const actions = actionsKey
|
|
60
|
+
? (actionsKey.split(',') as NonNullable<BeforeRemoveOptions['actions']>)
|
|
61
|
+
: undefined;
|
|
62
|
+
const subscription = Navigation.addBeforeRemoveListener(
|
|
63
|
+
navigator.sceneId,
|
|
64
|
+
event => eventCallback(event),
|
|
65
|
+
actions ? { actions } : undefined,
|
|
66
|
+
);
|
|
67
|
+
return () => {
|
|
68
|
+
subscription.remove();
|
|
69
|
+
};
|
|
70
|
+
}, [enabled, navigator.sceneId, actionsKey]);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function useVisibleEffect(callback: VisibleEffectCallback) {
|
|
10
74
|
const navigator = useNavigator();
|
|
11
75
|
const event = useEffectEvent(callback);
|
|
12
76
|
|
|
13
77
|
useEffect(() => {
|
|
14
|
-
let destructor: (() => void) |
|
|
78
|
+
let destructor: (() => void) | void;
|
|
15
79
|
if (navigator.visibility === 'visible') {
|
|
16
80
|
destructor = event();
|
|
17
81
|
}
|
|
@@ -19,13 +83,17 @@ export function useVisibleEffect<T extends Function>(callback: T) {
|
|
|
19
83
|
if (v === 'visible') {
|
|
20
84
|
destructor = event();
|
|
21
85
|
} else {
|
|
22
|
-
destructor
|
|
86
|
+
if (typeof destructor === 'function') {
|
|
87
|
+
destructor();
|
|
88
|
+
}
|
|
23
89
|
destructor = undefined;
|
|
24
90
|
}
|
|
25
91
|
});
|
|
26
92
|
return () => {
|
|
27
93
|
subscription.remove();
|
|
28
|
-
destructor
|
|
94
|
+
if (typeof destructor === 'function') {
|
|
95
|
+
destructor();
|
|
96
|
+
}
|
|
29
97
|
};
|
|
30
98
|
}, [navigator]);
|
|
31
99
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,17 +1,52 @@
|
|
|
1
|
-
import { withNavigation } from './NavigationComponentWrap';
|
|
2
1
|
import navigation from './Navigation';
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Augment this interface via `declare module 'hybrid-navigation'` to enable
|
|
5
|
+
* strongly typed route names, props, and navigation results.
|
|
6
|
+
*/
|
|
7
|
+
export interface NavigationParamList {}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Augment this interface via `declare module 'hybrid-navigation'` to configure
|
|
11
|
+
* route type checking. Set `allowUnregisteredRoutes: true` during incremental
|
|
12
|
+
* migration so declared routes get strict checking while unmigrated routes
|
|
13
|
+
* remain accepted as `string & {}`.
|
|
14
|
+
*/
|
|
15
|
+
export interface NavigationTypeConfig {}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Augment this interface via `declare module 'hybrid-navigation'` to register
|
|
19
|
+
* strongly typed custom container layouts alongside built-in layouts.
|
|
20
|
+
*/
|
|
21
|
+
export interface CustomLayoutMap {}
|
|
22
|
+
|
|
5
23
|
const Navigation = navigation;
|
|
6
24
|
export default Navigation;
|
|
7
25
|
|
|
8
26
|
export { RESULT_OK, RESULT_CANCEL, RESULT_BLOCK } from './Navigation';
|
|
27
|
+
export type {
|
|
28
|
+
DispatchParams,
|
|
29
|
+
GlobalSceneLifecycleListener,
|
|
30
|
+
GlobalVisibilityEventListener,
|
|
31
|
+
HOC,
|
|
32
|
+
InterceptParams,
|
|
33
|
+
Navigation,
|
|
34
|
+
NavigationInterceptor,
|
|
35
|
+
NavigationSubscription,
|
|
36
|
+
ResultType,
|
|
37
|
+
RootLayoutListener,
|
|
38
|
+
SceneLifecycleListener,
|
|
39
|
+
VisibilityEventListener,
|
|
40
|
+
} from './Navigation';
|
|
9
41
|
export { withNavigationItem } from './NavigationComponentWrap';
|
|
10
42
|
export type { NavigationProps } from './NavigationComponentWrap';
|
|
11
43
|
|
|
12
44
|
export * from './Navigator';
|
|
13
45
|
export * from './hooks';
|
|
14
46
|
export * from './router';
|
|
47
|
+
export * from './routeGraph';
|
|
48
|
+
export * from './reveal';
|
|
49
|
+
export * from './defineRoutes';
|
|
15
50
|
export * from './DeepLink';
|
|
16
51
|
export * from './Route';
|
|
17
52
|
export * from './Options';
|