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 2 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
36 changes: 36 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,32 @@ 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!;
rampazzo1989 marked this conversation as resolved.
Show resolved Hide resolved

let direction: 'left' | 'right' | undefined = undefined;

if (rowState === 0) {
direction = translationX > 0 ? 'left' : 'right';
} else if (rowState === 1) {
direction = 'left';
} else if (rowState === -1) {
direction = 'right';
}
rampazzo1989 marked this conversation as resolved.
Show resolved Hide resolved

if (direction) {
if (rowState === 0) {
this.props.onSwipeableOpenStartDrag?.(direction);
} else {
this.props.onSwipeableCloseStartDrag?.(direction);
}
}
}
rampazzo1989 marked this conversation as resolved.
Show resolved Hide resolved
};

private handleRelease = (
Expand Down
Loading