Initial functionality of player items queue

Fix environment objects

Hide video player placeholder on tvOS

Queue improvements
This commit is contained in:
Arkadiusz Fal
2021-10-05 22:20:09 +02:00
parent d6b3c6637d
commit 70c089e696
44 changed files with 1711 additions and 689 deletions

View File

@@ -0,0 +1,71 @@
import Foundation
import SwiftUI
struct VideoBanner: View {
let video: Video
var body: some View {
HStack(alignment: .center, spacing: 12) {
smallThumbnail
VStack(alignment: .leading, spacing: 4) {
Text(video.title)
.truncationMode(.middle)
.lineLimit(2)
.font(.headline)
.frame(alignment: .leading)
HStack {
Text(video.author)
.lineLimit(1)
Spacer()
if let time = video.playTime {
Text(time)
.fontWeight(.light)
}
}
.foregroundColor(.secondary)
}
}
.contentShape(Rectangle())
.buttonStyle(.plain)
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: 100, alignment: .center)
}
var smallThumbnail: some View {
Group {
if let url = video.thumbnailURL(quality: .medium) {
AsyncImage(url: url) { image in
image
.resizable()
} placeholder: {
HStack {
ProgressView()
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity)
}
}
} else {
Image(systemName: "exclamationmark.square")
}
}
.background(.gray)
#if os(tvOS)
.frame(width: 177, height: 100)
.mask(RoundedRectangle(cornerRadius: 12))
#else
.frame(width: 88, height: 50)
.mask(RoundedRectangle(cornerRadius: 6))
#endif
}
}
struct VideoBanner_Previews: PreviewProvider {
static var previews: some View {
VStack(spacing: 20) {
VideoBanner(video: Video.fixture)
VideoBanner(video: Video.fixtureUpcomingWithoutPublishedOrViews)
}
.frame(maxWidth: 900)
}
}

View File

@@ -2,32 +2,43 @@ import Defaults
import SwiftUI
struct VideoView: View {
@EnvironmentObject<NavigationModel> private var navigation
var video: Video
@State private var playerNavigationLinkActive = false
@Environment(\.inNavigationView) private var inNavigationView
#if os(iOS)
@Environment(\.verticalSizeClass) private var verticalSizeClass
@Environment(\.horizontalCells) private var horizontalCells
#endif
@Environment(\.inNavigationView) private var inNavigationView
var video: Video
@EnvironmentObject<PlayerModel> private var player
var body: some View {
Group {
if inNavigationView {
NavigationLink(destination: VideoPlayerView(video)) {
content
}
} else {
Button(action: { navigation.playVideo(video) }) {
content
Button(action: {
player.playNow(video)
if inNavigationView {
playerNavigationLinkActive = true
} else {
player.presentPlayer()
}
}) {
content
}
NavigationLink(isActive: $playerNavigationLinkActive, destination: {
VideoPlayerView()
.environment(\.inNavigationView, true)
}) {
EmptyView()
}
}
.buttonStyle(.plain)
.contentShape(RoundedRectangle(cornerRadius: 12))
.contextMenu { VideoContextMenuView(video: video) }
.contextMenu { VideoContextMenuView(video: video, playerNavigationLinkActive: $playerNavigationLinkActive) }
}
var content: some View {
@@ -131,7 +142,7 @@ struct VideoView: View {
#else
.frame(minHeight: 50, alignment: .top)
#endif
.padding(.bottom)
.padding(.bottom, 4)
Group {
if additionalDetailsAvailable {

View File

@@ -28,14 +28,14 @@ struct VideosCellsHorizontal: View {
.padding(.vertical, 30)
#else
.padding(.horizontal, 15)
.padding(.vertical, 20)
.padding(.vertical, 10)
#endif
}
.id(UUID())
#if os(tvOS)
.frame(height: 560)
#else
.frame(height: 280)
.frame(height: 250)
#endif
.edgesIgnoringSafeArea(.horizontal)