Open History to see the last commit
1diff --git a/apple/Handlers/RNPanHandler.m b/apple/Handlers/RNPanHandler.m
2index e67d02c..4708f0f 100644
3--- a/apple/Handlers/RNPanHandler.m
4+++ b/apple/Handlers/RNPanHandler.m
5@@ -31,6 +31,7 @@ @interface RNBetterPanGestureRecognizer : UIPanGestureRecognizer
6 @property (nonatomic) CGFloat failOffsetYStart;
7 @property (nonatomic) CGFloat failOffsetYEnd;
8 @property (nonatomic) CGFloat activateAfterLongPress;
9+@property (nonatomic) BOOL handlingTouchStart;
11 #if !TARGET_OS_OSX && !TARGET_OS_TV
12 @property (atomic, readonly, strong) RNGHStylusData *stylusData;
13@@ -126,9 +127,14 @@ - (void)activateAfterLongPress
15 - (void)interactionsBegan:(NSSet *)touches withEvent:(UIEvent *)event
16 {
17- if (self.state == UIGestureRecognizerStatePossible && ![self.delegate gestureRecognizerShouldBegin:self]) {
18- self.state = UIGestureRecognizerStateFailed;
19- return;
20+ if (self.state == UIGestureRecognizerStatePossible) {
21+ self.handlingTouchStart = touches.count > 0;
22+ BOOL shouldBegin = [self.delegate gestureRecognizerShouldBegin:self];
23+ self.handlingTouchStart = NO;
24+ if (!shouldBegin) {
25+ self.state = UIGestureRecognizerStateFailed;
26+ return;
27+ }
28 }
30 if (touches.count == 0) {
31@@ -476,6 +482,23 @@ - (void)updateConfig:(NSDictionary *)config
33 - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
34 {
35+#if !TARGET_OS_OSX && !TARGET_OS_TV
36+ RNBetterPanGestureRecognizer *recognizer = (RNBetterPanGestureRecognizer *)gestureRecognizer;
37+ if (!recognizer.handlingTouchStart && recognizer.allowedScrollTypesMask != 0 && recognizer.numberOfTouches == 0) {
38+ // Trackpad scroll events can begin without touchesMoved enforcing failure
39+ // offsets. Reject vertical scrolling before a horizontal row pan cancels
40+ // the enclosing UIScrollView. The manual touch-start preflight above has
41+ // no current translation yet, so leave that path to the touch callbacks.
42+ CGPoint translation = [recognizer translationInView:recognizer.view.window];
43+ BOOL horizontalOnly = (!isnan(recognizer.activeOffsetXStart) || !isnan(recognizer.activeOffsetXEnd)) &&
44+ isnan(recognizer.activeOffsetYStart) && isnan(recognizer.activeOffsetYEnd);
45+ if ([recognizer shouldFailUnderCustomCriteria] ||
46+ (horizontalOnly && fabs(translation.y) > fabs(translation.x))) {
47+ return NO;
48+ }
49+ }
50+#endif
51+
52 RNGestureHandlerState savedState = _lastState;
53 BOOL shouldBegin = [super gestureRecognizerShouldBegin:gestureRecognizer];
54 _lastState = savedState;
55diff --git a/lib/module/components/ReanimatedSwipeable/ReanimatedSwipeable.js b/lib/module/components/ReanimatedSwipeable/ReanimatedSwipeable.js
56index 5f2f759..c0b8237 100644
57--- a/lib/module/components/ReanimatedSwipeable/ReanimatedSwipeable.js
58+++ b/lib/module/components/ReanimatedSwipeable/ReanimatedSwipeable.js
59@@ -42,6 +42,8 @@ const Swipeable = props => {
60 enableTrackpadTwoFingerGesture = DEFAULT_ENABLE_TRACKING_TWO_FINGER_GESTURE,
61 dragOffsetFromLeft = DEFAULT_DRAG_OFFSET,
62 dragOffsetFromRight = -DEFAULT_DRAG_OFFSET,
63+ failOffsetY,
64+ onSwipeableRelease,
65 friction = DEFAULT_FRICTION,
66 overshootFriction = DEFAULT_OVERSHOOT_FRICTION,
67 onSwipeableOpenStartDrag: onSwipeableOpenStartDragProp,
68@@ -293,8 +295,12 @@ const Swipeable = props => {
69 toValue = -rightWidth.value;
70 }
71 }
72+ // Let a UI-thread full-swipe commit take over before the return spring.
73+ if (onSwipeableRelease?.(appliedTranslation)) {
74+ return;
75+ }
76 animateRow(toValue, velocityX / friction);
77- }, [animateRow, friction, leftThreshold, leftWidth, rightThreshold, rightWidth, rowState, userDrag]);
78+ }, [animateRow, friction, leftThreshold, leftWidth, rightThreshold, rightWidth, rowState, userDrag, onSwipeableRelease, appliedTranslation]);
79 const close = useCallback(() => {
80 'worklet';
82@@ -340,6 +346,8 @@ const Swipeable = props => {
83 enabled: enabled ?? true,
84 enableTrackpadTwoFingerGesture: enableTrackpadTwoFingerGesture,
85 activeOffsetX: [dragOffsetFromRight, dragOffsetFromLeft],
86+ failOffsetY,
87+ failOffsetY,
88 simultaneousWith,
89 requireToFail,
90 block,
91diff --git a/lib/typescript/components/ReanimatedSwipeable/ReanimatedSwipeableProps.d.ts b/lib/typescript/components/ReanimatedSwipeable/ReanimatedSwipeableProps.d.ts
92index e97b6db..de07f26 100644
93--- a/lib/typescript/components/ReanimatedSwipeable/ReanimatedSwipeableProps.d.ts
94+++ b/lib/typescript/components/ReanimatedSwipeable/ReanimatedSwipeableProps.d.ts
95@@ -59,6 +59,12 @@ export type SwipeableProps = {
96 * Called when action panel is closed.
97 */
98 onSwipeableClose?: (direction: SwipeDirection.LEFT | SwipeDirection.RIGHT) => void;
99+ /**
100+ * UI-thread worklet called on release before the built-in spring starts.
101+ * Return true to consume the release and take ownership of translation.
102+ * The caller must reset or remove the row after its custom animation.
103+ */
104+ onSwipeableRelease?: (translation: SharedValue<number>) => boolean;
105 /**
106 * Called when action panel starts animating on open (either right or left).
107 */
108@@ -150,6 +156,13 @@ export type SwipeableProps = {
109 * The horizontal offset from the starting point required to trigger a left-swipe gesture. Defaults to -10.
110 */
111 dragOffsetFromRight?: number;
112+ /**
113+ * Range along the Y axis (in points) that, once exceeded before the swipe
114+ * activates, makes the pan fail. Lets vertically-dominant pans (list
115+ * scrolling, especially trackpad two-finger pans) skip the swipe entirely.
116+ * Passed straight to the underlying Pan gesture's `failOffsetY`.
117+ */
118+ failOffsetY?: number | [start: number, end: number];
119 }>;
120 export interface SwipeableMethods {
121 close: () => void;
122diff --git a/src/components/ReanimatedSwipeable/ReanimatedSwipeable.tsx b/src/components/ReanimatedSwipeable/ReanimatedSwipeable.tsx
123index b62da83..7d88839 100644
124--- a/src/components/ReanimatedSwipeable/ReanimatedSwipeable.tsx
125+++ b/src/components/ReanimatedSwipeable/ReanimatedSwipeable.tsx
126@@ -77,6 +77,8 @@ const Swipeable = (props: SwipeableProps) => {
127 enableTrackpadTwoFingerGesture = DEFAULT_ENABLE_TRACKING_TWO_FINGER_GESTURE,
128 dragOffsetFromLeft = DEFAULT_DRAG_OFFSET,
129 dragOffsetFromRight = -DEFAULT_DRAG_OFFSET,
130+ failOffsetY,
131+ onSwipeableRelease,
132 friction = DEFAULT_FRICTION,
133 overshootFriction = DEFAULT_OVERSHOOT_FRICTION,
134 onSwipeableOpenStartDrag: onSwipeableOpenStartDragProp,
135@@ -518,6 +520,11 @@ const Swipeable = (props: SwipeableProps) => {
136 }
137 }
139+ // Let a UI-thread full-swipe commit take over before the return spring.
140+ if (onSwipeableRelease?.(appliedTranslation)) {
141+ return;
142+ }
143+
144 animateRow(toValue, velocityX / friction);
145 },
146 [
147@@ -529,6 +536,8 @@ const Swipeable = (props: SwipeableProps) => {
148 rightWidth,
149 rowState,
150 userDrag,
151+ onSwipeableRelease,
152+ appliedTranslation,
153 ]
154 );
156@@ -606,6 +615,7 @@ const Swipeable = (props: SwipeableProps) => {
157 typeof dragOffsetFromRight,
158 typeof dragOffsetFromLeft,
159 ],
160+ failOffsetY,
161 simultaneousWith,
162 requireToFail,
163 block,
164@@ -619,6 +629,7 @@ const Swipeable = (props: SwipeableProps) => {
165 block,
166 dragOffsetFromLeft,
167 dragOffsetFromRight,
168+ failOffsetY,
169 enableTrackpadTwoFingerGesture,
170 enabled,
171 handleFinalize,
172diff --git a/src/components/ReanimatedSwipeable/ReanimatedSwipeableProps.ts b/src/components/ReanimatedSwipeable/ReanimatedSwipeableProps.ts
173index 1e1246f..f526d4f 100644
174--- a/src/components/ReanimatedSwipeable/ReanimatedSwipeableProps.ts
175+++ b/src/components/ReanimatedSwipeable/ReanimatedSwipeableProps.ts
176@@ -77,6 +77,13 @@ export type SwipeableProps = {
177 direction: SwipeDirection.LEFT | SwipeDirection.RIGHT
178 ) => void;
180+ /**
181+ * UI-thread worklet called on release before the built-in spring starts.
182+ * Return true to consume the release and take ownership of translation.
183+ * The caller must reset or remove the row after its custom animation.
184+ */
185+ onSwipeableRelease?: (translation: SharedValue<number>) => boolean;
186+
187 /**
188 * Called when action panel starts animating on open (either right or left).
189 */
190@@ -196,6 +203,14 @@ export type SwipeableProps = {
191 * The horizontal offset from the starting point required to trigger a left-swipe gesture. Defaults to -10.
192 */
193 dragOffsetFromRight?: number;
194+
195+ /**
196+ * Range along the Y axis (in points) that, once exceeded before the swipe
197+ * activates, makes the pan fail. Lets vertically-dominant pans (list
198+ * scrolling, especially trackpad two-finger pans) skip the swipe entirely.
199+ * Passed straight to the underlying Pan gesture's `failOffsetY`.
200+ */
201+ failOffsetY?: number | [start: number, end: number];
202 }>;
204 export interface SwipeableMethods {