From 09de2cbbab40d3d45b9b72b230b5a361ffcc42b9 Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Thu, 17 Nov 2022 22:47:45 +0100 Subject: [PATCH] Add overlay model visibility methods --- Model/Player/ControlsOverlayModel.swift | 13 ++++++++++++- Model/Player/PlayerControlsModel.swift | 2 +- Shared/Player/Controls/PlayerControls.swift | 2 +- Shared/Player/VideoPlayerView.swift | 2 +- Shared/Views/ControlsBar.swift | 2 +- 5 files changed, 16 insertions(+), 5 deletions(-) diff --git a/Model/Player/ControlsOverlayModel.swift b/Model/Player/ControlsOverlayModel.swift index ec0777bd..91f99d7a 100644 --- a/Model/Player/ControlsOverlayModel.swift +++ b/Model/Player/ControlsOverlayModel.swift @@ -3,8 +3,9 @@ import Foundation import SwiftUI final class ControlOverlaysModel: ObservableObject { + static let animation = Animation.easeInOut(duration: 0.2) static let shared = ControlOverlaysModel() - @Published var presenting = false { didSet { handlePresentationChange() } } + @Published private(set) var presenting = false { didSet { handlePresentationChange() } } private lazy var controls = PlayerControlsModel.shared private lazy var player: PlayerModel! = PlayerModel.shared @@ -14,6 +15,16 @@ final class ControlOverlaysModel: ObservableObject { controls.objectWillChange.send() } + func hide() { + presenting = false + controls.objectWillChange.send() + } + + func show() { + presenting = true + controls.objectWillChange.send() + } + private func handlePresentationChange() { guard let player else { return } player.backend.setNeedsNetworkStateUpdates(presenting && Defaults[.showMPVPlaybackStats]) diff --git a/Model/Player/PlayerControlsModel.swift b/Model/Player/PlayerControlsModel.swift index 9912fbd1..72ba9c91 100644 --- a/Model/Player/PlayerControlsModel.swift +++ b/Model/Player/PlayerControlsModel.swift @@ -70,7 +70,7 @@ final class PlayerControlsModel: ObservableObject { func hideOverlays() { presentingDetailsOverlay = false - controlsOverlayModel.presenting = false + controlsOverlayModel.hide() } func show() { diff --git a/Shared/Player/Controls/PlayerControls.swift b/Shared/Player/Controls/PlayerControls.swift index c3c74149..2777f62f 100644 --- a/Shared/Player/Controls/PlayerControls.swift +++ b/Shared/Player/Controls/PlayerControls.swift @@ -195,7 +195,7 @@ struct PlayerControls: View { guard player.presentingPlayer else { return } if value == "swipe down", !model.presentingControls, !model.presentingOverlays { withAnimation(Self.animation) { - controlsOverlayModel.presenting = false + controlsOverlayModel.hide() } } else { model.show() diff --git a/Shared/Player/VideoPlayerView.swift b/Shared/Player/VideoPlayerView.swift index eda29c0e..21c2b16a 100644 --- a/Shared/Player/VideoPlayerView.swift +++ b/Shared/Player/VideoPlayerView.swift @@ -367,7 +367,7 @@ struct VideoPlayerView: View { player.controls.show() } else if direction == .down, !controlsOverlayModel.presenting, !player.controls.presentingControls { withAnimation(PlayerControls.animation) { - controlsOverlayModel.presenting = true + controlsOverlayModel.hide() } } diff --git a/Shared/Views/ControlsBar.swift b/Shared/Views/ControlsBar.swift index 2d883c99..e526484b 100644 --- a/Shared/Views/ControlsBar.swift +++ b/Shared/Views/ControlsBar.swift @@ -66,7 +66,7 @@ struct ControlsBar: View { } } else if detailsToggleFullScreen { Button { - controlsOverlayModel.presenting = false + controlsOverlayModel.hide() controls.presentingControls = false withAnimation { fullScreen.toggle()