react-native-screen-transitions 3.0.0-rc.2 → 3.0.0-rc.3
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/README.md +421 -371
- package/lib/commonjs/blank-stack/components/{Overlay.js → overlay.js} +7 -5
- package/lib/commonjs/blank-stack/components/overlay.js.map +1 -0
- package/lib/commonjs/blank-stack/components/{Screens.js → screens.js} +8 -10
- package/lib/commonjs/blank-stack/components/screens.js.map +1 -0
- package/lib/commonjs/blank-stack/components/stack-view.js +95 -0
- package/lib/commonjs/blank-stack/components/stack-view.js.map +1 -0
- package/lib/commonjs/blank-stack/index.js +1 -8
- package/lib/commonjs/blank-stack/index.js.map +1 -1
- package/lib/commonjs/blank-stack/navigators/{createBlankStackNavigator.js → create-blank-stack-navigator.js} +3 -3
- package/lib/commonjs/blank-stack/navigators/create-blank-stack-navigator.js.map +1 -0
- package/lib/commonjs/blank-stack/utils/with-stack-navigation/helpers/compose-descriptors.js +1 -11
- package/lib/commonjs/blank-stack/utils/with-stack-navigation/helpers/compose-descriptors.js.map +1 -1
- package/lib/commonjs/blank-stack/utils/with-stack-navigation/hooks/use-closing-route-keys.js +1 -12
- package/lib/commonjs/blank-stack/utils/with-stack-navigation/hooks/use-closing-route-keys.js.map +1 -1
- package/lib/commonjs/blank-stack/utils/with-stack-navigation/hooks/use-stack-navigation-state.js.map +1 -1
- package/lib/commonjs/blank-stack/utils/with-stack-navigation/index.js +49 -55
- package/lib/commonjs/blank-stack/utils/with-stack-navigation/index.js.map +1 -1
- package/lib/commonjs/blank-stack/utils/with-stack-navigation/{_types.js → types.js} +1 -1
- package/lib/commonjs/blank-stack/utils/with-stack-navigation/types.js.map +1 -0
- package/lib/commonjs/shared/hooks/animation/use-screen-animation.js +38 -22
- package/lib/commonjs/shared/hooks/animation/use-screen-animation.js.map +1 -1
- package/lib/commonjs/shared/hooks/gestures/use-build-gestures.js.map +1 -1
- package/lib/commonjs/shared/providers/flags.provider.js +25 -0
- package/lib/commonjs/shared/providers/flags.provider.js.map +1 -0
- package/lib/commonjs/shared/providers/register-bounds.provider.js +71 -45
- package/lib/commonjs/shared/providers/register-bounds.provider.js.map +1 -1
- package/lib/commonjs/shared/stores/bounds.store.js +91 -47
- package/lib/commonjs/shared/stores/bounds.store.js.map +1 -1
- package/lib/commonjs/shared/utils/bounds/helpers/is-bounds-equal.js +1 -1
- package/lib/commonjs/shared/utils/bounds/helpers/is-bounds-equal.js.map +1 -1
- package/lib/commonjs/shared/utils/bounds/index.js +4 -5
- package/lib/commonjs/shared/utils/bounds/index.js.map +1 -1
- package/lib/commonjs/shared/utils/create-provider.js +20 -1
- package/lib/commonjs/shared/utils/create-provider.js.map +1 -1
- package/lib/commonjs/shared/utils/reset-stores-for-screen.js +2 -0
- package/lib/commonjs/shared/utils/reset-stores-for-screen.js.map +1 -1
- package/lib/module/blank-stack/components/{Overlay.js → overlay.js} +7 -5
- package/lib/module/blank-stack/components/overlay.js.map +1 -0
- package/lib/module/blank-stack/components/{Screens.js → screens.js} +8 -10
- package/lib/module/blank-stack/components/screens.js.map +1 -0
- package/lib/module/blank-stack/components/stack-view.js +90 -0
- package/lib/module/blank-stack/components/stack-view.js.map +1 -0
- package/lib/module/blank-stack/index.js +1 -2
- package/lib/module/blank-stack/index.js.map +1 -1
- package/lib/module/blank-stack/navigators/{createBlankStackNavigator.js → create-blank-stack-navigator.js} +2 -2
- package/lib/module/blank-stack/navigators/create-blank-stack-navigator.js.map +1 -0
- package/lib/module/blank-stack/utils/with-stack-navigation/helpers/compose-descriptors.js +1 -11
- package/lib/module/blank-stack/utils/with-stack-navigation/helpers/compose-descriptors.js.map +1 -1
- package/lib/module/blank-stack/utils/with-stack-navigation/hooks/use-closing-route-keys.js +1 -12
- package/lib/module/blank-stack/utils/with-stack-navigation/hooks/use-closing-route-keys.js.map +1 -1
- package/lib/module/blank-stack/utils/with-stack-navigation/hooks/use-stack-navigation-state.js.map +1 -1
- package/lib/module/blank-stack/utils/with-stack-navigation/index.js +48 -54
- package/lib/module/blank-stack/utils/with-stack-navigation/index.js.map +1 -1
- package/lib/module/blank-stack/utils/with-stack-navigation/types.js +4 -0
- package/lib/module/blank-stack/utils/with-stack-navigation/types.js.map +1 -0
- package/lib/module/shared/hooks/animation/use-screen-animation.js +38 -22
- package/lib/module/shared/hooks/animation/use-screen-animation.js.map +1 -1
- package/lib/module/shared/hooks/gestures/use-build-gestures.js.map +1 -1
- package/lib/module/shared/providers/flags.provider.js +19 -0
- package/lib/module/shared/providers/flags.provider.js.map +1 -0
- package/lib/module/shared/providers/register-bounds.provider.js +71 -45
- package/lib/module/shared/providers/register-bounds.provider.js.map +1 -1
- package/lib/module/shared/stores/bounds.store.js +91 -47
- package/lib/module/shared/stores/bounds.store.js.map +1 -1
- package/lib/module/shared/utils/bounds/helpers/is-bounds-equal.js +1 -1
- package/lib/module/shared/utils/bounds/helpers/is-bounds-equal.js.map +1 -1
- package/lib/module/shared/utils/bounds/index.js +4 -5
- package/lib/module/shared/utils/bounds/index.js.map +1 -1
- package/lib/module/shared/utils/create-provider.js +20 -1
- package/lib/module/shared/utils/create-provider.js.map +1 -1
- package/lib/module/shared/utils/reset-stores-for-screen.js +2 -0
- package/lib/module/shared/utils/reset-stores-for-screen.js.map +1 -1
- package/lib/typescript/blank-stack/components/{Overlay.d.ts → overlay.d.ts} +1 -1
- package/lib/typescript/blank-stack/components/overlay.d.ts.map +1 -0
- package/lib/typescript/blank-stack/components/{Screens.d.ts → screens.d.ts} +1 -1
- package/lib/typescript/blank-stack/components/{Screens.d.ts.map → screens.d.ts.map} +1 -1
- package/lib/typescript/blank-stack/components/stack-view.d.ts +3 -0
- package/lib/typescript/blank-stack/components/stack-view.d.ts.map +1 -0
- package/lib/typescript/blank-stack/index.d.ts +1 -2
- package/lib/typescript/blank-stack/index.d.ts.map +1 -1
- package/lib/typescript/blank-stack/navigators/{createBlankStackNavigator.d.ts → create-blank-stack-navigator.d.ts} +1 -1
- package/lib/typescript/blank-stack/navigators/create-blank-stack-navigator.d.ts.map +1 -0
- package/lib/typescript/blank-stack/types.d.ts +4 -0
- package/lib/typescript/blank-stack/types.d.ts.map +1 -1
- package/lib/typescript/blank-stack/utils/with-stack-navigation/helpers/compose-descriptors.d.ts.map +1 -1
- package/lib/typescript/blank-stack/utils/with-stack-navigation/hooks/use-closing-route-keys.d.ts.map +1 -1
- package/lib/typescript/blank-stack/utils/with-stack-navigation/hooks/use-stack-navigation-state.d.ts +1 -1
- package/lib/typescript/blank-stack/utils/with-stack-navigation/hooks/use-stack-navigation-state.d.ts.map +1 -1
- package/lib/typescript/blank-stack/utils/with-stack-navigation/index.d.ts +3 -5
- package/lib/typescript/blank-stack/utils/with-stack-navigation/index.d.ts.map +1 -1
- package/lib/typescript/blank-stack/utils/with-stack-navigation/{_types.d.ts → types.d.ts} +1 -1
- package/lib/typescript/blank-stack/utils/with-stack-navigation/types.d.ts.map +1 -0
- package/lib/typescript/shared/hooks/animation/use-screen-animation.d.ts.map +1 -1
- package/lib/typescript/shared/hooks/gestures/use-build-gestures.d.ts.map +1 -1
- package/lib/typescript/shared/index.d.ts +20 -20
- package/lib/typescript/shared/providers/flags.provider.d.ts +10 -0
- package/lib/typescript/shared/providers/flags.provider.d.ts.map +1 -0
- package/lib/typescript/shared/providers/register-bounds.provider.d.ts.map +1 -1
- package/lib/typescript/shared/stores/bounds.store.d.ts +23 -11
- package/lib/typescript/shared/stores/bounds.store.d.ts.map +1 -1
- package/lib/typescript/shared/types/bounds.types.d.ts +2 -2
- package/lib/typescript/shared/types/bounds.types.d.ts.map +1 -1
- package/lib/typescript/shared/utils/bounds/index.d.ts.map +1 -1
- package/lib/typescript/shared/utils/create-provider.d.ts +2 -2
- package/lib/typescript/shared/utils/create-provider.d.ts.map +1 -1
- package/lib/typescript/shared/utils/reset-stores-for-screen.d.ts.map +1 -1
- package/package.json +2 -1
- package/src/blank-stack/components/{Overlay.tsx → overlay.tsx} +4 -3
- package/src/blank-stack/components/{Screens.tsx → screens.tsx} +7 -9
- package/src/blank-stack/components/stack-view.tsx +104 -0
- package/src/blank-stack/index.ts +1 -2
- package/src/blank-stack/navigators/{createBlankStackNavigator.tsx → create-blank-stack-navigator.tsx} +1 -1
- package/src/blank-stack/types.ts +5 -7
- package/src/blank-stack/utils/with-stack-navigation/helpers/compose-descriptors.ts +1 -8
- package/src/blank-stack/utils/with-stack-navigation/hooks/use-closing-route-keys.tsx +1 -12
- package/src/blank-stack/utils/with-stack-navigation/hooks/use-stack-navigation-state.tsx +1 -1
- package/src/blank-stack/utils/with-stack-navigation/index.tsx +42 -62
- package/src/shared/__tests__/bounds.store.test.ts +398 -167
- package/src/shared/__tests__/determine-dismissal.test.ts +2 -12
- package/src/shared/__tests__/geometry.test.ts +1 -1
- package/src/shared/__tests__/gesture.velocity.test.ts +2 -10
- package/src/shared/hooks/animation/use-screen-animation.tsx +55 -29
- package/src/shared/hooks/gestures/use-build-gestures.tsx +4 -1
- package/src/shared/providers/flags.provider.tsx +21 -0
- package/src/shared/providers/register-bounds.provider.tsx +85 -54
- package/src/shared/stores/bounds.store.ts +90 -54
- package/src/shared/types/bounds.types.ts +2 -2
- package/src/shared/utils/bounds/helpers/is-bounds-equal.ts +1 -1
- package/src/shared/utils/bounds/index.ts +7 -10
- package/src/shared/utils/create-provider.tsx +35 -1
- package/src/shared/utils/reset-stores-for-screen.ts +2 -0
- package/lib/commonjs/blank-stack/components/Overlay.js.map +0 -1
- package/lib/commonjs/blank-stack/components/Screens.js.map +0 -1
- package/lib/commonjs/blank-stack/components/StackView.js +0 -93
- package/lib/commonjs/blank-stack/components/StackView.js.map +0 -1
- package/lib/commonjs/blank-stack/navigators/createBlankStackNavigator.js.map +0 -1
- package/lib/commonjs/blank-stack/utils/with-stack-navigation/_types.js.map +0 -1
- package/lib/module/blank-stack/components/Overlay.js.map +0 -1
- package/lib/module/blank-stack/components/Screens.js.map +0 -1
- package/lib/module/blank-stack/components/StackView.js +0 -88
- package/lib/module/blank-stack/components/StackView.js.map +0 -1
- package/lib/module/blank-stack/navigators/createBlankStackNavigator.js.map +0 -1
- package/lib/module/blank-stack/utils/with-stack-navigation/_types.js +0 -4
- package/lib/module/blank-stack/utils/with-stack-navigation/_types.js.map +0 -1
- package/lib/typescript/blank-stack/components/Overlay.d.ts.map +0 -1
- package/lib/typescript/blank-stack/components/StackView.d.ts +0 -2
- package/lib/typescript/blank-stack/components/StackView.d.ts.map +0 -1
- package/lib/typescript/blank-stack/navigators/createBlankStackNavigator.d.ts.map +0 -1
- package/lib/typescript/blank-stack/utils/with-stack-navigation/_types.d.ts.map +0 -1
- package/src/blank-stack/components/StackView.tsx +0 -108
- /package/src/blank-stack/utils/with-stack-navigation/{_types.ts → types.ts} +0 -0
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { SafeAreaProviderCompat } from "@react-navigation/elements";
|
|
2
|
+
import {
|
|
3
|
+
NavigationContext,
|
|
4
|
+
NavigationRouteContext,
|
|
5
|
+
} from "@react-navigation/native";
|
|
6
|
+
import * as React from "react";
|
|
7
|
+
import { StyleSheet } from "react-native";
|
|
8
|
+
import { GestureHandlerRootView } from "react-native-gesture-handler";
|
|
9
|
+
import { ScreenContainer } from "react-native-screens";
|
|
10
|
+
import { BlankStackScreenLifecycleController } from "../../shared/components/controllers/screen-lifecycle";
|
|
11
|
+
import { FlagsProvider } from "../../shared/providers/flags.provider";
|
|
12
|
+
import { ScreenTransitionProvider } from "../../shared/providers/screen-transition.provider";
|
|
13
|
+
import type { BlankStackDescriptor } from "../types";
|
|
14
|
+
import { withStackNavigationProvider } from "../utils/with-stack-navigation";
|
|
15
|
+
import { Overlay } from "./overlay";
|
|
16
|
+
import { Screen } from "./screens";
|
|
17
|
+
|
|
18
|
+
function isFabric() {
|
|
19
|
+
return "nativeFabricUIManager" in global;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
type SceneViewProps = {
|
|
23
|
+
descriptor: BlankStackDescriptor;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const SceneView = React.memo(({ descriptor }: SceneViewProps) => {
|
|
27
|
+
const { route, navigation, render } = descriptor;
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<NavigationContext.Provider value={navigation}>
|
|
31
|
+
<NavigationRouteContext.Provider value={route}>
|
|
32
|
+
{descriptor.options.overlayMode === "screen" && <Overlay.Screen />}
|
|
33
|
+
{render()}
|
|
34
|
+
</NavigationRouteContext.Provider>
|
|
35
|
+
</NavigationContext.Provider>
|
|
36
|
+
);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
export const StackView = withStackNavigationProvider(
|
|
40
|
+
({
|
|
41
|
+
activeScreensLimit,
|
|
42
|
+
descriptors,
|
|
43
|
+
focusedIndex,
|
|
44
|
+
routes,
|
|
45
|
+
scenes,
|
|
46
|
+
shouldShowFloatOverlay,
|
|
47
|
+
}) => {
|
|
48
|
+
return (
|
|
49
|
+
<FlagsProvider TRANSITIONS_ALWAYS_ON>
|
|
50
|
+
<GestureHandlerRootView>
|
|
51
|
+
<SafeAreaProviderCompat>
|
|
52
|
+
{shouldShowFloatOverlay ? <Overlay.Float /> : null}
|
|
53
|
+
<ScreenContainer style={styles.container}>
|
|
54
|
+
{scenes.map((scene, sceneIndex) => {
|
|
55
|
+
const descriptor = scene.descriptor;
|
|
56
|
+
const route = scene.route;
|
|
57
|
+
const isFocused = focusedIndex === sceneIndex;
|
|
58
|
+
const isBelowFocused = focusedIndex - 1 === sceneIndex;
|
|
59
|
+
|
|
60
|
+
const previousDescriptor =
|
|
61
|
+
scenes[sceneIndex - 1]?.descriptor ?? undefined;
|
|
62
|
+
const nextDescriptor =
|
|
63
|
+
scenes[sceneIndex + 1]?.descriptor ?? undefined;
|
|
64
|
+
|
|
65
|
+
const isPreloaded = descriptors[route.key] === undefined;
|
|
66
|
+
|
|
67
|
+
// On Fabric, when screen is frozen, animated and reanimated values are not updated
|
|
68
|
+
// due to component being unmounted. To avoid this, we don't freeze the previous screen there
|
|
69
|
+
const shouldFreeze = isFabric()
|
|
70
|
+
? !isPreloaded && !isFocused && !isBelowFocused
|
|
71
|
+
: !isPreloaded && !isFocused;
|
|
72
|
+
return (
|
|
73
|
+
<Screen
|
|
74
|
+
key={route.key}
|
|
75
|
+
isPreloaded={isPreloaded}
|
|
76
|
+
index={sceneIndex}
|
|
77
|
+
activeScreensLimit={activeScreensLimit}
|
|
78
|
+
routeKey={route.key}
|
|
79
|
+
routesLength={routes.length}
|
|
80
|
+
shouldFreeze={shouldFreeze}
|
|
81
|
+
freezeOnBlur={descriptor.options.freezeOnBlur}
|
|
82
|
+
>
|
|
83
|
+
<ScreenTransitionProvider
|
|
84
|
+
previous={previousDescriptor}
|
|
85
|
+
current={descriptor}
|
|
86
|
+
next={nextDescriptor}
|
|
87
|
+
LifecycleController={BlankStackScreenLifecycleController}
|
|
88
|
+
>
|
|
89
|
+
<SceneView key={route.key} descriptor={descriptor} />
|
|
90
|
+
</ScreenTransitionProvider>
|
|
91
|
+
</Screen>
|
|
92
|
+
);
|
|
93
|
+
})}
|
|
94
|
+
</ScreenContainer>
|
|
95
|
+
</SafeAreaProviderCompat>
|
|
96
|
+
</GestureHandlerRootView>
|
|
97
|
+
</FlagsProvider>
|
|
98
|
+
);
|
|
99
|
+
},
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
const styles = StyleSheet.create({
|
|
103
|
+
container: { flex: 1 },
|
|
104
|
+
});
|
package/src/blank-stack/index.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { createBlankStackNavigator } from "../blank-stack/navigators/createBlankStackNavigator";
|
|
1
|
+
export { createBlankStackNavigator } from "../blank-stack/navigators/create-blank-stack-navigator";
|
|
3
2
|
export type {
|
|
4
3
|
BlankStackNavigationEventMap,
|
|
5
4
|
BlankStackNavigationOptions,
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
useNavigationBuilder,
|
|
14
14
|
} from "@react-navigation/native";
|
|
15
15
|
import * as React from "react";
|
|
16
|
-
import { StackView } from "../components/
|
|
16
|
+
import { StackView } from "../components/stack-view";
|
|
17
17
|
import type {
|
|
18
18
|
BlankStackNavigationEventMap,
|
|
19
19
|
BlankStackNavigationOptions,
|
package/src/blank-stack/types.ts
CHANGED
|
@@ -12,18 +12,11 @@ import type {
|
|
|
12
12
|
Theme,
|
|
13
13
|
} from "@react-navigation/native";
|
|
14
14
|
import type { DerivedValue } from "react-native-reanimated";
|
|
15
|
-
import type { ScreenProps } from "react-native-screens";
|
|
16
15
|
import type { ScreenTransitionConfig } from "../shared";
|
|
17
16
|
import type {
|
|
18
17
|
OverlayInterpolationProps,
|
|
19
18
|
ScreenInterpolationProps,
|
|
20
|
-
ScreenStyleInterpolator,
|
|
21
|
-
TransitionSpec,
|
|
22
19
|
} from "../shared/types/animation.types";
|
|
23
|
-
import type {
|
|
24
|
-
GestureActivationArea,
|
|
25
|
-
GestureDirection,
|
|
26
|
-
} from "../shared/types/gesture.types";
|
|
27
20
|
|
|
28
21
|
export type BlankStackNavigationEventMap = {
|
|
29
22
|
/**
|
|
@@ -104,6 +97,11 @@ export type BlankStackOverlayProps = {
|
|
|
104
97
|
*/
|
|
105
98
|
focusedIndex: number;
|
|
106
99
|
|
|
100
|
+
/**
|
|
101
|
+
* All routes currently in the stack.
|
|
102
|
+
*/
|
|
103
|
+
routes: Route<string>[];
|
|
104
|
+
|
|
107
105
|
/**
|
|
108
106
|
* Options passed to the overlay component.
|
|
109
107
|
*/
|
|
@@ -9,15 +9,8 @@ export const composeDescriptors = (
|
|
|
9
9
|
const composed: BlankStackDescriptorMap = {};
|
|
10
10
|
|
|
11
11
|
for (const route of routes) {
|
|
12
|
-
|
|
12
|
+
composed[route.key] =
|
|
13
13
|
nextDescriptors[route.key] ?? currentDescriptors[route.key];
|
|
14
|
-
|
|
15
|
-
// useScreenAnimation depends on this, however with blank-stack, this should be enabled by default
|
|
16
|
-
const withEnableTransitions = {
|
|
17
|
-
...adjusted,
|
|
18
|
-
options: { ...adjusted.options, enableTransitions: true },
|
|
19
|
-
};
|
|
20
|
-
composed[route.key] = withEnableTransitions;
|
|
21
14
|
}
|
|
22
15
|
|
|
23
16
|
return composed;
|
|
@@ -4,7 +4,6 @@ import useStableCallback from "../../../../shared/hooks/use-stable-callback";
|
|
|
4
4
|
|
|
5
5
|
export const useClosingRouteKeys = () => {
|
|
6
6
|
const keysRef = useRef<Set<string>>(new Set());
|
|
7
|
-
const finishedRef = useRef<Set<string>>(new Set());
|
|
8
7
|
const shared = useSharedValue<string[]>([]);
|
|
9
8
|
|
|
10
9
|
const add = useStableCallback((key: string) => {
|
|
@@ -13,7 +12,6 @@ export const useClosingRouteKeys = () => {
|
|
|
13
12
|
return;
|
|
14
13
|
}
|
|
15
14
|
|
|
16
|
-
finishedRef.current.delete(key);
|
|
17
15
|
keys.add(key);
|
|
18
16
|
shared.modify((prev) => {
|
|
19
17
|
"worklet";
|
|
@@ -26,12 +24,8 @@ export const useClosingRouteKeys = () => {
|
|
|
26
24
|
|
|
27
25
|
const remove = useStableCallback((key: string) => {
|
|
28
26
|
const keys = keysRef.current;
|
|
29
|
-
|
|
30
|
-
finishedRef.current.delete(key);
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
27
|
+
keys.delete(key);
|
|
33
28
|
|
|
34
|
-
finishedRef.current.delete(key);
|
|
35
29
|
shared.modify((prev) => {
|
|
36
30
|
"worklet";
|
|
37
31
|
const index = prev.indexOf(key);
|
|
@@ -44,13 +38,8 @@ export const useClosingRouteKeys = () => {
|
|
|
44
38
|
|
|
45
39
|
const clear = useStableCallback(() => {
|
|
46
40
|
const keys = keysRef.current;
|
|
47
|
-
if (!keys.size) {
|
|
48
|
-
finishedRef.current.clear();
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
41
|
|
|
52
42
|
keys.clear();
|
|
53
|
-
finishedRef.current.clear();
|
|
54
43
|
shared.modify((prev) => {
|
|
55
44
|
"worklet";
|
|
56
45
|
prev.length = 0;
|
|
@@ -2,11 +2,11 @@ import { type Route, StackActions } from "@react-navigation/native";
|
|
|
2
2
|
import { useLayoutEffect, useState } from "react";
|
|
3
3
|
import useStableCallback from "../../../../shared/hooks/use-stable-callback";
|
|
4
4
|
import type { BlankStackDescriptorMap } from "../../../types";
|
|
5
|
-
import type { StackNavigationContextProps } from "../_types";
|
|
6
5
|
import { areDescriptorsEqual } from "../helpers/are-descriptors-equal";
|
|
7
6
|
import { composeDescriptors } from "../helpers/compose-descriptors";
|
|
8
7
|
import { haveSameRouteKeys } from "../helpers/have-same-route-keys";
|
|
9
8
|
import { routesAreIdentical } from "../helpers/routes-are-identical";
|
|
9
|
+
import type { StackNavigationContextProps } from "../types";
|
|
10
10
|
import { useClosingRouteKeys } from "./use-closing-route-keys";
|
|
11
11
|
import { usePrevious } from "./use-previous";
|
|
12
12
|
|
|
@@ -1,45 +1,50 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
import createProvider from "../../../shared/utils/create-provider";
|
|
2
3
|
import type { BlankStackScene } from "../../types";
|
|
4
|
+
import { calculateActiveScreensLimit } from "./helpers/calculate-active-screens-limit";
|
|
3
5
|
import { useStackNavigationState } from "./hooks/use-stack-navigation-state";
|
|
4
6
|
import type {
|
|
5
7
|
StackNavigationContextProps,
|
|
6
8
|
StackNavigationContextValue,
|
|
7
|
-
} from "./
|
|
8
|
-
import { calculateActiveScreensLimit } from "./helpers/calculate-active-screens-limit";
|
|
9
|
-
|
|
10
|
-
export const StackNavigationContext =
|
|
11
|
-
createContext<StackNavigationContextValue | null>(null);
|
|
9
|
+
} from "./types";
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
const { withStackNavigationProvider, useStackNavigationContext } =
|
|
12
|
+
createProvider("StackNavigation")<
|
|
13
|
+
StackNavigationContextProps,
|
|
14
|
+
StackNavigationContextValue
|
|
15
|
+
>((props) => {
|
|
17
16
|
const { state, handleCloseRoute, closingRouteKeys } =
|
|
18
17
|
useStackNavigationState(props);
|
|
19
18
|
|
|
20
|
-
const scenes
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
19
|
+
const { scenes, activeScreensLimit, shouldShowFloatOverlay } =
|
|
20
|
+
useMemo(() => {
|
|
21
|
+
const scenes: BlankStackScene[] = [];
|
|
22
|
+
let shouldShowFloatOverlay = false;
|
|
23
|
+
|
|
24
|
+
for (const route of state.routes) {
|
|
25
|
+
const descriptor = state.descriptors[route.key];
|
|
26
|
+
scenes.push({ route, descriptor });
|
|
27
|
+
|
|
28
|
+
if (!shouldShowFloatOverlay) {
|
|
29
|
+
const options = descriptor?.options;
|
|
30
|
+
shouldShowFloatOverlay =
|
|
31
|
+
options?.overlayMode === "float" &&
|
|
32
|
+
options?.overlayShown === true;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
scenes,
|
|
38
|
+
activeScreensLimit: calculateActiveScreensLimit(
|
|
39
|
+
state.routes,
|
|
40
|
+
state.descriptors,
|
|
41
|
+
),
|
|
42
|
+
shouldShowFloatOverlay,
|
|
43
|
+
};
|
|
44
|
+
}, [state.routes, state.descriptors]);
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
value: {
|
|
43
48
|
routes: state.routes,
|
|
44
49
|
focusedIndex: props.state.index,
|
|
45
50
|
descriptors: state.descriptors,
|
|
@@ -48,33 +53,8 @@ export function withStackNavigationProvider(
|
|
|
48
53
|
handleCloseRoute,
|
|
49
54
|
scenes,
|
|
50
55
|
shouldShowFloatOverlay,
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
scenes,
|
|
55
|
-
activeScreensLimit,
|
|
56
|
-
closingRouteKeys,
|
|
57
|
-
handleCloseRoute,
|
|
58
|
-
props.state.index,
|
|
59
|
-
shouldShowFloatOverlay,
|
|
60
|
-
]);
|
|
61
|
-
|
|
62
|
-
return (
|
|
63
|
-
<StackNavigationContext.Provider value={contextValue}>
|
|
64
|
-
<Component {...contextValue} />
|
|
65
|
-
</StackNavigationContext.Provider>
|
|
66
|
-
);
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export const useStackNavigationContext = () => {
|
|
71
|
-
const context = useContext(StackNavigationContext);
|
|
72
|
-
|
|
73
|
-
if (!context) {
|
|
74
|
-
throw new Error(
|
|
75
|
-
"StackNavigationContext.Provider is missing in the component tree.",
|
|
76
|
-
);
|
|
77
|
-
}
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
});
|
|
78
59
|
|
|
79
|
-
|
|
80
|
-
};
|
|
60
|
+
export { useStackNavigationContext, withStackNavigationProvider };
|