Display more details in player view

This commit is contained in:
Arkadiusz Fal
2021-08-22 21:13:33 +02:00
parent ea634390a6
commit f80b61f9c7
22 changed files with 716 additions and 36 deletions

View File

@@ -3,11 +3,24 @@ import Siesta
import SwiftUI
struct VideoPlayerView: View {
static let defaultAspectRatio: CGFloat = 1.77777778
static var defaultMinimumHeightLeft: CGFloat {
#if os(macOS)
300
#else
200
#endif
}
@EnvironmentObject<NavigationState> private var navigationState
@ObservedObject private var store = Store<Video>()
@Environment(\.dismiss) private var dismiss
@ObservedObject private var playbackState = PlaybackState()
#if os(iOS)
@Environment(\.verticalSizeClass) private var verticalSizeClass
#endif
var resource: Resource {
InvidiousAPI.shared.video(video.id)
@@ -21,25 +34,50 @@ struct VideoPlayerView: View {
}
var body: some View {
VStack {
Player(video: video)
.frame(alignment: .leading)
VStack(spacing: 0) {
#if os(tvOS)
Player(playbackState: playbackState, video: video)
#else
GeometryReader { geometry in
VStack(spacing: 0) {
#if os(iOS)
if verticalSizeClass == .regular {
PlaybackBar(playbackState: playbackState, video: video)
}
#elseif os(macOS)
PlaybackBar(playbackState: playbackState, video: video)
#endif
#if !os(tvOS)
ScrollView(.vertical) {
VStack(alignment: .leading) {
Text(video.title)
Text(video.author)
Button("Done") {
dismiss()
}
.keyboardShortcut(.cancelAction)
Player(playbackState: playbackState, video: video)
.modifier(VideoPlayerSizeModifier(geometry: geometry, aspectRatio: playbackState.aspectRatio))
}
.frame(minWidth: 0, maxWidth: .infinity, alignment: .leading)
.background(.black)
VStack(spacing: 0) {
#if os(iOS)
if verticalSizeClass == .regular {
ScrollView(.vertical, showsIndicators: showScrollIndicators) {
if let video = store.item {
VideoDetails(video: video)
} else {
VideoDetails(video: video)
}
}
}
#else
if let video = store.item {
VideoDetails(video: video)
} else {
VideoDetails(video: video)
}
#endif
}
.modifier(VideoDetailsPaddingModifier(geometry: geometry, aspectRatio: playbackState.aspectRatio))
}
.animation(.linear(duration: 0.2), value: playbackState.aspectRatio)
#endif
}
.onAppear {
resource.loadIfNeeded()
}
@@ -51,8 +89,29 @@ struct VideoPlayerView: View {
}
#if os(macOS)
.navigationTitle(video.title)
.frame(maxWidth: 1000, minHeight: 700)
#elseif os(iOS)
.navigationBarTitle(video.title, displayMode: .inline)
#endif
}
var showScrollIndicators: Bool {
#if os(macOS)
false
#else
true
#endif
}
}
struct VideoPlayerView_Previews: PreviewProvider {
static var previews: some View {
VStack {
Spacer()
}
.sheet(isPresented: .constant(true)) {
VideoPlayerView(Video.fixture)
.environmentObject(NavigationState())
}
}
}