2022-12-17 18:35:07 +00:00
|
|
|
import Defaults
|
2022-12-10 21:37:14 +00:00
|
|
|
import Foundation
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct PlayerOverlayModifier: ViewModifier {
|
2022-12-17 18:35:07 +00:00
|
|
|
@ObservedObject private var player = PlayerModel.shared
|
|
|
|
@State private var expansionState = ControlsBar.ExpansionState.mini
|
|
|
|
|
|
|
|
@Environment(\.navigationStyle) private var navigationStyle
|
|
|
|
|
|
|
|
@Default(.playerButtonShowsControlButtonsWhenMinimized) private var controlsWhenMinimized
|
|
|
|
|
2022-12-10 21:37:14 +00:00
|
|
|
func body(content: Content) -> some View {
|
|
|
|
content
|
2022-12-11 11:38:57 +00:00
|
|
|
#if !os(tvOS)
|
2022-12-17 18:35:07 +00:00
|
|
|
.overlay(overlay, alignment: .bottomTrailing)
|
2022-12-11 11:38:57 +00:00
|
|
|
#endif
|
2022-12-10 21:37:14 +00:00
|
|
|
}
|
2022-12-17 18:35:07 +00:00
|
|
|
|
|
|
|
@ViewBuilder var overlay: some View {
|
|
|
|
Group {
|
|
|
|
if player.currentItem != nil {
|
|
|
|
ControlsBar(fullScreen: .constant(false), expansionState: $expansionState, playerBar: true)
|
|
|
|
.offset(x: expansionState == .mini && !controlsWhenMinimized ? 10 : 0, y: 0)
|
|
|
|
.transition(.opacity)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.animation(.default, value: player.currentItem)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct PlayerOverlayModifier_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
|
|
|
HStack {}
|
|
|
|
.frame(maxWidth: .infinity, maxHeight: 100)
|
|
|
|
.modifier(PlayerOverlayModifier())
|
|
|
|
}
|
2022-12-10 21:37:14 +00:00
|
|
|
}
|