From fc0446291af400b2757c04d85caf4bf703484811 Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Tue, 14 Oct 2025 15:49:06 +0300 Subject: [PATCH] Handle the long press gesture states better and avoid multiple action invocations --- .../Timeline/View/Style/LongPressWithFeedback.swift | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/ElementX/Sources/Screens/Timeline/View/Style/LongPressWithFeedback.swift b/ElementX/Sources/Screens/Timeline/View/Style/LongPressWithFeedback.swift index 9ad30877c..e934ea43c 100644 --- a/ElementX/Sources/Screens/Timeline/View/Style/LongPressWithFeedback.swift +++ b/ElementX/Sources/Screens/Timeline/View/Style/LongPressWithFeedback.swift @@ -19,10 +19,14 @@ struct LongPressWithFeedback: ViewModifier { mainContent(content: content) .gesture(LongPressGestureRepresentable { gesture in switch gesture.state { + case .began: + handleLongPress(isPressing: true) case .ended, .cancelled, .failed: handleLongPress(isPressing: false) - default: - handleLongPress(isPressing: true) + case .possible, .changed: + break + @unknown default: + break } }) } else { @@ -49,7 +53,9 @@ struct LongPressWithFeedback: ViewModifier { // The wait time needs to be at least 0.5 seconds or the long press gesture will take precedence over long pressing links. try? await Task.sleep(for: .seconds(0.5)) - if Task.isCancelled { return } + if Task.isCancelled { + return + } action() feedbackGenerator.impactOccurred()