diff --git a/Riot/Modules/Room/VoiceMessages/VoiceMessagePlaybackView.swift b/Riot/Modules/Room/VoiceMessages/VoiceMessagePlaybackView.swift
index 77638d38be..436e1002a4 100644
--- a/Riot/Modules/Room/VoiceMessages/VoiceMessagePlaybackView.swift
+++ b/Riot/Modules/Room/VoiceMessages/VoiceMessagePlaybackView.swift
@@ -43,7 +43,6 @@ class VoiceMessagePlaybackView: UIView, NibLoadable, Themable {
private var _waveformView: VoiceMessageWaveformView!
private var currentTheme: Theme?
- private var scrubProgress: CGFloat?
@IBOutlet private var backgroundView: UIView!
@IBOutlet private var recordingIcon: UIView!
@@ -51,6 +50,9 @@ class VoiceMessagePlaybackView: UIView, NibLoadable, Themable {
@IBOutlet private var elapsedTimeLabel: UILabel!
@IBOutlet private var waveformContainerView: UIView!
+ private var longPressGestureRecognizer: UILongPressGestureRecognizer!
+ private var panGestureRecognizer: UIPanGestureRecognizer!
+
weak var delegate: VoiceMessagePlaybackViewDelegate?
var details: VoiceMessagePlaybackViewDetails?
@@ -75,6 +77,14 @@ class VoiceMessagePlaybackView: UIView, NibLoadable, Themable {
_waveformView = VoiceMessageWaveformView(frame: waveformContainerView.bounds)
waveformContainerView.vc_addSubViewMatchingParent(_waveformView)
+
+ longPressGestureRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(handleLongPressGesture(_:)))
+ longPressGestureRecognizer.minimumPressDuration = 0.2
+ waveformView.addGestureRecognizer(longPressGestureRecognizer)
+
+ panGestureRecognizer = UIPanGestureRecognizer(target: self, action: #selector(handlePanGesture(_:)))
+ panGestureRecognizer.isEnabled = false
+ waveformView.addGestureRecognizer(panGestureRecognizer)
}
func configureWithDetails(_ details: VoiceMessagePlaybackViewDetails?) {
@@ -136,28 +146,36 @@ class VoiceMessagePlaybackView: UIView, NibLoadable, Themable {
currentTheme = theme
configureWithDetails(details)
}
-
+
// MARK: - Private
- @IBAction private func onPlayButtonTap() {
+ private func onPlayButtonTap() {
delegate?.voiceMessagePlaybackViewDidRequestPlaybackToggle()
}
- @IBAction private func tap(gestureRecognizer: UITapGestureRecognizer) {
+ @objc private func handleLongPressGesture(_ gestureRecognizer: UITapGestureRecognizer) {
let x = gestureRecognizer.location(in: waveformContainerView).x.clamped(to: 0...waveformContainerView.bounds.width)
let progress = x / waveformContainerView.bounds.width
delegate?.voiceMessagePlaybackViewDidRequestSeek(to: progress)
+
+ switch gestureRecognizer.state {
+ case .began:
+ panGestureRecognizer.isEnabled = true
+ case .ended, .failed, .cancelled:
+ panGestureRecognizer.isEnabled = false
+ default:
+ break
+ }
}
-
- @IBAction private func pan(gestureRecognizer: UIPanGestureRecognizer) {
- switch gestureRecognizer.state {
- case .began, .changed:
- let x = gestureRecognizer.location(in: waveformContainerView).x.clamped(to: 0...waveformContainerView.bounds.width)
- let progress = x / waveformContainerView.bounds.width
- scrubProgress = progress
- delegate?.voiceMessagePlaybackViewDidRequestSeek(to: progress)
- default:
- scrubProgress = nil
- }
+
+ @objc private func handlePanGesture(_ gestureRecognizer: UIPanGestureRecognizer) {
+ switch gestureRecognizer.state {
+ case .began, .changed:
+ let x = gestureRecognizer.location(in: waveformContainerView).x.clamped(to: 0...waveformContainerView.bounds.width)
+ let progress = x / waveformContainerView.bounds.width
+ delegate?.voiceMessagePlaybackViewDidRequestSeek(to: progress)
+ default:
+ break
}
+ }
}
diff --git a/Riot/Modules/Room/VoiceMessages/VoiceMessagePlaybackView.xib b/Riot/Modules/Room/VoiceMessages/VoiceMessagePlaybackView.xib
index d60ec0b68b..1bbca0184c 100644
--- a/Riot/Modules/Room/VoiceMessages/VoiceMessagePlaybackView.xib
+++ b/Riot/Modules/Room/VoiceMessages/VoiceMessagePlaybackView.xib
@@ -51,10 +51,6 @@
-
-
-
-
@@ -86,16 +82,6 @@
-
-
-
-
-
-
-
-
-
-
diff --git a/changelog.d/4935.change b/changelog.d/4935.change
new file mode 100644
index 0000000000..93c0dcc9cc
--- /dev/null
+++ b/changelog.d/4935.change
@@ -0,0 +1 @@
+Voice Message scrubbing should require a slightly longer press, to avoid accidental scrubbing when scrolling the timeline
\ No newline at end of file