From b3c423e253b606e020a8ef7d7e243a44d38ac54b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ignacy=20=C5=81=C4=85tka?= Date: Fri, 11 Oct 2024 16:45:39 +0200 Subject: [PATCH 1/2] fix callbacks being called every update --- src/components/ReanimatedSwipeable.tsx | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/components/ReanimatedSwipeable.tsx b/src/components/ReanimatedSwipeable.tsx index cf71f50bd4..edae3402fd 100644 --- a/src/components/ReanimatedSwipeable.tsx +++ b/src/components/ReanimatedSwipeable.tsx @@ -562,6 +562,8 @@ const Swipeable = forwardRef( } }); + const dragStarted = useSharedValue(false); + const panGesture = Gesture.Pan() .onUpdate((event: GestureUpdateEvent) => { userDrag.value = event.translationX; @@ -575,18 +577,23 @@ const Swipeable = forwardRef( ? 'left' : 'right'; - if (rowState.value === 0 && onSwipeableOpenStartDrag) { - runOnJS(onSwipeableOpenStartDrag)(direction); - } else if (rowState.value !== 0 && onSwipeableCloseStartDrag) { - runOnJS(onSwipeableCloseStartDrag)(direction); + if (dragStarted.value === false) { + dragStarted.value = true; + if (rowState.value === 0 && onSwipeableOpenStartDrag) { + runOnJS(onSwipeableOpenStartDrag)(direction); + } else if (rowState.value !== 0 && onSwipeableCloseStartDrag) { + runOnJS(onSwipeableCloseStartDrag)(direction); + } } + updateAnimatedEvent(); }) .onEnd( (event: GestureStateChangeEvent) => { handleRelease(event); } - ); + ) + .onFinalize(() => (dragStarted.value = false)); if (enableTrackpadTwoFingerGesture) { panGesture.enableTrackpadTwoFingerGesture(enableTrackpadTwoFingerGesture); From d0bda4353678ecdfd40a0f022b7ed742b76bbe59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ignacy=20=C5=81=C4=85tka?= Date: Mon, 14 Oct 2024 11:57:33 +0200 Subject: [PATCH 2/2] apply stylistic suggestions --- src/components/ReanimatedSwipeable.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/components/ReanimatedSwipeable.tsx b/src/components/ReanimatedSwipeable.tsx index edae3402fd..5f55a4586c 100644 --- a/src/components/ReanimatedSwipeable.tsx +++ b/src/components/ReanimatedSwipeable.tsx @@ -577,7 +577,7 @@ const Swipeable = forwardRef( ? 'left' : 'right'; - if (dragStarted.value === false) { + if (!dragStarted.value) { dragStarted.value = true; if (rowState.value === 0 && onSwipeableOpenStartDrag) { runOnJS(onSwipeableOpenStartDrag)(direction); @@ -593,7 +593,9 @@ const Swipeable = forwardRef( handleRelease(event); } ) - .onFinalize(() => (dragStarted.value = false)); + .onFinalize(() => { + dragStarted.value = false; + }); if (enableTrackpadTwoFingerGesture) { panGesture.enableTrackpadTwoFingerGesture(enableTrackpadTwoFingerGesture);