react-native-screen-transitions 2.4.1 → 2.4.2-beta.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/lib/commonjs/__configs__/presets.js.map +1 -1
- package/lib/commonjs/components/root-transition-aware.js.map +1 -1
- package/lib/commonjs/constants.js.map +1 -1
- package/lib/commonjs/hooks/animation/use-screen-animation.js +9 -5
- package/lib/commonjs/hooks/animation/use-screen-animation.js.map +1 -1
- package/lib/commonjs/index.js +7 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/integrations/blank-stack/components/Header.js +142 -0
- package/lib/commonjs/integrations/blank-stack/components/Header.js.map +1 -0
- package/lib/commonjs/integrations/blank-stack/components/Screens.js +64 -0
- package/lib/commonjs/integrations/blank-stack/components/Screens.js.map +1 -0
- package/lib/commonjs/integrations/blank-stack/components/StackView.js +94 -0
- package/lib/commonjs/integrations/blank-stack/components/StackView.js.map +1 -0
- package/lib/commonjs/integrations/blank-stack/navigators/createBlankStackNavigator.js +74 -0
- package/lib/commonjs/integrations/blank-stack/navigators/createBlankStackNavigator.js.map +1 -0
- package/lib/commonjs/integrations/blank-stack/utils/with-stack-navigation/_hooks/use-closing-route-keys.js +66 -0
- package/lib/commonjs/integrations/blank-stack/utils/with-stack-navigation/_hooks/use-closing-route-keys.js.map +1 -0
- package/lib/commonjs/integrations/blank-stack/utils/with-stack-navigation/_hooks/use-previous.js +16 -0
- package/lib/commonjs/integrations/blank-stack/utils/with-stack-navigation/_hooks/use-previous.js.map +1 -0
- package/lib/commonjs/integrations/blank-stack/utils/with-stack-navigation/_hooks/use-stack-navigation-state.js +208 -0
- package/lib/commonjs/integrations/blank-stack/utils/with-stack-navigation/_hooks/use-stack-navigation-state.js.map +1 -0
- package/lib/commonjs/{types/navigator.js → integrations/blank-stack/utils/with-stack-navigation/_types.js} +1 -1
- package/lib/commonjs/integrations/blank-stack/utils/with-stack-navigation/_types.js.map +1 -0
- package/lib/commonjs/integrations/blank-stack/utils/with-stack-navigation/_utils/are-descriptors-equal.js +15 -0
- package/lib/commonjs/integrations/blank-stack/utils/with-stack-navigation/_utils/are-descriptors-equal.js.map +1 -0
- package/lib/commonjs/integrations/blank-stack/utils/with-stack-navigation/_utils/calculateActiveScreensLimit.js +23 -0
- package/lib/commonjs/integrations/blank-stack/utils/with-stack-navigation/_utils/calculateActiveScreensLimit.js.map +1 -0
- package/lib/commonjs/integrations/blank-stack/utils/with-stack-navigation/_utils/compose-descriptors.js +15 -0
- package/lib/commonjs/integrations/blank-stack/utils/with-stack-navigation/_utils/compose-descriptors.js.map +1 -0
- package/lib/commonjs/integrations/blank-stack/utils/with-stack-navigation/_utils/have-same-route-keys.js +14 -0
- package/lib/commonjs/integrations/blank-stack/utils/with-stack-navigation/_utils/have-same-route-keys.js.map +1 -0
- package/lib/commonjs/integrations/blank-stack/utils/with-stack-navigation/_utils/routes-are-identical.js +13 -0
- package/lib/commonjs/integrations/blank-stack/utils/with-stack-navigation/_utils/routes-are-identical.js.map +1 -0
- package/lib/commonjs/integrations/blank-stack/utils/with-stack-navigation/index.js +71 -0
- package/lib/commonjs/integrations/blank-stack/utils/with-stack-navigation/index.js.map +1 -0
- package/lib/commonjs/integrations/native-stack/navigators/createNativeStackNavigator.js.map +1 -1
- package/lib/commonjs/integrations/native-stack/utils/getModalRoutesKeys.js.map +1 -1
- package/lib/commonjs/integrations/native-stack/utils/useInvalidPreventRemoveError.js.map +1 -1
- package/lib/commonjs/integrations/native-stack/views/NativeStackView.js.map +1 -1
- package/lib/commonjs/integrations/native-stack/views/NativeStackView.native.js.map +1 -1
- package/lib/commonjs/integrations/native-stack/views/useHeaderConfigProps.js.map +1 -1
- package/lib/commonjs/providers/keys.js.map +1 -1
- package/lib/commonjs/providers/screen-transition-provider.js.map +1 -1
- package/lib/commonjs/providers/transition-styles.js +18 -4
- package/lib/commonjs/providers/transition-styles.js.map +1 -1
- package/lib/commonjs/stores/animations.js.map +1 -1
- package/lib/commonjs/stores/bounds/index.js.map +1 -1
- package/lib/commonjs/stores/gestures.js.map +1 -1
- package/lib/commonjs/stores/utils/reset-stores-for-screen.js.map +1 -1
- package/lib/commonjs/types/blank-stack.navigator.js +6 -0
- package/lib/commonjs/types/{navigator.js.map → blank-stack.navigator.js.map} +1 -1
- package/lib/commonjs/types/native-stack.navigator.js +6 -0
- package/lib/commonjs/types/native-stack.navigator.js.map +1 -0
- package/lib/commonjs/utils/animation/derivations.js +1 -14
- package/lib/commonjs/utils/animation/derivations.js.map +1 -1
- package/lib/commonjs/utils/bounds/constants.js.map +1 -1
- package/lib/commonjs/utils/bounds/index.js +23 -90
- package/lib/commonjs/utils/bounds/index.js.map +1 -1
- package/lib/commonjs/utils/gesture/apply-offset-rules.js.map +1 -1
- package/lib/commonjs/utils/gesture/check-gesture-activation.js.map +1 -1
- package/lib/module/__configs__/presets.js.map +1 -1
- package/lib/module/components/root-transition-aware.js.map +1 -1
- package/lib/module/constants.js.map +1 -1
- package/lib/module/hooks/animation/use-screen-animation.js +9 -5
- package/lib/module/hooks/animation/use-screen-animation.js.map +1 -1
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/integrations/blank-stack/components/Header.js +138 -0
- package/lib/module/integrations/blank-stack/components/Header.js.map +1 -0
- package/lib/module/integrations/blank-stack/components/Screens.js +58 -0
- package/lib/module/integrations/blank-stack/components/Screens.js.map +1 -0
- package/lib/module/integrations/blank-stack/components/StackView.js +90 -0
- package/lib/module/integrations/blank-stack/components/StackView.js.map +1 -0
- package/lib/module/integrations/blank-stack/navigators/createBlankStackNavigator.js +68 -0
- package/lib/module/integrations/blank-stack/navigators/createBlankStackNavigator.js.map +1 -0
- package/lib/module/integrations/blank-stack/utils/with-stack-navigation/_hooks/use-closing-route-keys.js +60 -0
- package/lib/module/integrations/blank-stack/utils/with-stack-navigation/_hooks/use-closing-route-keys.js.map +1 -0
- package/lib/module/integrations/blank-stack/utils/with-stack-navigation/_hooks/use-previous.js +11 -0
- package/lib/module/integrations/blank-stack/utils/with-stack-navigation/_hooks/use-previous.js.map +1 -0
- package/lib/module/integrations/blank-stack/utils/with-stack-navigation/_hooks/use-stack-navigation-state.js +202 -0
- package/lib/module/integrations/blank-stack/utils/with-stack-navigation/_hooks/use-stack-navigation-state.js.map +1 -0
- package/lib/module/integrations/blank-stack/utils/with-stack-navigation/_types.js +4 -0
- package/lib/module/integrations/blank-stack/utils/with-stack-navigation/_types.js.map +1 -0
- package/lib/module/integrations/blank-stack/utils/with-stack-navigation/_utils/are-descriptors-equal.js +10 -0
- package/lib/module/integrations/blank-stack/utils/with-stack-navigation/_utils/are-descriptors-equal.js.map +1 -0
- package/lib/module/integrations/blank-stack/utils/with-stack-navigation/_utils/calculateActiveScreensLimit.js +19 -0
- package/lib/module/integrations/blank-stack/utils/with-stack-navigation/_utils/calculateActiveScreensLimit.js.map +1 -0
- package/lib/module/integrations/blank-stack/utils/with-stack-navigation/_utils/compose-descriptors.js +10 -0
- package/lib/module/integrations/blank-stack/utils/with-stack-navigation/_utils/compose-descriptors.js.map +1 -0
- package/lib/module/integrations/blank-stack/utils/with-stack-navigation/_utils/have-same-route-keys.js +9 -0
- package/lib/module/integrations/blank-stack/utils/with-stack-navigation/_utils/have-same-route-keys.js.map +1 -0
- package/lib/module/integrations/blank-stack/utils/with-stack-navigation/_utils/routes-are-identical.js +8 -0
- package/lib/module/integrations/blank-stack/utils/with-stack-navigation/_utils/routes-are-identical.js.map +1 -0
- package/lib/module/integrations/blank-stack/utils/with-stack-navigation/index.js +65 -0
- package/lib/module/integrations/blank-stack/utils/with-stack-navigation/index.js.map +1 -0
- package/lib/module/integrations/native-stack/navigators/createNativeStackNavigator.js.map +1 -1
- package/lib/module/integrations/native-stack/utils/getModalRoutesKeys.js.map +1 -1
- package/lib/module/integrations/native-stack/utils/useInvalidPreventRemoveError.js.map +1 -1
- package/lib/module/integrations/native-stack/views/NativeStackView.js.map +1 -1
- package/lib/module/integrations/native-stack/views/NativeStackView.native.js.map +1 -1
- package/lib/module/integrations/native-stack/views/useHeaderConfigProps.js.map +1 -1
- package/lib/module/providers/keys.js.map +1 -1
- package/lib/module/providers/screen-transition-provider.js.map +1 -1
- package/lib/module/providers/transition-styles.js +19 -5
- package/lib/module/providers/transition-styles.js.map +1 -1
- package/lib/module/stores/animations.js.map +1 -1
- package/lib/module/stores/bounds/index.js.map +1 -1
- package/lib/module/stores/gestures.js.map +1 -1
- package/lib/module/stores/utils/reset-stores-for-screen.js.map +1 -1
- package/lib/module/types/blank-stack.navigator.js +4 -0
- package/lib/module/types/{navigator.js.map → blank-stack.navigator.js.map} +1 -1
- package/lib/module/types/native-stack.navigator.js +4 -0
- package/lib/module/types/native-stack.navigator.js.map +1 -0
- package/lib/module/utils/animation/derivations.js +1 -14
- package/lib/module/utils/animation/derivations.js.map +1 -1
- package/lib/module/utils/bounds/constants.js.map +1 -1
- package/lib/module/utils/bounds/index.js +24 -91
- package/lib/module/utils/bounds/index.js.map +1 -1
- package/lib/module/utils/gesture/apply-offset-rules.js.map +1 -1
- package/lib/module/utils/gesture/check-gesture-activation.js.map +1 -1
- package/lib/typescript/__configs__/index.d.ts +9 -9
- package/lib/typescript/__configs__/index.d.ts.map +1 -1
- package/lib/typescript/__configs__/presets.d.ts +1 -1
- package/lib/typescript/__configs__/presets.d.ts.map +1 -1
- package/lib/typescript/components/root-transition-aware.d.ts.map +1 -1
- package/lib/typescript/constants.d.ts +2 -2
- package/lib/typescript/constants.d.ts.map +1 -1
- package/lib/typescript/hooks/animation/use-screen-animation.d.ts +1 -1
- package/lib/typescript/hooks/animation/use-screen-animation.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +20 -18
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/integrations/blank-stack/components/Header.d.ts +5 -0
- package/lib/typescript/integrations/blank-stack/components/Header.d.ts.map +1 -0
- package/lib/typescript/integrations/blank-stack/components/Screens.d.ts +15 -0
- package/lib/typescript/integrations/blank-stack/components/Screens.d.ts.map +1 -0
- package/lib/typescript/integrations/blank-stack/components/StackView.d.ts +2 -0
- package/lib/typescript/integrations/blank-stack/components/StackView.d.ts.map +1 -0
- package/lib/typescript/integrations/blank-stack/navigators/createBlankStackNavigator.d.ts +109 -0
- package/lib/typescript/integrations/blank-stack/navigators/createBlankStackNavigator.d.ts.map +1 -0
- package/lib/typescript/integrations/blank-stack/utils/with-stack-navigation/_hooks/use-closing-route-keys.d.ts +8 -0
- package/lib/typescript/integrations/blank-stack/utils/with-stack-navigation/_hooks/use-closing-route-keys.d.ts.map +1 -0
- package/lib/typescript/integrations/blank-stack/utils/with-stack-navigation/_hooks/use-previous.d.ts +2 -0
- package/lib/typescript/integrations/blank-stack/utils/with-stack-navigation/_hooks/use-previous.d.ts.map +1 -0
- package/lib/typescript/integrations/blank-stack/utils/with-stack-navigation/_hooks/use-stack-navigation-state.d.ts +20 -0
- package/lib/typescript/integrations/blank-stack/utils/with-stack-navigation/_hooks/use-stack-navigation-state.d.ts.map +1 -0
- package/lib/typescript/integrations/blank-stack/utils/with-stack-navigation/_types.d.ts +23 -0
- package/lib/typescript/integrations/blank-stack/utils/with-stack-navigation/_types.d.ts.map +1 -0
- package/lib/typescript/integrations/blank-stack/utils/with-stack-navigation/_utils/are-descriptors-equal.d.ts +3 -0
- package/lib/typescript/integrations/blank-stack/utils/with-stack-navigation/_utils/are-descriptors-equal.d.ts.map +1 -0
- package/lib/typescript/integrations/blank-stack/utils/with-stack-navigation/_utils/calculateActiveScreensLimit.d.ts +4 -0
- package/lib/typescript/integrations/blank-stack/utils/with-stack-navigation/_utils/calculateActiveScreensLimit.d.ts.map +1 -0
- package/lib/typescript/integrations/blank-stack/utils/with-stack-navigation/_utils/compose-descriptors.d.ts +4 -0
- package/lib/typescript/integrations/blank-stack/utils/with-stack-navigation/_utils/compose-descriptors.d.ts.map +1 -0
- package/lib/typescript/integrations/blank-stack/utils/with-stack-navigation/_utils/have-same-route-keys.d.ts +3 -0
- package/lib/typescript/integrations/blank-stack/utils/with-stack-navigation/_utils/have-same-route-keys.d.ts.map +1 -0
- package/lib/typescript/integrations/blank-stack/utils/with-stack-navigation/_utils/routes-are-identical.d.ts +3 -0
- package/lib/typescript/integrations/blank-stack/utils/with-stack-navigation/_utils/routes-are-identical.d.ts.map +1 -0
- package/lib/typescript/integrations/blank-stack/utils/with-stack-navigation/index.d.ts +6 -0
- package/lib/typescript/integrations/blank-stack/utils/with-stack-navigation/index.d.ts.map +1 -0
- package/lib/typescript/integrations/native-stack/navigators/createNativeStackNavigator.d.ts +1 -1
- package/lib/typescript/integrations/native-stack/navigators/createNativeStackNavigator.d.ts.map +1 -1
- package/lib/typescript/integrations/native-stack/utils/getModalRoutesKeys.d.ts +1 -1
- package/lib/typescript/integrations/native-stack/utils/getModalRoutesKeys.d.ts.map +1 -1
- package/lib/typescript/integrations/native-stack/utils/useInvalidPreventRemoveError.d.ts +1 -1
- package/lib/typescript/integrations/native-stack/utils/useInvalidPreventRemoveError.d.ts.map +1 -1
- package/lib/typescript/integrations/native-stack/views/NativeStackView.d.ts +1 -1
- package/lib/typescript/integrations/native-stack/views/NativeStackView.d.ts.map +1 -1
- package/lib/typescript/integrations/native-stack/views/NativeStackView.native.d.ts +1 -1
- package/lib/typescript/integrations/native-stack/views/NativeStackView.native.d.ts.map +1 -1
- package/lib/typescript/integrations/native-stack/views/useHeaderConfigProps.d.ts +1 -1
- package/lib/typescript/integrations/native-stack/views/useHeaderConfigProps.d.ts.map +1 -1
- package/lib/typescript/providers/keys.d.ts +1 -1
- package/lib/typescript/providers/keys.d.ts.map +1 -1
- package/lib/typescript/providers/screen-transition-provider.d.ts +1 -1
- package/lib/typescript/providers/screen-transition-provider.d.ts.map +1 -1
- package/lib/typescript/providers/transition-styles.d.ts.map +1 -1
- package/lib/typescript/stores/animations.d.ts +1 -1
- package/lib/typescript/stores/animations.d.ts.map +1 -1
- package/lib/typescript/stores/bounds/index.d.ts +1 -1
- package/lib/typescript/stores/bounds/index.d.ts.map +1 -1
- package/lib/typescript/stores/gestures.d.ts +1 -1
- package/lib/typescript/stores/gestures.d.ts.map +1 -1
- package/lib/typescript/stores/utils/reset-stores-for-screen.d.ts +1 -1
- package/lib/typescript/stores/utils/reset-stores-for-screen.d.ts.map +1 -1
- package/lib/typescript/types/animation.d.ts +2 -4
- package/lib/typescript/types/animation.d.ts.map +1 -1
- package/lib/typescript/types/blank-stack.navigator.d.ts +219 -0
- package/lib/typescript/types/blank-stack.navigator.d.ts.map +1 -0
- package/lib/typescript/types/bounds.d.ts +0 -57
- package/lib/typescript/types/bounds.d.ts.map +1 -1
- package/lib/typescript/types/{navigator.d.ts → native-stack.navigator.d.ts} +5 -1
- package/lib/typescript/types/native-stack.navigator.d.ts.map +1 -0
- package/lib/typescript/utils/animation/derivations.d.ts +1 -4
- package/lib/typescript/utils/animation/derivations.d.ts.map +1 -1
- package/lib/typescript/utils/bounds/_types/builder.d.ts +2 -2
- package/lib/typescript/utils/bounds/_types/builder.d.ts.map +1 -1
- package/lib/typescript/utils/bounds/_utils/geometry.d.ts +2 -2
- package/lib/typescript/utils/bounds/_utils/geometry.d.ts.map +1 -1
- package/lib/typescript/utils/bounds/constants.d.ts +2 -2
- package/lib/typescript/utils/bounds/constants.d.ts.map +1 -1
- package/lib/typescript/utils/bounds/index.d.ts +4 -4
- package/lib/typescript/utils/bounds/index.d.ts.map +1 -1
- package/lib/typescript/utils/gesture/apply-offset-rules.d.ts +2 -2
- package/lib/typescript/utils/gesture/apply-offset-rules.d.ts.map +1 -1
- package/lib/typescript/utils/gesture/check-gesture-activation.d.ts +2 -2
- package/lib/typescript/utils/gesture/check-gesture-activation.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/__configs__/presets.ts +590 -590
- package/src/components/root-transition-aware.tsx +27 -27
- package/src/constants.ts +47 -47
- package/src/hooks/animation/use-screen-animation.tsx +52 -47
- package/src/index.ts +33 -22
- package/src/integrations/blank-stack/components/Header.tsx +143 -0
- package/src/integrations/blank-stack/components/Screens.tsx +96 -0
- package/src/integrations/blank-stack/components/StackView.tsx +106 -0
- package/src/integrations/blank-stack/navigators/createBlankStackNavigator.tsx +122 -0
- package/src/integrations/blank-stack/utils/with-stack-navigation/_hooks/use-closing-route-keys.tsx +62 -0
- package/src/integrations/blank-stack/utils/with-stack-navigation/_hooks/use-previous.tsx +11 -0
- package/src/integrations/blank-stack/utils/with-stack-navigation/_hooks/use-stack-navigation-state.tsx +280 -0
- package/src/integrations/blank-stack/utils/with-stack-navigation/_types.ts +36 -0
- package/src/integrations/blank-stack/utils/with-stack-navigation/_utils/are-descriptors-equal.ts +15 -0
- package/src/integrations/blank-stack/utils/with-stack-navigation/_utils/calculateActiveScreensLimit.ts +29 -0
- package/src/integrations/blank-stack/utils/with-stack-navigation/_utils/compose-descriptors.ts +17 -0
- package/src/integrations/blank-stack/utils/with-stack-navigation/_utils/have-same-route-keys.ts +12 -0
- package/src/integrations/blank-stack/utils/with-stack-navigation/_utils/routes-are-identical.ts +11 -0
- package/src/integrations/blank-stack/utils/with-stack-navigation/index.tsx +93 -0
- package/src/integrations/native-stack/navigators/createNativeStackNavigator.tsx +95 -95
- package/src/integrations/native-stack/utils/getModalRoutesKeys.ts +14 -14
- package/src/integrations/native-stack/utils/useInvalidPreventRemoveError.tsx +23 -23
- package/src/integrations/native-stack/views/NativeStackView.native.tsx +608 -608
- package/src/integrations/native-stack/views/NativeStackView.tsx +188 -188
- package/src/integrations/native-stack/views/useHeaderConfigProps.tsx +260 -260
- package/src/providers/keys.tsx +22 -22
- package/src/providers/screen-transition-provider.tsx +20 -20
- package/src/providers/transition-styles.tsx +24 -11
- package/src/stores/animations.ts +23 -23
- package/src/stores/bounds/index.ts +82 -82
- package/src/stores/gestures.ts +36 -36
- package/src/stores/utils/reset-stores-for-screen.ts +4 -4
- package/src/types/animation.ts +2 -4
- package/src/types/blank-stack.navigator.ts +271 -0
- package/src/types/bounds.ts +0 -64
- package/src/types/{navigator.ts → native-stack.navigator.ts} +5 -0
- package/src/utils/animation/derivations.ts +3 -20
- package/src/utils/bounds/_types/builder.ts +111 -111
- package/src/utils/bounds/_utils/geometry.ts +2 -2
- package/src/utils/bounds/constants.ts +29 -29
- package/src/utils/bounds/index.ts +35 -105
- package/src/utils/gesture/apply-offset-rules.ts +271 -271
- package/src/utils/gesture/check-gesture-activation.ts +260 -260
- package/lib/module/types/navigator.js +0 -4
- package/lib/typescript/types/navigator.d.ts.map +0 -1
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { SafeAreaProviderCompat } from "@react-navigation/elements";
|
|
2
|
+
import {
|
|
3
|
+
NavigationContext,
|
|
4
|
+
NavigationRouteContext,
|
|
5
|
+
} from "@react-navigation/native";
|
|
6
|
+
import { GestureHandlerRootView } from "react-native-gesture-handler";
|
|
7
|
+
import { ScreenContainer } from "react-native-screens";
|
|
8
|
+
import { RootTransitionAware } from "../../../components/root-transition-aware";
|
|
9
|
+
import { ScreenTransitionProvider } from "../../../providers/screen-transition-provider";
|
|
10
|
+
import type { BlankStackDescriptor } from "../../../types/blank-stack.navigator";
|
|
11
|
+
import { withStackNavigationProvider } from "../utils/with-stack-navigation";
|
|
12
|
+
import { Header } from "./Header";
|
|
13
|
+
import { Screen } from "./Screens";
|
|
14
|
+
|
|
15
|
+
function isFabric() {
|
|
16
|
+
return "nativeFabricUIManager" in global;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
type SceneViewProps = {
|
|
20
|
+
descriptor: BlankStackDescriptor;
|
|
21
|
+
isFocused: boolean;
|
|
22
|
+
sceneIndex: number;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const SceneView = ({ descriptor }: SceneViewProps) => {
|
|
26
|
+
const { route, navigation, render } = descriptor;
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<NavigationContext.Provider value={navigation}>
|
|
30
|
+
<NavigationRouteContext.Provider value={route}>
|
|
31
|
+
<RootTransitionAware>
|
|
32
|
+
{descriptor.options.headerMode === "screen" && <Header.Screen />}
|
|
33
|
+
{render()}
|
|
34
|
+
</RootTransitionAware>
|
|
35
|
+
</NavigationRouteContext.Provider>
|
|
36
|
+
</NavigationContext.Provider>
|
|
37
|
+
);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export const StackView = withStackNavigationProvider(
|
|
41
|
+
({
|
|
42
|
+
activeScreensLimit,
|
|
43
|
+
descriptors,
|
|
44
|
+
FloatHeader,
|
|
45
|
+
focusedIndex,
|
|
46
|
+
routes,
|
|
47
|
+
scenes,
|
|
48
|
+
}) => {
|
|
49
|
+
return (
|
|
50
|
+
<GestureHandlerRootView>
|
|
51
|
+
<SafeAreaProviderCompat>
|
|
52
|
+
<FloatHeader />
|
|
53
|
+
<ScreenContainer style={{ flex: 1 }}>
|
|
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
|
+
routes={routes}
|
|
80
|
+
shouldFreeze={shouldFreeze}
|
|
81
|
+
freezeOnBlur={descriptor.options.freezeOnBlur}
|
|
82
|
+
>
|
|
83
|
+
<ScreenTransitionProvider
|
|
84
|
+
// @ts-expect-error
|
|
85
|
+
previous={previousDescriptor}
|
|
86
|
+
// @ts-expect-error
|
|
87
|
+
current={descriptor}
|
|
88
|
+
// @ts-expect-error
|
|
89
|
+
next={nextDescriptor}
|
|
90
|
+
>
|
|
91
|
+
<SceneView
|
|
92
|
+
key={route.key}
|
|
93
|
+
isFocused={isFocused}
|
|
94
|
+
sceneIndex={sceneIndex}
|
|
95
|
+
descriptor={descriptor}
|
|
96
|
+
/>
|
|
97
|
+
</ScreenTransitionProvider>
|
|
98
|
+
</Screen>
|
|
99
|
+
);
|
|
100
|
+
})}
|
|
101
|
+
</ScreenContainer>
|
|
102
|
+
</SafeAreaProviderCompat>
|
|
103
|
+
</GestureHandlerRootView>
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
);
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createNavigatorFactory,
|
|
3
|
+
type EventArg,
|
|
4
|
+
type NavigatorTypeBagBase,
|
|
5
|
+
type ParamListBase,
|
|
6
|
+
type StackActionHelpers,
|
|
7
|
+
StackActions,
|
|
8
|
+
type StackNavigationState,
|
|
9
|
+
StackRouter,
|
|
10
|
+
type StackRouterOptions,
|
|
11
|
+
type StaticConfig,
|
|
12
|
+
type TypedNavigator,
|
|
13
|
+
useNavigationBuilder,
|
|
14
|
+
} from "@react-navigation/native";
|
|
15
|
+
import * as React from "react";
|
|
16
|
+
import { StackView } from "../components/StackView";
|
|
17
|
+
import type {
|
|
18
|
+
BlankStackNavigationEventMap,
|
|
19
|
+
BlankStackNavigationOptions,
|
|
20
|
+
BlankStackNavigationProp,
|
|
21
|
+
BlankStackNavigatorProps,
|
|
22
|
+
} from "../../../types/blank-stack.navigator";
|
|
23
|
+
|
|
24
|
+
function BlankStackNavigator({
|
|
25
|
+
id,
|
|
26
|
+
initialRouteName,
|
|
27
|
+
children,
|
|
28
|
+
layout,
|
|
29
|
+
screenListeners,
|
|
30
|
+
screenOptions,
|
|
31
|
+
screenLayout,
|
|
32
|
+
...rest
|
|
33
|
+
}: BlankStackNavigatorProps) {
|
|
34
|
+
const { state, describe, descriptors, navigation, NavigationContent } =
|
|
35
|
+
useNavigationBuilder<
|
|
36
|
+
StackNavigationState<ParamListBase>,
|
|
37
|
+
StackRouterOptions,
|
|
38
|
+
StackActionHelpers<ParamListBase>,
|
|
39
|
+
BlankStackNavigationOptions,
|
|
40
|
+
BlankStackNavigationEventMap
|
|
41
|
+
>(StackRouter, {
|
|
42
|
+
id,
|
|
43
|
+
initialRouteName,
|
|
44
|
+
children,
|
|
45
|
+
layout,
|
|
46
|
+
screenListeners,
|
|
47
|
+
screenOptions,
|
|
48
|
+
screenLayout,
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
React.useEffect(
|
|
52
|
+
() =>
|
|
53
|
+
// @ts-expect-error: there may not be a tab navigator in parent
|
|
54
|
+
navigation?.addListener?.("tabPress", (e: any) => {
|
|
55
|
+
const isFocused = navigation.isFocused();
|
|
56
|
+
|
|
57
|
+
// Run the operation in the next frame so we're sure all listeners have been run
|
|
58
|
+
// This is necessary to know if preventDefault() has been called
|
|
59
|
+
requestAnimationFrame(() => {
|
|
60
|
+
if (
|
|
61
|
+
state.index > 0 &&
|
|
62
|
+
isFocused &&
|
|
63
|
+
!(e as EventArg<"tabPress", true>).defaultPrevented
|
|
64
|
+
) {
|
|
65
|
+
// When user taps on already focused tab and we're inside the tab,
|
|
66
|
+
// reset the stack to replicate native behaviour
|
|
67
|
+
navigation.dispatch({
|
|
68
|
+
...StackActions.popToTop(),
|
|
69
|
+
target: state.key,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}),
|
|
74
|
+
[navigation, state.index, state.key]
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
return (
|
|
78
|
+
<NavigationContent>
|
|
79
|
+
<StackView
|
|
80
|
+
{...rest}
|
|
81
|
+
state={state}
|
|
82
|
+
navigation={navigation}
|
|
83
|
+
descriptors={descriptors}
|
|
84
|
+
describe={describe}
|
|
85
|
+
/>
|
|
86
|
+
</NavigationContent>
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function createBlankStackNavigator<
|
|
91
|
+
const ParamList extends ParamListBase,
|
|
92
|
+
const NavigatorID extends string | undefined = undefined,
|
|
93
|
+
const TypeBag extends NavigatorTypeBagBase = {
|
|
94
|
+
ParamList: ParamList;
|
|
95
|
+
NavigatorID: NavigatorID;
|
|
96
|
+
State: StackNavigationState<ParamList>;
|
|
97
|
+
ScreenOptions: BlankStackNavigationOptions;
|
|
98
|
+
EventMap: BlankStackNavigationEventMap;
|
|
99
|
+
NavigationList: {
|
|
100
|
+
[RouteName in keyof ParamList]: BlankStackNavigationProp<
|
|
101
|
+
ParamList,
|
|
102
|
+
RouteName,
|
|
103
|
+
NavigatorID
|
|
104
|
+
>;
|
|
105
|
+
};
|
|
106
|
+
Navigator: typeof BlankStackNavigator;
|
|
107
|
+
},
|
|
108
|
+
const Config extends StaticConfig<TypeBag> = StaticConfig<TypeBag>
|
|
109
|
+
>(config?: Config): TypedNavigator<TypeBag, Config> {
|
|
110
|
+
return createNavigatorFactory(BlankStackNavigator)(config);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
import { withLayoutContext } from "expo-router";
|
|
114
|
+
|
|
115
|
+
const { Navigator } = createBlankStackNavigator();
|
|
116
|
+
|
|
117
|
+
export const BlankStack = withLayoutContext<
|
|
118
|
+
BlankStackNavigationOptions,
|
|
119
|
+
typeof Navigator,
|
|
120
|
+
StackNavigationState<ParamListBase>,
|
|
121
|
+
BlankStackNavigationEventMap
|
|
122
|
+
>(Navigator);
|
package/src/integrations/blank-stack/utils/with-stack-navigation/_hooks/use-closing-route-keys.tsx
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { useRef } from "react";
|
|
2
|
+
import { useSharedValue } from "react-native-reanimated";
|
|
3
|
+
import useStableCallback from "../../../../../hooks/use-stable-callback";
|
|
4
|
+
|
|
5
|
+
export const useClosingRouteKeys = () => {
|
|
6
|
+
const keysRef = useRef<Set<string>>(new Set());
|
|
7
|
+
const shared = useSharedValue<string[]>([]);
|
|
8
|
+
|
|
9
|
+
const add = useStableCallback((key: string) => {
|
|
10
|
+
const keys = keysRef.current;
|
|
11
|
+
if (keys.has(key)) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
keys.add(key);
|
|
16
|
+
shared.modify((prev) => {
|
|
17
|
+
"worklet";
|
|
18
|
+
if (!prev.includes(key)) {
|
|
19
|
+
prev.push(key);
|
|
20
|
+
}
|
|
21
|
+
return prev;
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const remove = useStableCallback((key: string) => {
|
|
26
|
+
const keys = keysRef.current;
|
|
27
|
+
if (!keys.delete(key)) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
shared.modify((prev) => {
|
|
32
|
+
"worklet";
|
|
33
|
+
const index = prev.indexOf(key);
|
|
34
|
+
if (index !== -1) {
|
|
35
|
+
prev.splice(index, 1);
|
|
36
|
+
}
|
|
37
|
+
return prev;
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const clear = useStableCallback(() => {
|
|
42
|
+
const keys = keysRef.current;
|
|
43
|
+
if (!keys.size) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
keys.clear();
|
|
48
|
+
shared.modify((prev) => {
|
|
49
|
+
"worklet";
|
|
50
|
+
prev.length = 0;
|
|
51
|
+
return prev;
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
return {
|
|
56
|
+
ref: keysRef,
|
|
57
|
+
shared,
|
|
58
|
+
add,
|
|
59
|
+
remove,
|
|
60
|
+
clear,
|
|
61
|
+
};
|
|
62
|
+
};
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import { type Route, StackActions } from "@react-navigation/native";
|
|
2
|
+
import { useLayoutEffect, useState } from "react";
|
|
3
|
+
import useStableCallback from "../../../../../hooks/use-stable-callback";
|
|
4
|
+
import type { BlankStackDescriptorMap } from "../../../../../types/blank-stack.navigator";
|
|
5
|
+
import type { StackNavigationContextProps } from "../_types";
|
|
6
|
+
import { areDescriptorsEqual } from "../_utils/are-descriptors-equal";
|
|
7
|
+
import { composeDescriptors } from "../_utils/compose-descriptors";
|
|
8
|
+
import { haveSameRouteKeys } from "../_utils/have-same-route-keys";
|
|
9
|
+
import { routesAreIdentical } from "../_utils/routes-are-identical";
|
|
10
|
+
import { useClosingRouteKeys } from "./use-closing-route-keys";
|
|
11
|
+
import { usePrevious } from "./use-previous";
|
|
12
|
+
|
|
13
|
+
type SyncRoutesWithRemovedParams = {
|
|
14
|
+
prevRoutes: Route<string>[];
|
|
15
|
+
prevDescriptors: BlankStackDescriptorMap;
|
|
16
|
+
nextRoutes: Route<string>[];
|
|
17
|
+
nextDescriptors: BlankStackDescriptorMap;
|
|
18
|
+
closingRouteKeys: ReturnType<typeof useClosingRouteKeys>;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Aligns current routes with the latest route data while preserving references
|
|
23
|
+
* when possible for performance optimization
|
|
24
|
+
*/
|
|
25
|
+
const alignRoutesWithLatest = (
|
|
26
|
+
currentRoutes: Route<string>[],
|
|
27
|
+
currentDescriptors: BlankStackDescriptorMap,
|
|
28
|
+
nextRoutes: Route<string>[],
|
|
29
|
+
nextDescriptors: BlankStackDescriptorMap
|
|
30
|
+
) => {
|
|
31
|
+
// Early return for empty current routes
|
|
32
|
+
if (currentRoutes.length === 0) {
|
|
33
|
+
return {
|
|
34
|
+
routes: nextRoutes,
|
|
35
|
+
descriptors: composeDescriptors(
|
|
36
|
+
nextRoutes,
|
|
37
|
+
nextDescriptors,
|
|
38
|
+
currentDescriptors
|
|
39
|
+
),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Create lookup map for efficient route finding
|
|
44
|
+
const nextRouteLookup = new Map<string, Route<string>>();
|
|
45
|
+
for (const route of nextRoutes) {
|
|
46
|
+
nextRouteLookup.set(route.key, route);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Track if any changes occurred
|
|
50
|
+
let didChange = currentRoutes.length !== nextRoutes.length;
|
|
51
|
+
|
|
52
|
+
// Align routes, updating references where needed
|
|
53
|
+
const alignedRoutes = currentRoutes.map((route) => {
|
|
54
|
+
const nextRoute = nextRouteLookup.get(route.key);
|
|
55
|
+
|
|
56
|
+
if (!nextRoute) {
|
|
57
|
+
return route; // Keep current route if not in next
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (nextRoute !== route) {
|
|
61
|
+
didChange = true;
|
|
62
|
+
return nextRoute; // Update to new route reference
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return route; // Keep current route reference
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
// Only create new array if changes occurred
|
|
69
|
+
const routesResult = didChange ? alignedRoutes : currentRoutes;
|
|
70
|
+
|
|
71
|
+
return {
|
|
72
|
+
routes: routesResult,
|
|
73
|
+
descriptors: composeDescriptors(
|
|
74
|
+
routesResult,
|
|
75
|
+
nextDescriptors,
|
|
76
|
+
currentDescriptors
|
|
77
|
+
),
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Synchronizes routes while handling removed routes that may still be animating out.
|
|
83
|
+
* This manages the complex logic of keeping closing routes visible during transitions.
|
|
84
|
+
*/
|
|
85
|
+
const syncRoutesWithRemoved = ({
|
|
86
|
+
prevRoutes,
|
|
87
|
+
prevDescriptors,
|
|
88
|
+
nextRoutes,
|
|
89
|
+
nextDescriptors,
|
|
90
|
+
closingRouteKeys,
|
|
91
|
+
}: SyncRoutesWithRemovedParams) => {
|
|
92
|
+
if (nextRoutes.length === 0) {
|
|
93
|
+
closingRouteKeys.clear();
|
|
94
|
+
return {
|
|
95
|
+
routes: nextRoutes,
|
|
96
|
+
descriptors: {},
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Start with next routes, will mutate if needed
|
|
101
|
+
let derivedRoutes: Route<string>[] = nextRoutes;
|
|
102
|
+
let mutated = false;
|
|
103
|
+
|
|
104
|
+
// Helper to ensure we're working with a mutable copy
|
|
105
|
+
const ensureMutable = () => {
|
|
106
|
+
if (!mutated) {
|
|
107
|
+
derivedRoutes = derivedRoutes.slice();
|
|
108
|
+
mutated = true;
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
// Get focused (last) routes for comparison
|
|
113
|
+
const previousFocusedRoute = prevRoutes[prevRoutes.length - 1];
|
|
114
|
+
const nextFocusedRoute = nextRoutes[nextRoutes.length - 1];
|
|
115
|
+
|
|
116
|
+
// Handle focus changes between routes
|
|
117
|
+
if (
|
|
118
|
+
previousFocusedRoute &&
|
|
119
|
+
nextFocusedRoute &&
|
|
120
|
+
previousFocusedRoute.key !== nextFocusedRoute.key
|
|
121
|
+
) {
|
|
122
|
+
const nextRouteWasPresent = prevRoutes.some(
|
|
123
|
+
(route) => route.key === nextFocusedRoute.key
|
|
124
|
+
);
|
|
125
|
+
const previousRouteStillPresent = nextRoutes.some(
|
|
126
|
+
(route) => route.key === previousFocusedRoute.key
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
if (nextRouteWasPresent && !previousRouteStillPresent) {
|
|
130
|
+
// Previous route was removed, mark as closing
|
|
131
|
+
closingRouteKeys.add(previousFocusedRoute.key);
|
|
132
|
+
|
|
133
|
+
ensureMutable();
|
|
134
|
+
derivedRoutes.push(previousFocusedRoute);
|
|
135
|
+
} else {
|
|
136
|
+
// Next route is now active, not closing
|
|
137
|
+
closingRouteKeys.remove(nextFocusedRoute.key);
|
|
138
|
+
|
|
139
|
+
if (!previousRouteStillPresent) {
|
|
140
|
+
// Previous route needs to be inserted for transition
|
|
141
|
+
closingRouteKeys.remove(previousFocusedRoute.key);
|
|
142
|
+
|
|
143
|
+
ensureMutable();
|
|
144
|
+
const insertIndex = Math.max(derivedRoutes.length - 1, 0);
|
|
145
|
+
derivedRoutes.splice(insertIndex, 0, previousFocusedRoute);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
} else if (nextFocusedRoute) {
|
|
149
|
+
// Same focused route, ensure it's not marked as closing
|
|
150
|
+
closingRouteKeys.remove(nextFocusedRoute.key);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Clean up closing keys that are no longer in the route list
|
|
154
|
+
const activeKeys = new Set(derivedRoutes.map((route) => route.key));
|
|
155
|
+
for (const key of Array.from(closingRouteKeys.ref.current)) {
|
|
156
|
+
if (!activeKeys.has(key)) {
|
|
157
|
+
closingRouteKeys.remove(key);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const routesResult = mutated ? derivedRoutes : nextRoutes;
|
|
162
|
+
|
|
163
|
+
return {
|
|
164
|
+
routes: routesResult,
|
|
165
|
+
descriptors: composeDescriptors(
|
|
166
|
+
routesResult,
|
|
167
|
+
nextDescriptors,
|
|
168
|
+
prevDescriptors
|
|
169
|
+
),
|
|
170
|
+
};
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
export const useStackNavigationState = (props: StackNavigationContextProps) => {
|
|
174
|
+
const previousRoutes = usePrevious(props.state.routes) ?? [];
|
|
175
|
+
const closingRouteKeys = useClosingRouteKeys();
|
|
176
|
+
|
|
177
|
+
const [localState, setLocalState] = useState(() => ({
|
|
178
|
+
routes: props.state.routes,
|
|
179
|
+
descriptors: props.descriptors,
|
|
180
|
+
}));
|
|
181
|
+
|
|
182
|
+
useLayoutEffect(() => {
|
|
183
|
+
const nextRoutesSnapshot = props.state.routes;
|
|
184
|
+
const previousRoutesSnapshot = previousRoutes;
|
|
185
|
+
|
|
186
|
+
setLocalState((current) => {
|
|
187
|
+
const routeKeysUnchanged = haveSameRouteKeys(
|
|
188
|
+
previousRoutesSnapshot,
|
|
189
|
+
nextRoutesSnapshot
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
let derivedRoutes: Route<string>[];
|
|
193
|
+
let derivedDescriptors: BlankStackDescriptorMap;
|
|
194
|
+
|
|
195
|
+
if (routeKeysUnchanged) {
|
|
196
|
+
const result = alignRoutesWithLatest(
|
|
197
|
+
current.routes,
|
|
198
|
+
current.descriptors,
|
|
199
|
+
nextRoutesSnapshot,
|
|
200
|
+
props.descriptors
|
|
201
|
+
);
|
|
202
|
+
|
|
203
|
+
derivedRoutes = result.routes;
|
|
204
|
+
derivedDescriptors = result.descriptors;
|
|
205
|
+
} else {
|
|
206
|
+
const fallbackRoutes =
|
|
207
|
+
previousRoutesSnapshot.length > 0
|
|
208
|
+
? previousRoutesSnapshot
|
|
209
|
+
: current.routes;
|
|
210
|
+
|
|
211
|
+
const result = syncRoutesWithRemoved({
|
|
212
|
+
prevRoutes: fallbackRoutes,
|
|
213
|
+
prevDescriptors: current.descriptors,
|
|
214
|
+
nextRoutes: nextRoutesSnapshot,
|
|
215
|
+
nextDescriptors: props.descriptors,
|
|
216
|
+
closingRouteKeys,
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
derivedRoutes = result.routes;
|
|
220
|
+
derivedDescriptors = result.descriptors;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const routesChanged = !routesAreIdentical(current.routes, derivedRoutes);
|
|
224
|
+
const descriptorsChanged = !areDescriptorsEqual(
|
|
225
|
+
current.descriptors,
|
|
226
|
+
derivedDescriptors
|
|
227
|
+
);
|
|
228
|
+
|
|
229
|
+
if (!routesChanged && !descriptorsChanged) {
|
|
230
|
+
return current;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
return {
|
|
234
|
+
routes: routesChanged ? derivedRoutes : current.routes,
|
|
235
|
+
descriptors: descriptorsChanged
|
|
236
|
+
? derivedDescriptors
|
|
237
|
+
: current.descriptors,
|
|
238
|
+
};
|
|
239
|
+
});
|
|
240
|
+
}, [props.state.routes, props.descriptors, previousRoutes, closingRouteKeys]);
|
|
241
|
+
|
|
242
|
+
const handleCloseRoute = useStableCallback(
|
|
243
|
+
({ route }: { route: Route<string> }) => {
|
|
244
|
+
if (props.state.routes.some((r) => r.key === route.key)) {
|
|
245
|
+
props.navigation.dispatch({
|
|
246
|
+
...StackActions.pop(),
|
|
247
|
+
source: route.key,
|
|
248
|
+
target: props.state.key,
|
|
249
|
+
});
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
closingRouteKeys.remove(route.key);
|
|
254
|
+
|
|
255
|
+
setLocalState((current) => {
|
|
256
|
+
if (!current.routes.some((candidate) => candidate.key === route.key)) {
|
|
257
|
+
return current;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const nextRoutes = current.routes.filter(
|
|
261
|
+
(candidate) => candidate.key !== route.key
|
|
262
|
+
);
|
|
263
|
+
|
|
264
|
+
const nextDescriptors = { ...current.descriptors };
|
|
265
|
+
delete nextDescriptors[route.key];
|
|
266
|
+
|
|
267
|
+
return {
|
|
268
|
+
routes: nextRoutes,
|
|
269
|
+
descriptors: nextDescriptors,
|
|
270
|
+
};
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
);
|
|
274
|
+
|
|
275
|
+
return {
|
|
276
|
+
state: localState,
|
|
277
|
+
handleCloseRoute,
|
|
278
|
+
closingRouteKeys,
|
|
279
|
+
};
|
|
280
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
NavigationRoute,
|
|
3
|
+
ParamListBase,
|
|
4
|
+
Route,
|
|
5
|
+
RouteProp,
|
|
6
|
+
StackNavigationState,
|
|
7
|
+
} from "@react-navigation/native";
|
|
8
|
+
import type React from "react";
|
|
9
|
+
import type { SharedValue } from "react-native-reanimated";
|
|
10
|
+
import type {
|
|
11
|
+
BlankStackDescriptor,
|
|
12
|
+
BlankStackDescriptorMap,
|
|
13
|
+
BlankStackNavigationHelpers,
|
|
14
|
+
BlankStackScene,
|
|
15
|
+
} from "../../../../types/blank-stack.navigator";
|
|
16
|
+
|
|
17
|
+
export interface StackNavigationContextValue {
|
|
18
|
+
routes: NavigationRoute<ParamListBase, string>[];
|
|
19
|
+
descriptors: BlankStackDescriptorMap;
|
|
20
|
+
scenes: BlankStackScene[];
|
|
21
|
+
activeScreensLimit: number;
|
|
22
|
+
closingRouteKeysShared: SharedValue<string[]>;
|
|
23
|
+
handleCloseRoute: (payload: { route: Route<string> }) => void;
|
|
24
|
+
FloatHeader: React.MemoExoticComponent<() => React.JSX.Element | null>;
|
|
25
|
+
focusedIndex: number;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface StackNavigationContextProps {
|
|
29
|
+
state: StackNavigationState<ParamListBase>;
|
|
30
|
+
navigation: BlankStackNavigationHelpers;
|
|
31
|
+
descriptors: BlankStackDescriptorMap;
|
|
32
|
+
describe: (
|
|
33
|
+
route: RouteProp<ParamListBase>,
|
|
34
|
+
placeholder: boolean
|
|
35
|
+
) => BlankStackDescriptor;
|
|
36
|
+
}
|
package/src/integrations/blank-stack/utils/with-stack-navigation/_utils/are-descriptors-equal.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { BlankStackDescriptorMap } from "../../../../../types/blank-stack.navigator";
|
|
2
|
+
|
|
3
|
+
export const areDescriptorsEqual = (
|
|
4
|
+
a: BlankStackDescriptorMap,
|
|
5
|
+
b: BlankStackDescriptorMap
|
|
6
|
+
): boolean => {
|
|
7
|
+
if (a === b) return true;
|
|
8
|
+
|
|
9
|
+
const aKeys = Object.keys(a);
|
|
10
|
+
const bKeys = Object.keys(b);
|
|
11
|
+
|
|
12
|
+
if (aKeys.length !== bKeys.length) return false;
|
|
13
|
+
|
|
14
|
+
return aKeys.every((key) => a[key] === b[key]);
|
|
15
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { NavigationRoute, ParamListBase } from "@react-navigation/native";
|
|
2
|
+
import type { BlankStackDescriptorMap } from "../../../../../types/blank-stack.navigator";
|
|
3
|
+
|
|
4
|
+
export function calculateActiveScreensLimit(
|
|
5
|
+
routes: NavigationRoute<ParamListBase, string>[],
|
|
6
|
+
descriptors: BlankStackDescriptorMap
|
|
7
|
+
): number {
|
|
8
|
+
if (routes.length === 0) {
|
|
9
|
+
return 1;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
let limit = 1;
|
|
13
|
+
|
|
14
|
+
for (let i = routes.length - 1; i >= 0; i--) {
|
|
15
|
+
const route = routes[i];
|
|
16
|
+
|
|
17
|
+
const shouldKeepPrevious =
|
|
18
|
+
descriptors?.[route.key]?.options?.detachPreviousScreen !== true;
|
|
19
|
+
|
|
20
|
+
if (shouldKeepPrevious) {
|
|
21
|
+
limit++;
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return Math.min(limit, routes.length);
|
|
29
|
+
}
|
package/src/integrations/blank-stack/utils/with-stack-navigation/_utils/compose-descriptors.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Route } from "@react-navigation/native";
|
|
2
|
+
import type { BlankStackDescriptorMap } from "../../../../../types/blank-stack.navigator";
|
|
3
|
+
|
|
4
|
+
export const composeDescriptors = (
|
|
5
|
+
routes: Route<string>[],
|
|
6
|
+
nextDescriptors: BlankStackDescriptorMap,
|
|
7
|
+
currentDescriptors: BlankStackDescriptorMap
|
|
8
|
+
): BlankStackDescriptorMap => {
|
|
9
|
+
const composed: BlankStackDescriptorMap = {};
|
|
10
|
+
|
|
11
|
+
for (const route of routes) {
|
|
12
|
+
composed[route.key] =
|
|
13
|
+
nextDescriptors[route.key] ?? currentDescriptors[route.key];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return composed;
|
|
17
|
+
};
|
package/src/integrations/blank-stack/utils/with-stack-navigation/_utils/have-same-route-keys.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Route } from "@react-navigation/native";
|
|
2
|
+
|
|
3
|
+
export const haveSameRouteKeys = (
|
|
4
|
+
previous: Route<string>[],
|
|
5
|
+
next: Route<string>[],
|
|
6
|
+
): boolean => {
|
|
7
|
+
if (previous.length !== next.length) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return previous.every((route, index) => route?.key === next[index]?.key);
|
|
12
|
+
};
|