Skip to content

Commit ae6f06b

Browse files
committed
IOS-12694: Video player: playback controls remain visible while scrubbing the timeline
(cherry picked from commit 217cedf) 217cedf IOS-12694: Video player: playback controls remain visible while scrubbing the timeline Co-authored-by: Jeff Fang <yfa@mega.co.nz>
1 parent 92afbfa commit ae6f06b

3 files changed

Lines changed: 29 additions & 5 deletions

File tree

‎Modules/Features/MEGAVideoPlayer/Sources/MEGAVideoPlayer/Overlay/PlayerOverlayView.swift‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,10 @@ public struct PlayerOverlayView: View {
9090
}
9191

9292
if viewModel.isControlsVisible {
93-
topToolbar
94-
centerPlaybackButtons
93+
if !viewModel.isScrubbing {
94+
topToolbar
95+
centerPlaybackButtons
96+
}
9597
bottomToolbar(isLandscape: isLandscape)
9698
}
9799

@@ -142,7 +144,7 @@ public struct PlayerOverlayView: View {
142144
}
143145

144146
private var backgroundColor: Color {
145-
if viewModel.isControlsVisible {
147+
if viewModel.isControlsVisible && !viewModel.isScrubbing {
146148
TokenColors.Background.blur.swiftUI
147149
} else {
148150
Color.clear

‎Modules/Features/MEGAVideoPlayer/Sources/MEGAVideoPlayer/Overlay/PlayerOverlayViewModel.swift‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ public final class PlayerOverlayViewModel: ObservableObject {
3232
@Published var isExternalPlaybackActive: Bool = false
3333
@Published var audioTrackSelection: AudioTrackSelection?
3434
@Published var isAudioTrackMenuPresented: Bool = false
35+
/// Whether a finger is currently on the seek bar
36+
@Published private(set) var isScrubbing = false
3537
private(set) var shouldShowPhotoPermissionAlert = false
3638
private var shouldShowAudioTrackMenu = false
3739
private var isHoldToSpeed = false
38-
/// Whether a finger is currently on the seek bar
39-
private(set) var isScrubbing = false
4040
private var shouldResumeAfterScrub = false
4141
private var autoHideTimer: Timer?
4242
private var doubleTapSeekTimer: Timer?

‎Modules/Features/MEGAVideoPlayer/Tests/MEGAVideoPlayerTests/PlayerOverlayViewModelTests.swift‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -894,6 +894,28 @@ struct PlayerOverlayViewModelTests {
894894
#expect(mockPlayer.pauseCallCount == expectedPauseCallCount)
895895
}
896896

897+
/// While scrubbing, the overlay hides the top toolbar, the playback buttons and the dimming layer
898+
/// based on `isScrubbing`, so the drag must publish its start and end. `isControlsVisible` is left
899+
/// untouched, so the controls reappear on their own once the finger lifts.
900+
@Test
901+
func seekBarDrag_shouldPublishScrubbingWithoutHidingControls() async {
902+
let sut = makeSUT()
903+
sut.duration = .seconds(100)
904+
sut.state = .playing
905+
let frame = CGRect(x: 0, y: 0, width: 100, height: 20)
906+
var publishedValues: [Bool] = []
907+
let cancellable = sut.$isScrubbing.sink { publishedValues.append($0) }
908+
909+
await sut.updateSeekBarDrag(at: CGPoint(x: 10, y: 10), in: frame)
910+
#expect(sut.isControlsVisible == true)
911+
912+
await sut.endSeekBarDrag(at: CGPoint(x: 20, y: 10), in: frame)
913+
914+
#expect(publishedValues == [false, true, false])
915+
#expect(sut.isControlsVisible == true)
916+
cancellable.cancel()
917+
}
918+
897919
@Test(arguments: [
898920
(PlaybackState.playing, 1),
899921
(.paused, 0)

0 commit comments

Comments
 (0)