1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-13 13:50:32 +05:30

Add overlay model visibility methods

This commit is contained in:
Arkadiusz Fal 2022-11-17 22:47:45 +01:00
parent daaf2417b7
commit 09de2cbbab
5 changed files with 16 additions and 5 deletions

View File

@ -3,8 +3,9 @@ import Foundation
import SwiftUI import SwiftUI
final class ControlOverlaysModel: ObservableObject { final class ControlOverlaysModel: ObservableObject {
static let animation = Animation.easeInOut(duration: 0.2)
static let shared = ControlOverlaysModel() 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 controls = PlayerControlsModel.shared
private lazy var player: PlayerModel! = PlayerModel.shared private lazy var player: PlayerModel! = PlayerModel.shared
@ -14,6 +15,16 @@ final class ControlOverlaysModel: ObservableObject {
controls.objectWillChange.send() controls.objectWillChange.send()
} }
func hide() {
presenting = false
controls.objectWillChange.send()
}
func show() {
presenting = true
controls.objectWillChange.send()
}
private func handlePresentationChange() { private func handlePresentationChange() {
guard let player else { return } guard let player else { return }
player.backend.setNeedsNetworkStateUpdates(presenting && Defaults[.showMPVPlaybackStats]) player.backend.setNeedsNetworkStateUpdates(presenting && Defaults[.showMPVPlaybackStats])

View File

@ -70,7 +70,7 @@ final class PlayerControlsModel: ObservableObject {
func hideOverlays() { func hideOverlays() {
presentingDetailsOverlay = false presentingDetailsOverlay = false
controlsOverlayModel.presenting = false controlsOverlayModel.hide()
} }
func show() { func show() {

View File

@ -195,7 +195,7 @@ struct PlayerControls: View {
guard player.presentingPlayer else { return } guard player.presentingPlayer else { return }
if value == "swipe down", !model.presentingControls, !model.presentingOverlays { if value == "swipe down", !model.presentingControls, !model.presentingOverlays {
withAnimation(Self.animation) { withAnimation(Self.animation) {
controlsOverlayModel.presenting = false controlsOverlayModel.hide()
} }
} else { } else {
model.show() model.show()

View File

@ -367,7 +367,7 @@ struct VideoPlayerView: View {
player.controls.show() player.controls.show()
} else if direction == .down, !controlsOverlayModel.presenting, !player.controls.presentingControls { } else if direction == .down, !controlsOverlayModel.presenting, !player.controls.presentingControls {
withAnimation(PlayerControls.animation) { withAnimation(PlayerControls.animation) {
controlsOverlayModel.presenting = true controlsOverlayModel.hide()
} }
} }

View File

@ -66,7 +66,7 @@ struct ControlsBar: View {
} }
} else if detailsToggleFullScreen { } else if detailsToggleFullScreen {
Button { Button {
controlsOverlayModel.presenting = false controlsOverlayModel.hide()
controls.presentingControls = false controls.presentingControls = false
withAnimation { withAnimation {
fullScreen.toggle() fullScreen.toggle()