mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-27 19:56:57 +02:00
Fixes #4935 - Enable voice message scrubbing pan gesture only after long press.
This commit is contained in:
committed by
Stefan Ceriu
parent
09911bd244
commit
27eaa9453c
@@ -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() {
|
||||
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)
|
||||
}
|
||||
|
||||
@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
|
||||
}
|
||||
|
||||
switch gestureRecognizer.state {
|
||||
case .began:
|
||||
panGestureRecognizer.isEnabled = true
|
||||
case .ended, .failed, .cancelled:
|
||||
panGestureRecognizer.isEnabled = false
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
@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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,10 +51,6 @@
|
||||
<rect key="frame" x="94" y="7" width="317" height="30"/>
|
||||
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
||||
<gestureRecognizers/>
|
||||
<connections>
|
||||
<outletCollection property="gestureRecognizers" destination="TvB-7x-51j" appends="YES" id="2ac-M3-OKn"/>
|
||||
<outletCollection property="gestureRecognizers" destination="Fwa-Eg-VFh" appends="YES" id="meS-g1-yIc"/>
|
||||
</connections>
|
||||
</view>
|
||||
</subviews>
|
||||
<constraints>
|
||||
@@ -86,16 +82,6 @@
|
||||
</connections>
|
||||
<point key="canvasLocation" x="-1742.753623188406" y="-299.33035714285711"/>
|
||||
</view>
|
||||
<panGestureRecognizer minimumNumberOfTouches="1" id="TvB-7x-51j">
|
||||
<connections>
|
||||
<action selector="panWithGestureRecognizer:" destination="cGR-49-HWB" id="mcT-Wy-ePL"/>
|
||||
</connections>
|
||||
</panGestureRecognizer>
|
||||
<tapGestureRecognizer id="Fwa-Eg-VFh">
|
||||
<connections>
|
||||
<action selector="tapWithGestureRecognizer:" destination="cGR-49-HWB" id="VMd-gQ-DPy"/>
|
||||
</connections>
|
||||
</tapGestureRecognizer>
|
||||
</objects>
|
||||
<resources>
|
||||
<image name="voice_message_play_button" width="15.5" height="15"/>
|
||||
|
||||
Reference in New Issue
Block a user