2022-12-18 00:05:07 +05:30
|
|
|
import Defaults
|
2022-12-11 03:07:14 +05:30
|
|
|
import Foundation
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct PlayerOverlayModifier: ViewModifier {
|
2022-12-18 00:05:07 +05:30
|
|
|
@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-19 06:07:09 +05:30
|
|
|
@Default(.playerButtonIsExpanded) private var playerButtonIsExpanded
|
|
|
|
@Default(.playerBarMaxWidth) private var playerBarMaxWidth
|
2022-12-18 00:05:07 +05:30
|
|
|
|
2022-12-11 03:07:14 +05:30
|
|
|
func body(content: Content) -> some View {
|
|
|
|
content
|
2022-12-11 17:08:57 +05:30
|
|
|
#if !os(tvOS)
|
2022-12-18 00:05:07 +05:30
|
|
|
.overlay(overlay, alignment: .bottomTrailing)
|
2022-12-11 17:08:57 +05:30
|
|
|
#endif
|
2022-12-11 03:07:14 +05:30
|
|
|
}
|
2022-12-18 00:05:07 +05:30
|
|
|
|
|
|
|
@ViewBuilder var overlay: some View {
|
|
|
|
Group {
|
2022-12-19 18:15:41 +05:30
|
|
|
ControlsBar(fullScreen: .constant(false), expansionState: $expansionState, playerBar: true)
|
|
|
|
.offset(x: expansionState == .mini && !controlsWhenMinimized ? 10 : 0, y: 0)
|
|
|
|
.frame(maxWidth: maxWidth, alignment: .trailing)
|
|
|
|
.onAppear {
|
|
|
|
if playerButtonIsExpanded {
|
|
|
|
expansionState = .full
|
2022-12-19 06:07:09 +05:30
|
|
|
}
|
2022-12-19 18:15:41 +05:30
|
|
|
}
|
|
|
|
.animation(.easeIn, value: player.videoForDisplay)
|
|
|
|
.opacity(player.videoForDisplay == nil ? 0 : 1)
|
2022-12-18 00:05:07 +05:30
|
|
|
}
|
|
|
|
}
|
2022-12-19 06:07:09 +05:30
|
|
|
|
|
|
|
var maxWidth: Double {
|
|
|
|
playerBarMaxWidth == "0" ? .infinity : (Double(playerBarMaxWidth) ?? 600)
|
|
|
|
}
|
2022-12-18 00:05:07 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
struct PlayerOverlayModifier_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
|
|
|
HStack {}
|
|
|
|
.frame(maxWidth: .infinity, maxHeight: 100)
|
|
|
|
.modifier(PlayerOverlayModifier())
|
|
|
|
}
|
2022-12-11 03:07:14 +05:30
|
|
|
}
|