From 03b343ff0a17a4721518eecc4ba5885b6d540bf0 Mon Sep 17 00:00:00 2001 From: Roman Cornelius Date: Thu, 18 Apr 2024 18:00:35 +0500 Subject: [PATCH] Change haptic feedback to one-shot --- .../kotlin/me/saket/swipe/SwipeableActionsBox.kt | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/library/src/commonMain/kotlin/me/saket/swipe/SwipeableActionsBox.kt b/library/src/commonMain/kotlin/me/saket/swipe/SwipeableActionsBox.kt index 9b2c837..5b2239c 100644 --- a/library/src/commonMain/kotlin/me/saket/swipe/SwipeableActionsBox.kt +++ b/library/src/commonMain/kotlin/me/saket/swipe/SwipeableActionsBox.kt @@ -103,10 +103,16 @@ fun SwipeableActionsBox( } val hapticFeedback = LocalHapticFeedback.current - if (state.hasCrossedSwipeThreshold() && state.swipedAction == null) { - LaunchedEffect(state.visibleAction) { - hapticFeedback.performHapticFeedback(HapticFeedbackType.LongPress) + var offsetCrossed by remember { mutableStateOf(false) } + if (state.hasCrossedSwipeThreshold()) { + if (!offsetCrossed) { + offsetCrossed = true + LaunchedEffect(state.visibleAction) { + hapticFeedback.performHapticFeedback(HapticFeedbackType.LongPress) + } } + } else { + offsetCrossed = false } }