react-native-screen-transitions 3.2.1 → 3.3.0-beta.1

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 (173) hide show
  1. package/README.md +105 -10
  2. package/lib/commonjs/blank-stack/components/adjusted-screen.js +2 -2
  3. package/lib/commonjs/blank-stack/components/adjusted-screen.js.map +1 -1
  4. package/lib/commonjs/shared/components/create-transition-aware-component.js +8 -2
  5. package/lib/commonjs/shared/components/create-transition-aware-component.js.map +1 -1
  6. package/lib/commonjs/shared/components/{root-transition-aware.js → screen-container.js} +28 -12
  7. package/lib/commonjs/shared/components/screen-container.js.map +1 -0
  8. package/lib/commonjs/shared/configs/presets.js +3 -3
  9. package/lib/commonjs/shared/configs/presets.js.map +1 -1
  10. package/lib/commonjs/shared/configs/specs.js +6 -1
  11. package/lib/commonjs/shared/configs/specs.js.map +1 -1
  12. package/lib/commonjs/shared/constants.js +36 -10
  13. package/lib/commonjs/shared/constants.js.map +1 -1
  14. package/lib/commonjs/shared/hooks/animation/use-screen-animation.js +25 -18
  15. package/lib/commonjs/shared/hooks/animation/use-screen-animation.js.map +1 -1
  16. package/lib/commonjs/shared/hooks/gestures/use-build-gestures.js +25 -202
  17. package/lib/commonjs/shared/hooks/gestures/use-build-gestures.js.map +1 -1
  18. package/lib/commonjs/shared/hooks/gestures/use-screen-gesture-handlers.js +342 -0
  19. package/lib/commonjs/shared/hooks/gestures/use-screen-gesture-handlers.js.map +1 -0
  20. package/lib/commonjs/shared/hooks/gestures/use-scroll-registry.js +47 -4
  21. package/lib/commonjs/shared/hooks/gestures/use-scroll-registry.js.map +1 -1
  22. package/lib/commonjs/shared/hooks/lifecycle/use-close-transition.js +3 -3
  23. package/lib/commonjs/shared/hooks/lifecycle/use-close-transition.js.map +1 -1
  24. package/lib/commonjs/shared/hooks/lifecycle/use-open-transition.js +25 -3
  25. package/lib/commonjs/shared/hooks/lifecycle/use-open-transition.js.map +1 -1
  26. package/lib/commonjs/shared/hooks/navigation/use-screen-state.js +33 -2
  27. package/lib/commonjs/shared/hooks/navigation/use-screen-state.js.map +1 -1
  28. package/lib/commonjs/shared/hooks/use-backdrop-pointer-events.js +32 -0
  29. package/lib/commonjs/shared/hooks/use-backdrop-pointer-events.js.map +1 -0
  30. package/lib/commonjs/shared/providers/gestures.provider.js +4 -2
  31. package/lib/commonjs/shared/providers/gestures.provider.js.map +1 -1
  32. package/lib/commonjs/shared/providers/screen/screen-composer.js +2 -2
  33. package/lib/commonjs/shared/providers/screen/screen-composer.js.map +1 -1
  34. package/lib/commonjs/shared/utils/animation/{start-screen-transition.js → animate-to-progress.js} +16 -8
  35. package/lib/commonjs/shared/utils/animation/animate-to-progress.js.map +1 -0
  36. package/lib/commonjs/shared/utils/gesture/check-gesture-activation.js +138 -0
  37. package/lib/commonjs/shared/utils/gesture/check-gesture-activation.js.map +1 -1
  38. package/lib/commonjs/shared/utils/gesture/determine-snap-target.js +56 -0
  39. package/lib/commonjs/shared/utils/gesture/determine-snap-target.js.map +1 -0
  40. package/lib/commonjs/shared/utils/gesture/validate-snap-points.js +31 -0
  41. package/lib/commonjs/shared/utils/gesture/validate-snap-points.js.map +1 -0
  42. package/lib/commonjs/shared/utils/gesture/velocity.js +11 -0
  43. package/lib/commonjs/shared/utils/gesture/velocity.js.map +1 -1
  44. package/lib/commonjs/shared/utils/logger.js +22 -0
  45. package/lib/commonjs/shared/utils/logger.js.map +1 -0
  46. package/lib/module/blank-stack/components/adjusted-screen.js +1 -1
  47. package/lib/module/blank-stack/components/adjusted-screen.js.map +1 -1
  48. package/lib/module/shared/components/create-transition-aware-component.js +8 -2
  49. package/lib/module/shared/components/create-transition-aware-component.js.map +1 -1
  50. package/lib/module/shared/components/screen-container.js +64 -0
  51. package/lib/module/shared/components/screen-container.js.map +1 -0
  52. package/lib/module/shared/configs/presets.js +3 -3
  53. package/lib/module/shared/configs/presets.js.map +1 -1
  54. package/lib/module/shared/configs/specs.js +5 -0
  55. package/lib/module/shared/configs/specs.js.map +1 -1
  56. package/lib/module/shared/constants.js +34 -9
  57. package/lib/module/shared/constants.js.map +1 -1
  58. package/lib/module/shared/hooks/animation/use-screen-animation.js +25 -18
  59. package/lib/module/shared/hooks/animation/use-screen-animation.js.map +1 -1
  60. package/lib/module/shared/hooks/gestures/use-build-gestures.js +25 -201
  61. package/lib/module/shared/hooks/gestures/use-build-gestures.js.map +1 -1
  62. package/lib/module/shared/hooks/gestures/use-screen-gesture-handlers.js +336 -0
  63. package/lib/module/shared/hooks/gestures/use-screen-gesture-handlers.js.map +1 -0
  64. package/lib/module/shared/hooks/gestures/use-scroll-registry.js +47 -4
  65. package/lib/module/shared/hooks/gestures/use-scroll-registry.js.map +1 -1
  66. package/lib/module/shared/hooks/lifecycle/use-close-transition.js +3 -3
  67. package/lib/module/shared/hooks/lifecycle/use-close-transition.js.map +1 -1
  68. package/lib/module/shared/hooks/lifecycle/use-open-transition.js +25 -3
  69. package/lib/module/shared/hooks/lifecycle/use-open-transition.js.map +1 -1
  70. package/lib/module/shared/hooks/navigation/use-screen-state.js +35 -4
  71. package/lib/module/shared/hooks/navigation/use-screen-state.js.map +1 -1
  72. package/lib/module/shared/hooks/use-backdrop-pointer-events.js +28 -0
  73. package/lib/module/shared/hooks/use-backdrop-pointer-events.js.map +1 -0
  74. package/lib/module/shared/providers/gestures.provider.js +4 -2
  75. package/lib/module/shared/providers/gestures.provider.js.map +1 -1
  76. package/lib/module/shared/providers/screen/screen-composer.js +2 -2
  77. package/lib/module/shared/providers/screen/screen-composer.js.map +1 -1
  78. package/lib/module/shared/utils/animation/{start-screen-transition.js → animate-to-progress.js} +14 -6
  79. package/lib/module/shared/utils/animation/animate-to-progress.js.map +1 -0
  80. package/lib/module/shared/utils/gesture/check-gesture-activation.js +137 -0
  81. package/lib/module/shared/utils/gesture/check-gesture-activation.js.map +1 -1
  82. package/lib/module/shared/utils/gesture/determine-snap-target.js +52 -0
  83. package/lib/module/shared/utils/gesture/determine-snap-target.js.map +1 -0
  84. package/lib/module/shared/utils/gesture/validate-snap-points.js +26 -0
  85. package/lib/module/shared/utils/gesture/validate-snap-points.js.map +1 -0
  86. package/lib/module/shared/utils/gesture/velocity.js +11 -0
  87. package/lib/module/shared/utils/gesture/velocity.js.map +1 -1
  88. package/lib/module/shared/utils/logger.js +17 -0
  89. package/lib/module/shared/utils/logger.js.map +1 -0
  90. package/lib/typescript/blank-stack/components/adjusted-screen.d.ts.map +1 -1
  91. package/lib/typescript/shared/components/create-transition-aware-component.d.ts.map +1 -1
  92. package/lib/typescript/shared/components/screen-container.d.ts +6 -0
  93. package/lib/typescript/shared/components/screen-container.d.ts.map +1 -0
  94. package/lib/typescript/shared/configs/specs.d.ts +1 -0
  95. package/lib/typescript/shared/configs/specs.d.ts.map +1 -1
  96. package/lib/typescript/shared/constants.d.ts +9 -0
  97. package/lib/typescript/shared/constants.d.ts.map +1 -1
  98. package/lib/typescript/shared/hooks/animation/use-screen-animation.d.ts.map +1 -1
  99. package/lib/typescript/shared/hooks/gestures/use-build-gestures.d.ts +1 -1
  100. package/lib/typescript/shared/hooks/gestures/use-build-gestures.d.ts.map +1 -1
  101. package/lib/typescript/shared/hooks/gestures/use-screen-gesture-handlers.d.ts +19 -0
  102. package/lib/typescript/shared/hooks/gestures/use-screen-gesture-handlers.d.ts.map +1 -0
  103. package/lib/typescript/shared/hooks/gestures/use-scroll-registry.d.ts +5 -1
  104. package/lib/typescript/shared/hooks/gestures/use-scroll-registry.d.ts.map +1 -1
  105. package/lib/typescript/shared/hooks/lifecycle/use-open-transition.d.ts.map +1 -1
  106. package/lib/typescript/shared/hooks/navigation/use-screen-state.d.ts +7 -0
  107. package/lib/typescript/shared/hooks/navigation/use-screen-state.d.ts.map +1 -1
  108. package/lib/typescript/shared/hooks/use-backdrop-pointer-events.d.ts +15 -0
  109. package/lib/typescript/shared/hooks/use-backdrop-pointer-events.d.ts.map +1 -0
  110. package/lib/typescript/shared/providers/gestures.provider.d.ts +1 -0
  111. package/lib/typescript/shared/providers/gestures.provider.d.ts.map +1 -1
  112. package/lib/typescript/shared/types/animation.types.d.ts +37 -2
  113. package/lib/typescript/shared/types/animation.types.d.ts.map +1 -1
  114. package/lib/typescript/shared/types/screen.types.d.ts +26 -0
  115. package/lib/typescript/shared/types/screen.types.d.ts.map +1 -1
  116. package/lib/typescript/shared/utils/animation/animate-to-progress.d.ts +19 -0
  117. package/lib/typescript/shared/utils/animation/animate-to-progress.d.ts.map +1 -0
  118. package/lib/typescript/shared/utils/gesture/check-gesture-activation.d.ts +23 -0
  119. package/lib/typescript/shared/utils/gesture/check-gesture-activation.d.ts.map +1 -1
  120. package/lib/typescript/shared/utils/gesture/determine-snap-target.d.ts +26 -0
  121. package/lib/typescript/shared/utils/gesture/determine-snap-target.d.ts.map +1 -0
  122. package/lib/typescript/shared/utils/gesture/validate-snap-points.d.ts +13 -0
  123. package/lib/typescript/shared/utils/gesture/validate-snap-points.d.ts.map +1 -0
  124. package/lib/typescript/shared/utils/gesture/velocity.d.ts +1 -0
  125. package/lib/typescript/shared/utils/gesture/velocity.d.ts.map +1 -1
  126. package/lib/typescript/shared/utils/logger.d.ts +6 -0
  127. package/lib/typescript/shared/utils/logger.d.ts.map +1 -0
  128. package/package.json +3 -2
  129. package/src/blank-stack/components/adjusted-screen.tsx +1 -1
  130. package/src/shared/__tests__/derivations.test.ts +1 -0
  131. package/src/shared/__tests__/determine-snap-target.test.ts +268 -0
  132. package/src/shared/__tests__/gesture-activation.test.ts +220 -0
  133. package/src/shared/__tests__/validate-snap-points.test.ts +125 -0
  134. package/src/shared/components/create-transition-aware-component.tsx +11 -1
  135. package/src/shared/components/screen-container.tsx +65 -0
  136. package/src/shared/configs/presets.ts +3 -3
  137. package/src/shared/configs/specs.ts +6 -0
  138. package/src/shared/constants.ts +36 -9
  139. package/src/shared/hooks/animation/use-screen-animation.tsx +32 -21
  140. package/src/shared/hooks/gestures/use-build-gestures.tsx +23 -275
  141. package/src/shared/hooks/gestures/use-screen-gesture-handlers.ts +434 -0
  142. package/src/shared/hooks/gestures/use-scroll-registry.tsx +52 -1
  143. package/src/shared/hooks/lifecycle/use-close-transition.ts +3 -3
  144. package/src/shared/hooks/lifecycle/use-open-transition.ts +27 -3
  145. package/src/shared/hooks/navigation/use-screen-state.tsx +59 -2
  146. package/src/shared/hooks/use-backdrop-pointer-events.ts +32 -0
  147. package/src/shared/providers/gestures.provider.tsx +3 -2
  148. package/src/shared/providers/screen/screen-composer.tsx +2 -2
  149. package/src/shared/types/animation.types.ts +39 -2
  150. package/src/shared/types/screen.types.ts +29 -0
  151. package/src/shared/utils/animation/{start-screen-transition.ts → animate-to-progress.ts} +23 -8
  152. package/src/shared/utils/gesture/check-gesture-activation.ts +129 -0
  153. package/src/shared/utils/gesture/determine-snap-target.ts +75 -0
  154. package/src/shared/utils/gesture/validate-snap-points.ts +37 -0
  155. package/src/shared/utils/gesture/velocity.ts +10 -0
  156. package/src/shared/utils/logger.ts +15 -0
  157. package/lib/commonjs/shared/components/root-transition-aware.js.map +0 -1
  158. package/lib/commonjs/shared/hooks/use-stack-pointer-events.js +0 -23
  159. package/lib/commonjs/shared/hooks/use-stack-pointer-events.js.map +0 -1
  160. package/lib/commonjs/shared/utils/animation/start-screen-transition.js.map +0 -1
  161. package/lib/module/shared/components/root-transition-aware.js +0 -48
  162. package/lib/module/shared/components/root-transition-aware.js.map +0 -1
  163. package/lib/module/shared/hooks/use-stack-pointer-events.js +0 -20
  164. package/lib/module/shared/hooks/use-stack-pointer-events.js.map +0 -1
  165. package/lib/module/shared/utils/animation/start-screen-transition.js.map +0 -1
  166. package/lib/typescript/shared/components/root-transition-aware.d.ts +0 -6
  167. package/lib/typescript/shared/components/root-transition-aware.d.ts.map +0 -1
  168. package/lib/typescript/shared/hooks/use-stack-pointer-events.d.ts +0 -10
  169. package/lib/typescript/shared/hooks/use-stack-pointer-events.d.ts.map +0 -1
  170. package/lib/typescript/shared/utils/animation/start-screen-transition.d.ts +0 -13
  171. package/lib/typescript/shared/utils/animation/start-screen-transition.d.ts.map +0 -1
  172. package/src/shared/components/root-transition-aware.tsx +0 -49
  173. package/src/shared/hooks/use-stack-pointer-events.ts +0 -15
@@ -1,40 +1,14 @@
1
1
  import { StackActions } from "@react-navigation/native";
2
2
  import { useCallback, useMemo, useRef } from "react";
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";
14
- import {
15
- DEFAULT_GESTURE_ACTIVATION_AREA,
16
- DEFAULT_GESTURE_DIRECTION,
17
- DEFAULT_GESTURE_DRIVES_PROGRESS,
18
- GESTURE_VELOCITY_IMPACT,
19
- } from "../../constants";
3
+ import { Gesture, type GestureType } from "react-native-gesture-handler";
4
+ import type { SharedValue } from "react-native-reanimated";
20
5
  import type {
21
6
  GestureContextType,
22
7
  ScrollConfig,
23
8
  } from "../../providers/gestures.provider";
24
9
  import { useKeys } from "../../providers/screen/keys.provider";
25
- import { AnimationStore } from "../../stores/animation.store";
26
10
  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";
11
+ import { useScreenGestureHandlers } from "./use-screen-gesture-handlers";
38
12
 
39
13
  interface BuildGesturesHookProps {
40
14
  scrollConfig: SharedValue<ScrollConfig | null>;
@@ -50,21 +24,13 @@ export const useBuildGestures = ({
50
24
  nativeGesture: GestureType;
51
25
  gestureAnimationValues: GestureStoreMap;
52
26
  } => {
53
- const dimensions = useWindowDimensions();
54
-
55
27
  const { current } = useKeys();
56
- const navState = current.navigation.getState();
57
- const isFirstScreen =
58
- navState.routes.findIndex((r) => r.key === current.route.key) === 0;
59
28
 
60
- const initialTouch = useSharedValue({
61
- x: 0,
62
- y: 0,
63
- });
29
+ const navState = current.navigation.getState();
64
30
 
65
- const gestureOffsetState = useSharedValue<GestureOffsetState>(
66
- GestureOffsetState.PENDING,
67
- );
31
+ const isFirstScreen = useMemo(() => {
32
+ return navState.routes.findIndex((r) => r.key === current.route.key) === 0;
33
+ }, [navState.routes, current.route.key]);
68
34
 
69
35
  // Ref for external gesture coordination (e.g., swipeable lists)
70
36
  const panGestureRef = useRef<GestureType | undefined>(undefined);
@@ -72,36 +38,19 @@ export const useBuildGestures = ({
72
38
  const gestureAnimationValues = GestureStore.getRouteGestures(
73
39
  current.route.key,
74
40
  );
75
- const animations = AnimationStore.getAll(current.route.key);
76
41
 
77
- const {
78
- gestureDirection = DEFAULT_GESTURE_DIRECTION,
79
- gestureVelocityImpact = GESTURE_VELOCITY_IMPACT,
80
- gestureDrivesProgress = DEFAULT_GESTURE_DRIVES_PROGRESS,
81
- gestureActivationArea = DEFAULT_GESTURE_ACTIVATION_AREA,
82
- gestureResponseDistance,
83
- transitionSpec,
84
- } = current.options;
42
+ const { snapPoints } = current.options;
85
43
 
86
- const gestureEnabled = Boolean(
44
+ // Dismiss gesture is controlled by gestureEnabled (disabled for first screen)
45
+ const canDismiss = Boolean(
87
46
  isFirstScreen ? false : current.options.gestureEnabled,
88
47
  );
89
48
 
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]);
49
+ // Snap navigation works independently - enabled when snap points exist
50
+ // This matches iOS native sheet behavior where gestureEnabled: false
51
+ // disables dismiss but you can still drag between detents
52
+ const hasSnapPoints = Array.isArray(snapPoints) && snapPoints.length > 0;
53
+ const gestureEnabled = canDismiss || hasSnapPoints;
105
54
 
106
55
  const handleDismiss = useCallback(() => {
107
56
  // If an ancestor navigator is already dismissing, skip this dismiss to
@@ -127,216 +76,15 @@ export const useBuildGestures = ({
127
76
  });
128
77
  }, [current, ancestorContext]);
129
78
 
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
- );
79
+ const { onTouchesDown, onTouchesMove, onStart, onUpdate, onEnd } =
80
+ useScreenGestureHandlers({
81
+ scrollConfig,
82
+ canDismiss,
83
+ handleDismiss,
84
+ ancestorIsDismissing:
85
+ ancestorContext?.gestureAnimationValues.isDismissing,
86
+ });
336
87
 
337
- // Memoize gestures to keep stable references - critical for RNGH
338
- // Child gestures reference ancestor's pan via requireExternalGestureToFail,
339
- // so the pan gesture MUST be stable or children will reference stale objects
340
88
  return useMemo(() => {
341
89
  const panGesture = Gesture.Pan()
342
90
  .withRef(panGestureRef)