mirror of
https://github.com/hanzoai/dev-desktop.git
synced 2026-11-20 01:07:23 +00:00
229 lines
10 KiB
Diff
229 lines
10 KiB
Diff
diff --git a/apple/Handlers/RNPanHandler.m b/apple/Handlers/RNPanHandler.m
|
|
index cb0666b9e35dc2b76ff0cb592e0a867e1a28b3dd..7f481d90f9993dbe874676c7393f90e266bffcbf 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;
|
|
@@ -133,9 +134,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) {
|
|
@@ -501,6 +507,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 30e6601d1dd2dbb8fa43b077feee374e0af4e509..5e6e99cee482c78aac71fe5ed1dc19e4ccf05ae4 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,
|
|
@@ -284,6 +286,10 @@ const Swipeable = props => {
|
|
if (event.canceled) {
|
|
// Restore the row to where it rested before the gesture.
|
|
const restingValue = rowState.value === 1 ? leftWidth.value : rowState.value === -1 ? -rightWidth.value : 0;
|
|
+ // A caller animating translation (e.g. a dismissal) keeps it.
|
|
+ if (onSwipeableRelease?.(appliedTranslation, true)) {
|
|
+ return;
|
|
+ }
|
|
animateRow(restingValue, 0, true);
|
|
return;
|
|
}
|
|
@@ -312,8 +318,12 @@ const Swipeable = props => {
|
|
toValue = -rightWidth.value;
|
|
}
|
|
}
|
|
+ // Let a UI-thread full-swipe commit take over before the return spring.
|
|
+ if (onSwipeableRelease?.(appliedTranslation, false)) {
|
|
+ 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';
|
|
|
|
@@ -359,6 +369,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 e97b6dbbced1bcbd359cf35293b7f10cbf13b0e7..b7d03718c4ce50a0a69f0f478ae5114d9310d9f3 100644
|
|
--- a/lib/typescript/components/ReanimatedSwipeable/ReanimatedSwipeableProps.d.ts
|
|
+++ b/lib/typescript/components/ReanimatedSwipeable/ReanimatedSwipeableProps.d.ts
|
|
@@ -59,6 +59,13 @@ 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,
|
|
+ * including a canceled pan (`canceled`), which must not commit an action.
|
|
+ * 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>, canceled: boolean) => boolean;
|
|
/**
|
|
* Called when action panel starts animating on open (either right or left).
|
|
*/
|
|
@@ -150,6 +157,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 2b3789a5277404e57607c05db96dc062d6db1b10..0c23c2ce6b0a07540c68204a8528b655b5624f84 100644
|
|
--- a/src/components/ReanimatedSwipeable/ReanimatedSwipeable.tsx
|
|
+++ b/src/components/ReanimatedSwipeable/ReanimatedSwipeable.tsx
|
|
@@ -80,6 +80,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,
|
|
@@ -520,6 +522,10 @@ const Swipeable = (props: SwipeableProps) => {
|
|
: rowState.value === -1
|
|
? -rightWidth.value
|
|
: 0;
|
|
+ // A caller animating translation (e.g. a dismissal) keeps it.
|
|
+ if (onSwipeableRelease?.(appliedTranslation, true)) {
|
|
+ return;
|
|
+ }
|
|
animateRow(restingValue, 0, true);
|
|
return;
|
|
}
|
|
@@ -552,6 +558,11 @@ const Swipeable = (props: SwipeableProps) => {
|
|
}
|
|
}
|
|
|
|
+ // Let a UI-thread full-swipe commit take over before the return spring.
|
|
+ if (onSwipeableRelease?.(appliedTranslation, false)) {
|
|
+ return;
|
|
+ }
|
|
+
|
|
animateRow(toValue, velocityX / friction);
|
|
},
|
|
[
|
|
@@ -563,6 +574,8 @@ const Swipeable = (props: SwipeableProps) => {
|
|
rightWidth,
|
|
rowState,
|
|
userDrag,
|
|
+ onSwipeableRelease,
|
|
+ appliedTranslation,
|
|
]
|
|
);
|
|
|
|
@@ -640,6 +653,7 @@ const Swipeable = (props: SwipeableProps) => {
|
|
typeof dragOffsetFromRight,
|
|
typeof dragOffsetFromLeft,
|
|
],
|
|
+ failOffsetY,
|
|
simultaneousWith,
|
|
requireToFail,
|
|
block,
|
|
@@ -653,6 +667,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 1e1246f709feb04c01cf3221472cc1219a8fffac..9099c53aa5e2ff164beeb0f43897fd56eef663fa 100644
|
|
--- a/src/components/ReanimatedSwipeable/ReanimatedSwipeableProps.ts
|
|
+++ b/src/components/ReanimatedSwipeable/ReanimatedSwipeableProps.ts
|
|
@@ -77,6 +77,14 @@ export type SwipeableProps = {
|
|
direction: SwipeDirection.LEFT | SwipeDirection.RIGHT
|
|
) => void;
|
|
|
|
+ /**
|
|
+ * UI-thread worklet called on release before the built-in spring starts,
|
|
+ * including a canceled pan (`canceled`), which must not commit an action.
|
|
+ * 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>, canceled: boolean) => boolean;
|
|
+
|
|
/**
|
|
* Called when action panel starts animating on open (either right or left).
|
|
*/
|
|
@@ -196,6 +204,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 {
|