Fade out tvOS player controls on auto-hide

This commit is contained in:
Arkadiusz Fal
2026-04-15 07:14:54 +02:00
parent c52796db75
commit 758f4a678d

View File

@@ -201,34 +201,37 @@ struct TVPlayerView: View {
// Video layer // Video layer
videoLayer videoLayer
// Controls overlay // Controls overlay always in tree, toggled via opacity so the fade-out
if controlsVisible && !isDetailsPanelVisible && !isDebugOverlayVisible { // isn't skipped by tvOS's focus engine forcibly tearing down a focused
TVPlayerControlsView( // subview when the conditional flips to false.
playerState: playerState, TVPlayerControlsView(
playerService: playerService, playerState: playerState,
focusedControl: $focusedControl, playerService: playerService,
onShowSettings: { showQualitySheet() }, focusedControl: $focusedControl,
onShowQueue: { showQueueSheet() }, onShowSettings: { showQualitySheet() },
onShowDetails: { showDetailsPanel(tab: .info) }, onShowQueue: { showQueueSheet() },
onShowComments: { showDetailsPanel(tab: .comments) }, onShowDetails: { showDetailsPanel(tab: .info) },
onShowDebug: { showDebugOverlay() }, onShowComments: { showDetailsPanel(tab: .comments) },
onClose: { closeVideo() }, onShowDebug: { showDebugOverlay() },
onScrubbingChanged: { scrubbing in onClose: { closeVideo() },
isScrubbing = scrubbing onScrubbingChanged: { scrubbing in
if scrubbing { isScrubbing = scrubbing
stopControlsTimer() if scrubbing {
} else { stopControlsTimer()
startControlsTimer() } else {
} startControlsTimer()
}, }
remoteSeekTime: scrubberRemoteSeekTime, },
onRemoteSeek: { forward in remoteSeekTime: scrubberRemoteSeekTime,
triggerScrubberRemoteSeek(forward: forward) onRemoteSeek: { forward in
}, triggerScrubberRemoteSeek(forward: forward)
cancelScrubTrigger: cancelScrubTrigger },
) cancelScrubTrigger: cancelScrubTrigger
.transition(.opacity.animation(.easeInOut(duration: 0.25))) )
} .opacity(shouldShowControls ? 1 : 0)
.allowsHitTesting(shouldShowControls)
.disabled(!shouldShowControls)
.animation(.easeInOut(duration: 0.25), value: shouldShowControls)
// Swipe-up details panel // Swipe-up details panel
if isDetailsPanelVisible { if isDetailsPanelVisible {
@@ -382,6 +385,13 @@ struct TVPlayerView: View {
} }
} }
// MARK: - Derived State
/// Whether the primary controls overlay should be visible right now.
private var shouldShowControls: Bool {
controlsVisible && !isDetailsPanelVisible && !isDebugOverlayVisible
}
// MARK: - Controls Timer // MARK: - Controls Timer
private func startControlsTimer() { private func startControlsTimer() {
@@ -392,9 +402,8 @@ struct TVPlayerView: View {
controlsHideTimer = Timer.scheduledTimer(withTimeInterval: 4.0, repeats: false) { _ in controlsHideTimer = Timer.scheduledTimer(withTimeInterval: 4.0, repeats: false) { _ in
Task { @MainActor in Task { @MainActor in
withAnimation(.easeOut(duration: 0.3)) { withAnimation(.easeOut(duration: 0.2)) {
controlsVisible = false controlsVisible = false
focusedControl = .background
} }
} }
} }
@@ -662,9 +671,8 @@ struct TVPlayerView: View {
private func hideControls() { private func hideControls() {
stopControlsTimer() stopControlsTimer()
withAnimation(.easeOut(duration: 0.25)) { withAnimation(.easeOut(duration: 0.2)) {
controlsVisible = false controlsVisible = false
focusedControl = .background
} }
} }