react-native-screen-transitions 3.2.0 → 3.3.0-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.
Files changed (152) hide show
  1. package/README.md +1 -1
  2. package/lib/commonjs/shared/components/create-transition-aware-component.js +8 -2
  3. package/lib/commonjs/shared/components/create-transition-aware-component.js.map +1 -1
  4. package/lib/commonjs/shared/components/{root-transition-aware.js → screen-container.js} +28 -12
  5. package/lib/commonjs/shared/components/screen-container.js.map +1 -0
  6. package/lib/commonjs/shared/configs/presets.js +3 -3
  7. package/lib/commonjs/shared/configs/presets.js.map +1 -1
  8. package/lib/commonjs/shared/configs/specs.js +6 -1
  9. package/lib/commonjs/shared/configs/specs.js.map +1 -1
  10. package/lib/commonjs/shared/hooks/gestures/use-build-gestures.js +36 -188
  11. package/lib/commonjs/shared/hooks/gestures/use-build-gestures.js.map +1 -1
  12. package/lib/commonjs/shared/hooks/gestures/use-screen-gesture-handlers.js +334 -0
  13. package/lib/commonjs/shared/hooks/gestures/use-screen-gesture-handlers.js.map +1 -0
  14. package/lib/commonjs/shared/hooks/gestures/use-scroll-registry.js +47 -4
  15. package/lib/commonjs/shared/hooks/gestures/use-scroll-registry.js.map +1 -1
  16. package/lib/commonjs/shared/hooks/lifecycle/use-close-transition.js +3 -3
  17. package/lib/commonjs/shared/hooks/lifecycle/use-close-transition.js.map +1 -1
  18. package/lib/commonjs/shared/hooks/lifecycle/use-open-transition.js +25 -3
  19. package/lib/commonjs/shared/hooks/lifecycle/use-open-transition.js.map +1 -1
  20. package/lib/commonjs/shared/hooks/navigation/use-screen-state.js +61 -2
  21. package/lib/commonjs/shared/hooks/navigation/use-screen-state.js.map +1 -1
  22. package/lib/commonjs/shared/hooks/use-backdrop-pointer-events.js +32 -0
  23. package/lib/commonjs/shared/hooks/use-backdrop-pointer-events.js.map +1 -0
  24. package/lib/commonjs/shared/providers/gestures.provider.js +4 -2
  25. package/lib/commonjs/shared/providers/gestures.provider.js.map +1 -1
  26. package/lib/commonjs/shared/providers/screen/screen-composer.js +2 -2
  27. package/lib/commonjs/shared/providers/screen/screen-composer.js.map +1 -1
  28. package/lib/commonjs/shared/providers/screen/styles.provider.js +41 -32
  29. package/lib/commonjs/shared/providers/screen/styles.provider.js.map +1 -1
  30. package/lib/commonjs/shared/utils/animation/{start-screen-transition.js → animate-to-progress.js} +11 -7
  31. package/lib/commonjs/shared/utils/animation/animate-to-progress.js.map +1 -0
  32. package/lib/commonjs/shared/utils/gesture/check-gesture-activation.js +71 -0
  33. package/lib/commonjs/shared/utils/gesture/check-gesture-activation.js.map +1 -1
  34. package/lib/commonjs/shared/utils/gesture/determine-snap-target.js +56 -0
  35. package/lib/commonjs/shared/utils/gesture/determine-snap-target.js.map +1 -0
  36. package/lib/commonjs/shared/utils/gesture/validate-snap-points.js +31 -0
  37. package/lib/commonjs/shared/utils/gesture/validate-snap-points.js.map +1 -0
  38. package/lib/commonjs/shared/utils/gesture/velocity.js +11 -0
  39. package/lib/commonjs/shared/utils/gesture/velocity.js.map +1 -1
  40. package/lib/module/shared/components/create-transition-aware-component.js +8 -2
  41. package/lib/module/shared/components/create-transition-aware-component.js.map +1 -1
  42. package/lib/module/shared/components/screen-container.js +64 -0
  43. package/lib/module/shared/components/screen-container.js.map +1 -0
  44. package/lib/module/shared/configs/presets.js +3 -3
  45. package/lib/module/shared/configs/presets.js.map +1 -1
  46. package/lib/module/shared/configs/specs.js +5 -0
  47. package/lib/module/shared/configs/specs.js.map +1 -1
  48. package/lib/module/shared/hooks/gestures/use-build-gestures.js +36 -187
  49. package/lib/module/shared/hooks/gestures/use-build-gestures.js.map +1 -1
  50. package/lib/module/shared/hooks/gestures/use-screen-gesture-handlers.js +328 -0
  51. package/lib/module/shared/hooks/gestures/use-screen-gesture-handlers.js.map +1 -0
  52. package/lib/module/shared/hooks/gestures/use-scroll-registry.js +47 -4
  53. package/lib/module/shared/hooks/gestures/use-scroll-registry.js.map +1 -1
  54. package/lib/module/shared/hooks/lifecycle/use-close-transition.js +3 -3
  55. package/lib/module/shared/hooks/lifecycle/use-close-transition.js.map +1 -1
  56. package/lib/module/shared/hooks/lifecycle/use-open-transition.js +25 -3
  57. package/lib/module/shared/hooks/lifecycle/use-open-transition.js.map +1 -1
  58. package/lib/module/shared/hooks/navigation/use-screen-state.js +63 -4
  59. package/lib/module/shared/hooks/navigation/use-screen-state.js.map +1 -1
  60. package/lib/module/shared/hooks/use-backdrop-pointer-events.js +28 -0
  61. package/lib/module/shared/hooks/use-backdrop-pointer-events.js.map +1 -0
  62. package/lib/module/shared/providers/gestures.provider.js +4 -2
  63. package/lib/module/shared/providers/gestures.provider.js.map +1 -1
  64. package/lib/module/shared/providers/screen/screen-composer.js +2 -2
  65. package/lib/module/shared/providers/screen/screen-composer.js.map +1 -1
  66. package/lib/module/shared/providers/screen/styles.provider.js +41 -32
  67. package/lib/module/shared/providers/screen/styles.provider.js.map +1 -1
  68. package/lib/module/shared/utils/animation/{start-screen-transition.js → animate-to-progress.js} +9 -5
  69. package/lib/module/shared/utils/animation/animate-to-progress.js.map +1 -0
  70. package/lib/module/shared/utils/gesture/check-gesture-activation.js +70 -0
  71. package/lib/module/shared/utils/gesture/check-gesture-activation.js.map +1 -1
  72. package/lib/module/shared/utils/gesture/determine-snap-target.js +52 -0
  73. package/lib/module/shared/utils/gesture/determine-snap-target.js.map +1 -0
  74. package/lib/module/shared/utils/gesture/validate-snap-points.js +26 -0
  75. package/lib/module/shared/utils/gesture/validate-snap-points.js.map +1 -0
  76. package/lib/module/shared/utils/gesture/velocity.js +11 -0
  77. package/lib/module/shared/utils/gesture/velocity.js.map +1 -1
  78. package/lib/typescript/shared/components/create-transition-aware-component.d.ts.map +1 -1
  79. package/lib/typescript/shared/components/screen-container.d.ts +6 -0
  80. package/lib/typescript/shared/components/screen-container.d.ts.map +1 -0
  81. package/lib/typescript/shared/configs/specs.d.ts +1 -0
  82. package/lib/typescript/shared/configs/specs.d.ts.map +1 -1
  83. package/lib/typescript/shared/hooks/gestures/use-build-gestures.d.ts +1 -1
  84. package/lib/typescript/shared/hooks/gestures/use-build-gestures.d.ts.map +1 -1
  85. package/lib/typescript/shared/hooks/gestures/use-screen-gesture-handlers.d.ts +34 -0
  86. package/lib/typescript/shared/hooks/gestures/use-screen-gesture-handlers.d.ts.map +1 -0
  87. package/lib/typescript/shared/hooks/gestures/use-scroll-registry.d.ts +5 -1
  88. package/lib/typescript/shared/hooks/gestures/use-scroll-registry.d.ts.map +1 -1
  89. package/lib/typescript/shared/hooks/lifecycle/use-open-transition.d.ts.map +1 -1
  90. package/lib/typescript/shared/hooks/navigation/use-screen-state.d.ts +14 -0
  91. package/lib/typescript/shared/hooks/navigation/use-screen-state.d.ts.map +1 -1
  92. package/lib/typescript/shared/hooks/use-backdrop-pointer-events.d.ts +15 -0
  93. package/lib/typescript/shared/hooks/use-backdrop-pointer-events.d.ts.map +1 -0
  94. package/lib/typescript/shared/providers/gestures.provider.d.ts +1 -0
  95. package/lib/typescript/shared/providers/gestures.provider.d.ts.map +1 -1
  96. package/lib/typescript/shared/providers/screen/styles.provider.d.ts.map +1 -1
  97. package/lib/typescript/shared/types/animation.types.d.ts +28 -2
  98. package/lib/typescript/shared/types/animation.types.d.ts.map +1 -1
  99. package/lib/typescript/shared/types/screen.types.d.ts +26 -0
  100. package/lib/typescript/shared/types/screen.types.d.ts.map +1 -1
  101. package/lib/typescript/shared/utils/animation/animate-to-progress.d.ts +19 -0
  102. package/lib/typescript/shared/utils/animation/animate-to-progress.d.ts.map +1 -0
  103. package/lib/typescript/shared/utils/gesture/check-gesture-activation.d.ts +24 -0
  104. package/lib/typescript/shared/utils/gesture/check-gesture-activation.d.ts.map +1 -1
  105. package/lib/typescript/shared/utils/gesture/determine-snap-target.d.ts +26 -0
  106. package/lib/typescript/shared/utils/gesture/determine-snap-target.d.ts.map +1 -0
  107. package/lib/typescript/shared/utils/gesture/validate-snap-points.d.ts +13 -0
  108. package/lib/typescript/shared/utils/gesture/validate-snap-points.d.ts.map +1 -0
  109. package/lib/typescript/shared/utils/gesture/velocity.d.ts +1 -0
  110. package/lib/typescript/shared/utils/gesture/velocity.d.ts.map +1 -1
  111. package/package.json +29 -2
  112. package/src/shared/__tests__/determine-snap-target.test.ts +268 -0
  113. package/src/shared/__tests__/gesture-activation.test.ts +247 -0
  114. package/src/shared/__tests__/validate-snap-points.test.ts +125 -0
  115. package/src/shared/components/create-transition-aware-component.tsx +11 -1
  116. package/src/shared/components/screen-container.tsx +65 -0
  117. package/src/shared/configs/presets.ts +3 -3
  118. package/src/shared/configs/specs.ts +6 -0
  119. package/src/shared/hooks/gestures/use-build-gestures.tsx +33 -253
  120. package/src/shared/hooks/gestures/use-screen-gesture-handlers.ts +436 -0
  121. package/src/shared/hooks/gestures/use-scroll-registry.tsx +52 -1
  122. package/src/shared/hooks/lifecycle/use-close-transition.ts +3 -3
  123. package/src/shared/hooks/lifecycle/use-open-transition.ts +27 -3
  124. package/src/shared/hooks/navigation/use-screen-state.tsx +106 -2
  125. package/src/shared/hooks/use-backdrop-pointer-events.ts +32 -0
  126. package/src/shared/providers/gestures.provider.tsx +3 -2
  127. package/src/shared/providers/screen/screen-composer.tsx +2 -2
  128. package/src/shared/providers/screen/styles.provider.tsx +40 -34
  129. package/src/shared/types/animation.types.ts +29 -2
  130. package/src/shared/types/screen.types.ts +29 -0
  131. package/src/shared/utils/animation/{start-screen-transition.ts → animate-to-progress.ts} +19 -7
  132. package/src/shared/utils/gesture/check-gesture-activation.ts +78 -0
  133. package/src/shared/utils/gesture/determine-snap-target.ts +75 -0
  134. package/src/shared/utils/gesture/validate-snap-points.ts +37 -0
  135. package/src/shared/utils/gesture/velocity.ts +10 -0
  136. package/lib/commonjs/shared/components/root-transition-aware.js.map +0 -1
  137. package/lib/commonjs/shared/hooks/use-stack-pointer-events.js +0 -23
  138. package/lib/commonjs/shared/hooks/use-stack-pointer-events.js.map +0 -1
  139. package/lib/commonjs/shared/utils/animation/start-screen-transition.js.map +0 -1
  140. package/lib/module/shared/components/root-transition-aware.js +0 -48
  141. package/lib/module/shared/components/root-transition-aware.js.map +0 -1
  142. package/lib/module/shared/hooks/use-stack-pointer-events.js +0 -20
  143. package/lib/module/shared/hooks/use-stack-pointer-events.js.map +0 -1
  144. package/lib/module/shared/utils/animation/start-screen-transition.js.map +0 -1
  145. package/lib/typescript/shared/components/root-transition-aware.d.ts +0 -6
  146. package/lib/typescript/shared/components/root-transition-aware.d.ts.map +0 -1
  147. package/lib/typescript/shared/hooks/use-stack-pointer-events.d.ts +0 -10
  148. package/lib/typescript/shared/hooks/use-stack-pointer-events.d.ts.map +0 -1
  149. package/lib/typescript/shared/utils/animation/start-screen-transition.d.ts +0 -13
  150. package/lib/typescript/shared/utils/animation/start-screen-transition.d.ts.map +0 -1
  151. package/src/shared/components/root-transition-aware.tsx +0 -49
  152. package/src/shared/hooks/use-stack-pointer-events.ts +0 -15
@@ -0,0 +1,65 @@
1
+ import { StackActions } from "@react-navigation/native";
2
+ import { memo, useCallback } from "react";
3
+ import { Pressable, StyleSheet, View } from "react-native";
4
+ import Animated, { useAnimatedStyle } from "react-native-reanimated";
5
+ import { NO_STYLES } from "../constants";
6
+ import { useBackdropPointerEvents } from "../hooks/use-backdrop-pointer-events";
7
+ import { useKeys } from "../providers/screen/keys.provider";
8
+ import { useScreenStyles } from "../providers/screen/styles.provider";
9
+
10
+ type Props = {
11
+ children: React.ReactNode;
12
+ };
13
+
14
+ export const ScreenContainer = memo(({ children }: Props) => {
15
+ const { stylesMap } = useScreenStyles();
16
+ const { current } = useKeys();
17
+ const { pointerEvents, backdropBehavior } = useBackdropPointerEvents();
18
+
19
+ const isDismissable = backdropBehavior === "dismiss";
20
+
21
+ const handleBackdropPress = useCallback(() => {
22
+ current.navigation.dispatch(StackActions.pop());
23
+ }, [current.navigation]);
24
+
25
+ const animatedContentStyle = useAnimatedStyle(() => {
26
+ "worklet";
27
+ return stylesMap.value.contentStyle || NO_STYLES;
28
+ });
29
+
30
+ const animatedBackdropStyle = useAnimatedStyle(() => {
31
+ "worklet";
32
+ return (
33
+ stylesMap.value.backdropStyle ?? stylesMap.value.overlayStyle ?? NO_STYLES
34
+ );
35
+ });
36
+
37
+ return (
38
+ <View style={styles.container} pointerEvents={pointerEvents}>
39
+ <Pressable
40
+ style={StyleSheet.absoluteFillObject}
41
+ pointerEvents={isDismissable ? "auto" : "none"}
42
+ onPress={isDismissable ? handleBackdropPress : undefined}
43
+ >
44
+ <Animated.View
45
+ style={[StyleSheet.absoluteFillObject, animatedBackdropStyle]}
46
+ />
47
+ </Pressable>
48
+ <Animated.View
49
+ style={[styles.content, animatedContentStyle]}
50
+ pointerEvents={isDismissable ? "box-none" : pointerEvents}
51
+ >
52
+ {children}
53
+ </Animated.View>
54
+ </View>
55
+ );
56
+ });
57
+
58
+ const styles = StyleSheet.create({
59
+ container: {
60
+ flex: 1,
61
+ },
62
+ content: {
63
+ flex: 1,
64
+ },
65
+ });
@@ -208,7 +208,7 @@ export const ElasticCard = (
208
208
  contentStyle: {
209
209
  transform: [{ scale }, { translateX }, { translateY }],
210
210
  },
211
- overlayStyle: {
211
+ backdropStyle: {
212
212
  backgroundColor: !next ? overlayColor : "rgba(0,0,0,0)",
213
213
  },
214
214
  };
@@ -281,7 +281,7 @@ export const SharedIGImage = ({
281
281
  });
282
282
 
283
283
  return {
284
- overlayStyle: {
284
+ backdropStyle: {
285
285
  backgroundColor: "black",
286
286
  opacity: interpolate(progress, [0, 1], [0, 0.5]),
287
287
  },
@@ -634,7 +634,7 @@ export const SharedXImage = ({
634
634
  transform: [{ translateY: contentY }, { translateY: dragY }],
635
635
  pointerEvents: current.animating ? "none" : "auto",
636
636
  },
637
- overlayStyle: {
637
+ backdropStyle: {
638
638
  backgroundColor: overlayClr,
639
639
  },
640
640
  };
@@ -8,3 +8,9 @@ export const DefaultSpec: WithSpringConfig = {
8
8
  // @ts-expect-error
9
9
  restSpeedThreshold: 0.02,
10
10
  };
11
+
12
+ export const DefaultSnapSpec: WithSpringConfig = {
13
+ stiffness: 500,
14
+ damping: 50,
15
+ mass: 1,
16
+ };
@@ -1,16 +1,8 @@
1
1
  import { StackActions } from "@react-navigation/native";
2
2
  import { useCallback, useMemo, useRef } from "react";
3
3
  import { useWindowDimensions } from "react-native";
4
- import {
5
- Gesture,
6
- type GestureStateChangeEvent,
7
- type GestureTouchEvent,
8
- type GestureType,
9
- type GestureUpdateEvent,
10
- type PanGestureHandlerEventPayload,
11
- } from "react-native-gesture-handler";
12
- import type { GestureStateManagerType } from "react-native-gesture-handler/lib/typescript/handlers/gestures/gestureStateManager";
13
- import { type SharedValue, useSharedValue } from "react-native-reanimated";
4
+ import { Gesture, type GestureType } from "react-native-gesture-handler";
5
+ import type { SharedValue } from "react-native-reanimated";
14
6
  import {
15
7
  DEFAULT_GESTURE_ACTIVATION_AREA,
16
8
  DEFAULT_GESTURE_DIRECTION,
@@ -24,17 +16,7 @@ import type {
24
16
  import { useKeys } from "../../providers/screen/keys.provider";
25
17
  import { AnimationStore } from "../../stores/animation.store";
26
18
  import { GestureStore, type GestureStoreMap } from "../../stores/gesture.store";
27
- import {
28
- type GestureDirection,
29
- GestureOffsetState,
30
- } from "../../types/gesture.types";
31
- import { startScreenTransition } from "../../utils/animation/start-screen-transition";
32
- import { applyOffsetRules } from "../../utils/gesture/check-gesture-activation";
33
- import { determineDismissal } from "../../utils/gesture/determine-dismissal";
34
- import { mapGestureToProgress } from "../../utils/gesture/map-gesture-to-progress";
35
- import { resetGestureValues } from "../../utils/gesture/reset-gesture-values";
36
- import { velocity } from "../../utils/gesture/velocity";
37
- import useStableCallbackValue from "../use-stable-callback-value";
19
+ import { useScreenGestureHandlers } from "./use-screen-gesture-handlers";
38
20
 
39
21
  interface BuildGesturesHookProps {
40
22
  scrollConfig: SharedValue<ScrollConfig | null>;
@@ -53,18 +35,12 @@ export const useBuildGestures = ({
53
35
  const dimensions = useWindowDimensions();
54
36
 
55
37
  const { current } = useKeys();
56
- const navState = current.navigation.getState();
57
- const isFirstScreen =
58
- navState.routes.findIndex((r) => r.key === current.route.key) === 0;
59
38
 
60
- const initialTouch = useSharedValue({
61
- x: 0,
62
- y: 0,
63
- });
39
+ const navState = current.navigation.getState();
64
40
 
65
- const gestureOffsetState = useSharedValue<GestureOffsetState>(
66
- GestureOffsetState.PENDING,
67
- );
41
+ const isFirstScreen = useMemo(() => {
42
+ return navState.routes.findIndex((r) => r.key === current.route.key) === 0;
43
+ }, [navState.routes, current.route.key]);
68
44
 
69
45
  // Ref for external gesture coordination (e.g., swipeable lists)
70
46
  const panGestureRef = useRef<GestureType | undefined>(undefined);
@@ -81,27 +57,19 @@ export const useBuildGestures = ({
81
57
  gestureActivationArea = DEFAULT_GESTURE_ACTIVATION_AREA,
82
58
  gestureResponseDistance,
83
59
  transitionSpec,
60
+ snapPoints,
84
61
  } = current.options;
85
62
 
86
- const gestureEnabled = Boolean(
63
+ // Dismiss gesture is controlled by gestureEnabled (disabled for first screen)
64
+ const canDismiss = Boolean(
87
65
  isFirstScreen ? false : current.options.gestureEnabled,
88
66
  );
89
67
 
90
- const directions = useMemo(() => {
91
- const directionsArray = Array.isArray(gestureDirection)
92
- ? gestureDirection
93
- : [gestureDirection];
94
- const isBidirectional = directionsArray.includes("bidirectional");
95
-
96
- return {
97
- vertical: directionsArray.includes("vertical") || isBidirectional,
98
- verticalInverted:
99
- directionsArray.includes("vertical-inverted") || isBidirectional,
100
- horizontal: directionsArray.includes("horizontal") || isBidirectional,
101
- horizontalInverted:
102
- directionsArray.includes("horizontal-inverted") || isBidirectional,
103
- };
104
- }, [gestureDirection]);
68
+ // Snap navigation works independently - enabled when snap points exist
69
+ // This matches iOS native sheet behavior where gestureEnabled: false
70
+ // disables dismiss but you can still drag between detents
71
+ const hasSnapPoints = Array.isArray(snapPoints) && snapPoints.length > 0;
72
+ const gestureEnabled = canDismiss || hasSnapPoints;
105
73
 
106
74
  const handleDismiss = useCallback(() => {
107
75
  // If an ancestor navigator is already dismissing, skip this dismiss to
@@ -127,212 +95,24 @@ export const useBuildGestures = ({
127
95
  });
128
96
  }, [current, ancestorContext]);
129
97
 
130
- const onTouchesDown = useStableCallbackValue((e: GestureTouchEvent) => {
131
- "worklet";
132
- const firstTouch = e.changedTouches[0];
133
- initialTouch.value = { x: firstTouch.x, y: firstTouch.y };
134
- gestureOffsetState.value = GestureOffsetState.PENDING;
135
- });
136
-
137
- const onTouchesMove = useStableCallbackValue(
138
- (e: GestureTouchEvent, manager: GestureStateManagerType) => {
139
- "worklet";
140
-
141
- // If an ancestor navigator is already dismissing via gesture, block new gestures here.
142
- if (ancestorContext?.gestureAnimationValues.isDismissing?.value) {
143
- gestureOffsetState.value = GestureOffsetState.FAILED;
144
- manager.fail();
145
- return;
146
- }
147
-
148
- const touch = e.changedTouches[0];
149
-
150
- const { isSwipingDown, isSwipingUp, isSwipingRight, isSwipingLeft } =
151
- applyOffsetRules({
152
- touch,
153
- directions,
154
- manager,
155
- dimensions,
156
- gestureOffsetState,
157
- initialTouch: initialTouch.value,
158
- activationArea: gestureActivationArea,
159
- responseDistance: gestureResponseDistance,
160
- });
161
-
162
- if (gestureOffsetState.value === GestureOffsetState.FAILED) {
163
- manager.fail();
164
- return;
165
- }
166
-
167
- // Keep pending until thresholds are met; no eager activation.
168
- if (gestureAnimationValues.isDragging?.value) {
169
- manager.activate();
170
- return;
171
- }
172
-
173
- const maxScrollY = scrollConfig.value?.contentHeight
174
- ? scrollConfig.value.contentHeight - scrollConfig.value.layoutHeight
175
- : 0;
176
-
177
- const maxScrollX = scrollConfig.value?.contentWidth
178
- ? scrollConfig.value.contentWidth - scrollConfig.value.layoutWidth
179
- : 0;
180
-
181
- const recognizedDirection =
182
- isSwipingDown || isSwipingUp || isSwipingRight || isSwipingLeft;
183
-
184
- const scrollCfg = scrollConfig.value;
185
-
186
- let shouldActivate = false;
187
- let activatedDirection: GestureDirection | null = null;
188
-
189
- if (recognizedDirection) {
190
- if (directions.vertical && isSwipingDown) {
191
- shouldActivate = scrollCfg ? scrollCfg.y <= 0 : true;
192
- if (shouldActivate) activatedDirection = "vertical";
193
- }
194
- if (directions.horizontal && isSwipingRight) {
195
- shouldActivate = scrollCfg ? scrollCfg.x <= 0 : true;
196
- if (shouldActivate) activatedDirection = "horizontal";
197
- }
198
- if (directions.verticalInverted && isSwipingUp) {
199
- shouldActivate = scrollCfg ? scrollCfg.y >= maxScrollY : true;
200
- if (shouldActivate) activatedDirection = "vertical-inverted";
201
- }
202
- if (directions.horizontalInverted && isSwipingLeft) {
203
- shouldActivate = scrollCfg ? scrollCfg.x >= maxScrollX : true;
204
- if (shouldActivate) activatedDirection = "horizontal-inverted";
205
- }
206
- }
207
-
208
- if (recognizedDirection && !shouldActivate) {
209
- manager.fail();
210
- return;
211
- }
212
-
213
- if (
214
- shouldActivate &&
215
- gestureOffsetState.value === GestureOffsetState.PASSED &&
216
- !gestureAnimationValues.isDismissing?.value
217
- ) {
218
- gestureAnimationValues.direction.value = activatedDirection;
219
- manager.activate();
220
- return;
221
- }
222
- },
223
- );
224
-
225
- const onStart = useStableCallbackValue(() => {
226
- "worklet";
227
- gestureAnimationValues.isDragging.value = 1;
228
- gestureAnimationValues.isDismissing.value = 0;
229
- });
230
-
231
- const onUpdate = useStableCallbackValue(
232
- (event: GestureUpdateEvent<PanGestureHandlerEventPayload>) => {
233
- "worklet";
234
-
235
- let gestureProgress = 0;
236
-
237
- const { translationX, translationY } = event;
238
- const { width, height } = dimensions;
239
-
240
- gestureAnimationValues.x.value = translationX;
241
- gestureAnimationValues.y.value = translationY;
242
- gestureAnimationValues.normalizedX.value = Math.max(
243
- -1,
244
- Math.min(1, translationX / width),
245
- );
246
- gestureAnimationValues.normalizedY.value = Math.max(
247
- -1,
248
- Math.min(1, translationY / height),
249
- );
250
-
251
- let maxProgress = 0;
252
-
253
- const allowedDown = directions.vertical;
254
- const allowedUp = directions.verticalInverted;
255
- const allowedRight = directions.horizontal;
256
- const allowedLeft = directions.horizontalInverted;
257
-
258
- if (allowedRight && event.translationX > 0) {
259
- const currentProgress = mapGestureToProgress(
260
- translationX,
261
- dimensions.width,
262
- );
263
- maxProgress = Math.max(maxProgress, currentProgress);
264
- }
265
-
266
- if (allowedLeft && event.translationX < 0) {
267
- const currentProgress = mapGestureToProgress(
268
- -translationX,
269
- dimensions.width,
270
- );
271
- maxProgress = Math.max(maxProgress, currentProgress);
272
- }
273
-
274
- if (allowedDown && event.translationY > 0) {
275
- const currentProgress = mapGestureToProgress(
276
- translationY,
277
- dimensions.height,
278
- );
279
- maxProgress = Math.max(maxProgress, currentProgress);
280
- }
281
-
282
- if (allowedUp && event.translationY < 0) {
283
- const currentProgress = mapGestureToProgress(
284
- -translationY,
285
- dimensions.height,
286
- );
287
- maxProgress = Math.max(maxProgress, currentProgress);
288
- }
289
-
290
- gestureProgress = maxProgress;
291
-
292
- if (gestureDrivesProgress) {
293
- animations.progress.value = 1 - gestureProgress;
294
- }
295
- },
296
- );
297
-
298
- const onEnd = useStableCallbackValue(
299
- (event: GestureStateChangeEvent<PanGestureHandlerEventPayload>) => {
300
- "worklet";
301
-
302
- const { shouldDismiss } = determineDismissal({
303
- event,
304
- directions,
305
- dimensions,
306
- gestureVelocityImpact,
307
- });
308
-
309
- const spec = shouldDismiss ? transitionSpec?.close : transitionSpec?.open;
310
-
311
- resetGestureValues({
312
- spec,
313
- gestures: gestureAnimationValues,
314
- shouldDismiss,
315
- event,
316
- dimensions,
317
- });
318
-
319
- const initialVelocity = velocity.calculateProgressVelocity({
320
- animations,
321
- shouldDismiss,
322
- event,
323
- dimensions,
324
- directions,
325
- });
326
-
327
- startScreenTransition({
328
- target: shouldDismiss ? "close" : "open",
329
- onAnimationFinish: shouldDismiss ? handleDismiss : undefined,
330
- spec: transitionSpec,
331
- animations,
332
- initialVelocity,
333
- });
334
- },
335
- );
98
+ const { onTouchesDown, onTouchesMove, onStart, onUpdate, onEnd } =
99
+ useScreenGestureHandlers({
100
+ dimensions,
101
+ animations,
102
+ gestureAnimationValues,
103
+ gestureDirection,
104
+ gestureDrivesProgress,
105
+ gestureVelocityImpact,
106
+ scrollConfig,
107
+ gestureActivationArea,
108
+ gestureResponseDistance,
109
+ snapPoints,
110
+ canDismiss,
111
+ transitionSpec,
112
+ handleDismiss,
113
+ ancestorIsDismissing:
114
+ ancestorContext?.gestureAnimationValues.isDismissing,
115
+ });
336
116
 
337
117
  // Memoize gestures to keep stable references - critical for RNGH
338
118
  // Child gestures reference ancestor's pan via requireExternalGestureToFail,