1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-15 14:50:32 +05:30
yattee/Shared/Player/PlayerBackendView.swift

99 lines
3.0 KiB
Swift
Raw Normal View History

2022-08-06 18:57:34 +05:30
import SwiftUI
struct PlayerBackendView: View {
#if os(iOS)
@Environment(\.verticalSizeClass) private var verticalSizeClass
#endif
@EnvironmentObject<PlayerModel> private var player
@EnvironmentObject<ThumbnailsModel> private var thumbnails
var body: some View {
ZStack(alignment: .top) {
Group {
switch player.activeBackend {
case .mpv:
player.mpvPlayerView
case .appleAVPlayer:
player.avPlayerView
}
}
.overlay(GeometryReader { proxy in
Color.clear
2022-08-13 20:16:45 +05:30
.onAppear { player.playerSize = proxy.size }
2022-08-06 18:57:34 +05:30
.onChange(of: proxy.size) { _ in player.playerSize = proxy.size }
.onChange(of: player.controls.presentingOverlays) { _ in player.playerSize = proxy.size }
})
#if os(iOS)
.padding(.top, player.playingFullScreen && verticalSizeClass == .regular ? 20 : 0)
#endif
#if !os(tvOS)
PlayerGestures()
PlayerControls(player: player, thumbnails: thumbnails)
#if os(iOS)
.padding(.top, controlsTopPadding)
.padding(.bottom, controlsBottomPadding)
#endif
2022-08-14 22:29:04 +05:30
#else
hiddenControlsButton
2022-08-06 18:57:34 +05:30
#endif
}
#if os(iOS)
.statusBarHidden(fullScreenLayout)
#endif
}
var fullScreenLayout: Bool {
#if os(iOS)
player.playingFullScreen || verticalSizeClass == .compact
#else
player.playingFullScreen
#endif
}
#if os(iOS)
var controlsTopPadding: Double {
guard fullScreenLayout else { return 0 }
if UIDevice.current.userInterfaceIdiom != .pad {
2022-08-07 17:41:57 +05:30
return verticalSizeClass == .compact ? SafeArea.insets.top : 0
2022-08-06 18:57:34 +05:30
} else {
2022-08-07 17:41:57 +05:30
return SafeArea.insets.top.isZero ? SafeArea.insets.bottom : SafeArea.insets.top
2022-08-06 18:57:34 +05:30
}
}
var controlsBottomPadding: Double {
guard fullScreenLayout else { return 0 }
if UIDevice.current.userInterfaceIdiom != .pad {
2022-08-07 17:41:57 +05:30
return fullScreenLayout && verticalSizeClass == .compact ? SafeArea.insets.bottom : 0
2022-08-06 18:57:34 +05:30
} else {
2022-08-07 17:41:57 +05:30
return fullScreenLayout ? SafeArea.insets.bottom : 0
2022-08-06 18:57:34 +05:30
}
}
#endif
2022-08-14 22:29:04 +05:30
#if os(tvOS)
private var hiddenControlsButton: some View {
VStack {
Button {
player.controls.show()
} label: {
EmptyView()
}
.offset(y: -100)
.buttonStyle(.plain)
.background(Color.clear)
.foregroundColor(.clear)
}
}
#endif
2022-08-06 18:57:34 +05:30
}
struct PlayerBackendView_Previews: PreviewProvider {
static var previews: some View {
PlayerBackendView()
.injectFixtureEnvironmentObjects()
}
}