Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@ dragOffsetFromRight?: number | SharedValue<number>;

The horizontal offset from the starting point required to trigger a left-swipe gesture. Defaults to `-10`.

### failOffsetY

```ts
failOffsetY?: number |
SharedValue<number> |
[number | SharedValue<number>, number | SharedValue<number>];
```

The vertical offset range after which the swipe gesture fails if it hasn't activated yet. Not set by default. Useful when `Swipeable` is placed inside a vertically scrollable container, e.g. a list with pull-to-refresh, so that a mostly vertical drag is not taken over by the swipe.

See [failOffsetY section](/docs/gestures/use-pan-gesture#failoffsety) in `Pan` gesture for more details.

### overshootLeft

```ts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,65 @@ describe('ReanimatedSwipeable callback identity', () => {
expect(scheduleOnRN).not.toHaveBeenCalled();
});
});

describe('ReanimatedSwipeable failOffsetY', () => {
let setConfigSpy: jest.SpyInstance;

beforeEach(() => {
jest.clearAllMocks();
setConfigSpy = jest.spyOn(
RNGestureHandlerModule,
'setGestureHandlerConfig'
);
});

afterEach(() => {
setConfigSpy.mockRestore();
});

function getPanConfigs() {
return setConfigSpy.mock.calls
.map(([, config]) => config as Record<string, unknown>)
.filter((config) => 'activeOffsetXStart' in config);
}

test('forwards failOffsetY to the pan gesture', async () => {
render(
<GestureHandlerRootView>
<ReanimatedSwipeable
failOffsetY={[-8, 8]}
renderRightActions={() => <Text>Delete</Text>}>
<Text>Row</Text>
</ReanimatedSwipeable>
</GestureHandlerRootView>
);
await flushNativeOps();

const panConfigs = getPanConfigs();
expect(panConfigs.length).toBeGreaterThan(0);
for (const config of panConfigs) {
expect(config).toMatchObject({
failOffsetYStart: -8,
failOffsetYEnd: 8,
});
}
});

test('does not set failOffsetY on the pan gesture when the prop is omitted', async () => {
render(
<GestureHandlerRootView>
<ReanimatedSwipeable renderRightActions={() => <Text>Delete</Text>}>
<Text>Row</Text>
</ReanimatedSwipeable>
</GestureHandlerRootView>
);
await flushNativeOps();

const panConfigs = getPanConfigs();
expect(panConfigs.length).toBeGreaterThan(0);
for (const config of panConfigs) {
expect(config).not.toHaveProperty('failOffsetYStart');
expect(config).not.toHaveProperty('failOffsetYEnd');
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ const Swipeable = (props: SwipeableProps) => {
enableTrackpadTwoFingerGesture = DEFAULT_ENABLE_TRACKING_TWO_FINGER_GESTURE,
dragOffsetFromLeft = DEFAULT_DRAG_OFFSET,
dragOffsetFromRight = -DEFAULT_DRAG_OFFSET,
failOffsetY,
friction = DEFAULT_FRICTION,
overshootFriction = DEFAULT_OVERSHOOT_FRICTION,
onSwipeableOpenStartDrag: onSwipeableOpenStartDragProp,
Expand Down Expand Up @@ -606,6 +607,7 @@ const Swipeable = (props: SwipeableProps) => {
typeof dragOffsetFromRight,
typeof dragOffsetFromLeft,
],
...(failOffsetY !== undefined && { failOffsetY }),
Comment thread
willheisenberg marked this conversation as resolved.
simultaneousWith,
requireToFail,
block,
Expand All @@ -621,6 +623,7 @@ const Swipeable = (props: SwipeableProps) => {
dragOffsetFromRight,
enableTrackpadTwoFingerGesture,
enabled,
failOffsetY,
handleFinalize,
handleRelease,
handleUpdate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,12 @@ export type SwipeableProps = {
* The horizontal offset from the starting point required to trigger a left-swipe gesture. Defaults to -10.
*/
dragOffsetFromRight?: number;

/**
* Vertical offset from the starting point after which the swipe gesture fails. Passed to the underlying pan gesture as `failOffsetY`.
* @see https://docs.swmansion.com/react-native-gesture-handler/docs/gestures/use-pan-gesture#failoffsety
*/
failOffsetY?: number | [number, number];
}>;

export interface SwipeableMethods {
Expand Down