mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-06 04:18:31 +00:00
Decrease the time it takes for the timeline long press gesture to trigger
This commit is contained in:
committed by
Stefan Ceriu
parent
22c0e38c5d
commit
74e0f03356
@@ -19,6 +19,7 @@ import SwiftUI
|
|||||||
struct LongPressWithFeedback: ViewModifier {
|
struct LongPressWithFeedback: ViewModifier {
|
||||||
let action: () -> Void
|
let action: () -> Void
|
||||||
|
|
||||||
|
@State private var triggerTask: Task<Void, Never>?
|
||||||
@State private var isLongPressing = false
|
@State private var isLongPressing = false
|
||||||
private let feedbackGenerator = UIImpactFeedbackGenerator(style: .heavy)
|
private let feedbackGenerator = UIImpactFeedbackGenerator(style: .heavy)
|
||||||
|
|
||||||
@@ -29,15 +30,27 @@ struct LongPressWithFeedback: ViewModifier {
|
|||||||
.shadow(color: .black.opacity(isLongPressing ? 0.1 : 0.0), radius: isLongPressing ? 3 : 0)
|
.shadow(color: .black.opacity(isLongPressing ? 0.1 : 0.0), radius: isLongPressing ? 3 : 0)
|
||||||
.scaleEffect(x: isLongPressing ? 1.05 : 1,
|
.scaleEffect(x: isLongPressing ? 1.05 : 1,
|
||||||
y: isLongPressing ? 1.05 : 1)
|
y: isLongPressing ? 1.05 : 1)
|
||||||
.animation(isLongPressing ? .spring(response: 1.5).delay(0.2) : .spring(response: 0.5),
|
.animation(isLongPressing ? .spring(response: 0.5).delay(0.1) : .spring(response: 0.5),
|
||||||
value: isLongPressing)
|
value: isLongPressing)
|
||||||
.onLongPressGesture(minimumDuration: 0.25) {
|
// The minimum duration here doesn't actually invoke the perform block when elapsed (thus
|
||||||
action()
|
// the implementation bellow) but it does cancel other system gestures e.g. swipe to reply
|
||||||
feedbackGenerator.impactOccurred()
|
.onLongPressGesture(minimumDuration: 0.25) { } onPressingChanged: { isPressing in
|
||||||
} onPressingChanged: { isPressing in
|
|
||||||
isLongPressing = isPressing
|
isLongPressing = isPressing
|
||||||
if isPressing {
|
|
||||||
feedbackGenerator.prepare()
|
guard isPressing else {
|
||||||
|
triggerTask?.cancel()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
feedbackGenerator.prepare()
|
||||||
|
|
||||||
|
triggerTask = Task {
|
||||||
|
try? await Task.sleep(for: .seconds(0.35))
|
||||||
|
|
||||||
|
if Task.isCancelled { return }
|
||||||
|
|
||||||
|
action()
|
||||||
|
feedbackGenerator.impactOccurred()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user