From 1b7ccd3345a120f7d9d95243ddb66db80c6f0d50 Mon Sep 17 00:00:00 2001 From: Felipe Date: Sat, 16 Sep 2023 11:34:52 -0300 Subject: [PATCH 1/3] feat: new onSwipeableOpenDragStart and onSwipeableCloseDragStart events --- src/components/Swipeable.tsx | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/components/Swipeable.tsx b/src/components/Swipeable.tsx index 0b801daa74..d5fb06d248 100644 --- a/src/components/Swipeable.tsx +++ b/src/components/Swipeable.tsx @@ -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: @@ -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) { + const { velocityX, translationX: dragX } = ev.nativeEvent; + + const { rowState } = this.state; + + const { friction } = this.props; + const translationX = (dragX + DRAG_TOSS * velocityX) / friction!; + + 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'; + } + + if (direction) { + if (rowState === 0) { + this.props.onSwipeableOpenStartDrag?.(direction); + } else { + this.props.onSwipeableCloseStartDrag?.(direction); + } + } + } }; private handleRelease = ( From ba3434196bb1c73b262031afb8e6c3de13d3358e Mon Sep 17 00:00:00 2001 From: Felipe Date: Wed, 20 Sep 2023 10:13:37 -0300 Subject: [PATCH 2/3] refactor: cosmetic changes after PR review --- src/components/Swipeable.tsx | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/src/components/Swipeable.tsx b/src/components/Swipeable.tsx index d5fb06d248..b7beb82113 100644 --- a/src/components/Swipeable.tsx +++ b/src/components/Swipeable.tsx @@ -346,28 +346,24 @@ export default class Swipeable extends Component< } if (ev.nativeEvent.state === State.ACTIVE) { const { velocityX, translationX: dragX } = ev.nativeEvent; - const { rowState } = this.state; - const { friction } = this.props; + const translationX = (dragX + DRAG_TOSS * velocityX) / friction!; - let direction: 'left' | 'right' | undefined = undefined; + const direction = + rowState === -1 + ? 'right' + : rowState === 1 + ? 'left' + : translationX > 0 + ? 'left' + : 'right'; if (rowState === 0) { - direction = translationX > 0 ? 'left' : 'right'; - } else if (rowState === 1) { - direction = 'left'; - } else if (rowState === -1) { - direction = 'right'; - } - - if (direction) { - if (rowState === 0) { - this.props.onSwipeableOpenStartDrag?.(direction); - } else { - this.props.onSwipeableCloseStartDrag?.(direction); - } + this.props.onSwipeableOpenStartDrag?.(direction); + } else { + this.props.onSwipeableCloseStartDrag?.(direction); } } }; From 24ee30ccbc79f52ae5e85e529c9419d63ee4b1bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Bert?= <63123542+m-bert@users.noreply.github.com> Date: Wed, 20 Sep 2023 15:30:06 +0200 Subject: [PATCH 3/3] Add new line --- src/components/Swipeable.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/Swipeable.tsx b/src/components/Swipeable.tsx index b7beb82113..b3ae488ab2 100644 --- a/src/components/Swipeable.tsx +++ b/src/components/Swipeable.tsx @@ -344,6 +344,7 @@ export default class Swipeable extends Component< if (ev.nativeEvent.oldState === State.ACTIVE) { this.handleRelease(ev); } + if (ev.nativeEvent.state === State.ACTIVE) { const { velocityX, translationX: dragX } = ev.nativeEvent; const { rowState } = this.state;