Skip to content

Commit

Permalink
Fixes #4935 - Enable voice message scrubbing pan gesture only after l…
Browse files Browse the repository at this point in the history
…ong press.
  • Loading branch information
stefanceriu committed Oct 8, 2021
1 parent a9950d1 commit 4e6fcbb
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 29 deletions.
48 changes: 33 additions & 15 deletions Riot/Modules/Room/VoiceMessages/VoiceMessagePlaybackView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,16 @@ 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!
@IBOutlet private var playButton: UIButton!
@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?
Expand All @@ -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?) {
Expand Down Expand Up @@ -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
}
}
}
14 changes: 0 additions & 14 deletions Riot/Modules/Room/VoiceMessages/VoiceMessagePlaybackView.xib
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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"/>
Expand Down
1 change: 1 addition & 0 deletions changelog.d/4935.change
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Voice Message scrubbing should require a slightly longer press, to avoid accidental scrubbing when scrolling the timeline

0 comments on commit 4e6fcbb

Please sign in to comment.