mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-04 19:44:05 +00:00
Handle the long press gesture states better and avoid multiple action invocations
This commit is contained in:
committed by
Stefan Ceriu
parent
8b45c12469
commit
fc0446291a
@@ -19,10 +19,14 @@ struct LongPressWithFeedback: ViewModifier {
|
|||||||
mainContent(content: content)
|
mainContent(content: content)
|
||||||
.gesture(LongPressGestureRepresentable { gesture in
|
.gesture(LongPressGestureRepresentable { gesture in
|
||||||
switch gesture.state {
|
switch gesture.state {
|
||||||
|
case .began:
|
||||||
|
handleLongPress(isPressing: true)
|
||||||
case .ended, .cancelled, .failed:
|
case .ended, .cancelled, .failed:
|
||||||
handleLongPress(isPressing: false)
|
handleLongPress(isPressing: false)
|
||||||
default:
|
case .possible, .changed:
|
||||||
handleLongPress(isPressing: true)
|
break
|
||||||
|
@unknown default:
|
||||||
|
break
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} else {
|
} 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.
|
// 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))
|
try? await Task.sleep(for: .seconds(0.5))
|
||||||
|
|
||||||
if Task.isCancelled { return }
|
if Task.isCancelled {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
action()
|
action()
|
||||||
feedbackGenerator.impactOccurred()
|
feedbackGenerator.impactOccurred()
|
||||||
|
|||||||
Reference in New Issue
Block a user