diff --git a/apple/Handlers/RNPanHandler.m b/apple/Handlers/RNPanHandler.m
index e67d02c..4708f0f 100644
--- a/apple/Handlers/RNPanHandler.m
+++ b/apple/Handlers/RNPanHandler.m
@@ -31,6 +31,7 @@ @interface RNBetterPanGestureRecognizer : UIPanGestureRecognizer
@property (nonatomic) CGFloat failOffsetYStart;
@property (nonatomic) CGFloat failOffsetYEnd;
@property (nonatomic) CGFloat activateAfterLongPress;
+@property (nonatomic) BOOL handlingTouchStart;
#if !TARGET_OS_OSX && !TARGET_OS_TV
@property (atomic, readonly, strong) RNGHStylusData *stylusData;
@@ -126,9 +127,14 @@ - (void)activateAfterLongPress
- (void)interactionsBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
- if (self.state == UIGestureRecognizerStatePossible && ![self.delegate gestureRecognizerShouldBegin:self]) {
- self.state = UIGestureRecognizerStateFailed;
- return;
+ if (self.state == UIGestureRecognizerStatePossible) {
+ self.handlingTouchStart = touches.count > 0;
+ BOOL shouldBegin = [self.delegate gestureRecognizerShouldBegin:self];
+ self.handlingTouchStart = NO;
+ if (!shouldBegin) {
+ self.state = UIGestureRecognizerStateFailed;
+ return;
+ }
}
if (touches.count == 0) {
@@ -476,6 +482,23 @@ - (void)updateConfig:(NSDictionary *)config
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
+#if !TARGET_OS_OSX && !TARGET_OS_TV
+ RNBetterPanGestureRecognizer *recognizer = (RNBetterPanGestureRecognizer *)gestureRecognizer;
+ if (!recognizer.handlingTouchStart && recognizer.allowedScrollTypesMask != 0 && recognizer.numberOfTouches == 0) {
+ // Trackpad scroll events can begin without touchesMoved enforcing failure
+ // offsets. Reject vertical scrolling before a horizontal row pan cancels
+ // the enclosing UIScrollView. The manual touch-start preflight above has
+ // no current translation yet, so leave that path to the touch callbacks.
+ CGPoint translation = [recognizer translationInView:recognizer.view.window];
+ BOOL horizontalOnly = (!isnan(recognizer.activeOffsetXStart) || !isnan(recognizer.activeOffsetXEnd)) &&
+ isnan(recognizer.activeOffsetYStart) && isnan(recognizer.activeOffsetYEnd);
+ if ([recognizer shouldFailUnderCustomCriteria] ||
+ (horizontalOnly && fabs(translation.y) > fabs(translation.x))) {
+ return NO;
+ }
+ }
+#endif
+
RNGestureHandlerState savedState = _lastState;
BOOL shouldBegin = [super gestureRecognizerShouldBegin:gestureRecognizer];
_lastState = savedState;
diff --git a/lib/module/components/ReanimatedSwipeable/ReanimatedSwipeable.js b/lib/module/components/ReanimatedSwipeable/ReanimatedSwipeable.js
index 5f2f759..c0b8237 100644
--- a/lib/module/components/ReanimatedSwipeable/ReanimatedSwipeable.js
+++ b/lib/module/components/ReanimatedSwipeable/ReanimatedSwipeable.js
@@ -42,6 +42,8 @@ const Swipeable = props => {
enableTrackpadTwoFingerGesture = DEFAULT_ENABLE_TRACKING_TWO_FINGER_GESTURE,
dragOffsetFromLeft = DEFAULT_DRAG_OFFSET,
dragOffsetFromRight = -DEFAULT_DRAG_OFFSET,
+ failOffsetY,
+ onSwipeableRelease,
friction = DEFAULT_FRICTION,
overshootFriction = DEFAULT_OVERSHOOT_FRICTION,
onSwipeableOpenStartDrag: onSwipeableOpenStartDragProp,
@@ -293,8 +295,12 @@ const Swipeable = props => {
toValue = -rightWidth.value;
}
}
+ // Let a UI-thread full-swipe commit take over before the return spring.
+ if (onSwipeableRelease?.(appliedTranslation)) {
+ return;
+ }
animateRow(toValue, velocityX / friction);
- }, [animateRow, friction, leftThreshold, leftWidth, rightThreshold, rightWidth, rowState, userDrag]);
+ }, [animateRow, friction, leftThreshold, leftWidth, rightThreshold, rightWidth, rowState, userDrag, onSwipeableRelease, appliedTranslation]);
const close = useCallback(() => {
'worklet';
@@ -340,6 +346,8 @@ const Swipeable = props => {
enabled: enabled ?? true,
enableTrackpadTwoFingerGesture: enableTrackpadTwoFingerGesture,
activeOffsetX: [dragOffsetFromRight, dragOffsetFromLeft],
+ failOffsetY,
+ failOffsetY,
simultaneousWith,
requireToFail,
block,
diff --git a/lib/typescript/components/ReanimatedSwipeable/ReanimatedSwipeableProps.d.ts b/lib/typescript/components/ReanimatedSwipeable/ReanimatedSwipeableProps.d.ts
index e97b6db..de07f26 100644
--- a/lib/typescript/components/ReanimatedSwipeable/ReanimatedSwipeableProps.d.ts
+++ b/lib/typescript/components/ReanimatedSwipeable/ReanimatedSwipeableProps.d.ts
@@ -59,6 +59,12 @@ export type SwipeableProps = {
* Called when action panel is closed.
*/
onSwipeableClose?: (direction: SwipeDirection.LEFT | SwipeDirection.RIGHT) => void;
+ /**
+ * UI-thread worklet called on release before the built-in spring starts.
+ * Return true to consume the release and take ownership of translation.
+ * The caller must reset or remove the row after its custom animation.
+ */
+ onSwipeableRelease?: (translation: SharedValue<number>) => boolean;
/**
* Called when action panel starts animating on open (either right or left).
*/
@@ -150,6 +156,13 @@ export type SwipeableProps = {
* The horizontal offset from the starting point required to trigger a left-swipe gesture. Defaults to -10.
*/
dragOffsetFromRight?: number;
+ /**
+ * Range along the Y axis (in points) that, once exceeded before the swipe
+ * activates, makes the pan fail. Lets vertically-dominant pans (list
+ * scrolling, especially trackpad two-finger pans) skip the swipe entirely.
+ * Passed straight to the underlying Pan gesture's `failOffsetY`.
+ */
+ failOffsetY?: number | [start: number, end: number];
}>;
export interface SwipeableMethods {
close: () => void;
diff --git a/src/components/ReanimatedSwipeable/ReanimatedSwipeable.tsx b/src/components/ReanimatedSwipeable/ReanimatedSwipeable.tsx
index b62da83..7d88839 100644
--- a/src/components/ReanimatedSwipeable/ReanimatedSwipeable.tsx
+++ b/src/components/ReanimatedSwipeable/ReanimatedSwipeable.tsx
@@ -77,6 +77,8 @@ const Swipeable = (props: SwipeableProps) => {
enableTrackpadTwoFingerGesture = DEFAULT_ENABLE_TRACKING_TWO_FINGER_GESTURE,
dragOffsetFromLeft = DEFAULT_DRAG_OFFSET,
dragOffsetFromRight = -DEFAULT_DRAG_OFFSET,
+ failOffsetY,
+ onSwipeableRelease,
friction = DEFAULT_FRICTION,
overshootFriction = DEFAULT_OVERSHOOT_FRICTION,
onSwipeableOpenStartDrag: onSwipeableOpenStartDragProp,
@@ -518,6 +520,11 @@ const Swipeable = (props: SwipeableProps) => {
}
}
+ // Let a UI-thread full-swipe commit take over before the return spring.
+ if (onSwipeableRelease?.(appliedTranslation)) {
+ return;
+ }
+
animateRow(toValue, velocityX / friction);
},
[
@@ -529,6 +536,8 @@ const Swipeable = (props: SwipeableProps) => {
rightWidth,
rowState,
userDrag,
+ onSwipeableRelease,
+ appliedTranslation,
]
);
@@ -606,6 +615,7 @@ const Swipeable = (props: SwipeableProps) => {
typeof dragOffsetFromRight,
typeof dragOffsetFromLeft,
],
+ failOffsetY,
simultaneousWith,
requireToFail,
block,
@@ -619,6 +629,7 @@ const Swipeable = (props: SwipeableProps) => {
block,
dragOffsetFromLeft,
dragOffsetFromRight,
+ failOffsetY,
enableTrackpadTwoFingerGesture,
enabled,
handleFinalize,
diff --git a/src/components/ReanimatedSwipeable/ReanimatedSwipeableProps.ts b/src/components/ReanimatedSwipeable/ReanimatedSwipeableProps.ts
index 1e1246f..f526d4f 100644
--- a/src/components/ReanimatedSwipeable/ReanimatedSwipeableProps.ts
+++ b/src/components/ReanimatedSwipeable/ReanimatedSwipeableProps.ts
@@ -77,6 +77,13 @@ export type SwipeableProps = {
direction: SwipeDirection.LEFT | SwipeDirection.RIGHT
) => void;
+ /**
+ * UI-thread worklet called on release before the built-in spring starts.
+ * Return true to consume the release and take ownership of translation.
+ * The caller must reset or remove the row after its custom animation.
+ */
+ onSwipeableRelease?: (translation: SharedValue<number>) => boolean;
+
/**
* Called when action panel starts animating on open (either right or left).
*/
@@ -196,6 +203,14 @@ export type SwipeableProps = {
* The horizontal offset from the starting point required to trigger a left-swipe gesture. Defaults to -10.
*/
dragOffsetFromRight?: number;
+
+ /**
+ * Range along the Y axis (in points) that, once exceeded before the swipe
+ * activates, makes the pan fail. Lets vertically-dominant pans (list
+ * scrolling, especially trackpad two-finger pans) skip the swipe entirely.
+ * Passed straight to the underlying Pan gesture's `failOffsetY`.
+ */
+ failOffsetY?: number | [start: number, end: number];
}>;
export interface SwipeableMethods {