Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New onSwipeableOpenDragStart and onSwipeableCloseDragStart events #2589

Merged
merged 5 commits into from
Sep 20, 2023
Merged
Changes from 4 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
32 changes: 32 additions & 0 deletions src/components/Swipeable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,16 @@ export interface SwipeableProps
*/
onSwipeableWillClose?: (direction: 'left' | 'right') => void;

/**
* Called when action panel starts being shown on dragging to open.
*/
onSwipeableOpenStartDrag?: (direction: 'left' | 'right') => void;

/**
* Called when action panel starts being shown on dragging to close.
*/
onSwipeableCloseStartDrag?: (direction: 'left' | 'right') => void;

/**
*
* This map describes the values to use as inputRange for extra interpolation:
Expand Down Expand Up @@ -334,6 +344,28 @@ export default class Swipeable extends Component<
if (ev.nativeEvent.oldState === State.ACTIVE) {
this.handleRelease(ev);
}
if (ev.nativeEvent.state === State.ACTIVE) {
m-bert marked this conversation as resolved.
Show resolved Hide resolved
const { velocityX, translationX: dragX } = ev.nativeEvent;
const { rowState } = this.state;
const { friction } = this.props;

const translationX = (dragX + DRAG_TOSS * velocityX) / friction!;

const direction =
rowState === -1
? 'right'
: rowState === 1
? 'left'
: translationX > 0
? 'left'
: 'right';

if (rowState === 0) {
this.props.onSwipeableOpenStartDrag?.(direction);
} else {
this.props.onSwipeableCloseStartDrag?.(direction);
}
}
};

private handleRelease = (
Expand Down
Loading