1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-13 05:40: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
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])

View File

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

View File

@ -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()

View File

@ -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()
}
}

View File

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