yattee/Apple TV/VideoThumbnailView.swift

83 lines
2.7 KiB
Swift
Raw Normal View History

2021-06-10 22:50:10 +00:00
import SwiftUI
import URLImage
import URLImageStore
struct VideoThumbnailView: View {
2021-06-11 00:05:59 +00:00
@Environment(\.isFocused) private var focused: Bool
2021-06-10 22:50:10 +00:00
var video: Video
var body: some View {
2021-06-11 00:05:59 +00:00
NavigationLink(destination: PlayerView(id: video.id)) {
2021-06-10 22:50:10 +00:00
HStack(alignment: .top, spacing: 2) {
2021-06-11 21:11:59 +00:00
Section {
if let thumbnail = video.thumbnailURL {
// to replace with AsyncImage when it is fixed with lazy views
URLImage(thumbnail) { image in
image
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 320, height: 180)
}
.mask(RoundedRectangle(cornerRadius: 12))
2021-06-10 22:50:10 +00:00
.frame(width: 320, height: 180)
2021-06-11 21:11:59 +00:00
} else {
Image(systemName: "exclamationmark.square")
}
2021-06-10 22:50:10 +00:00
}
.frame(width: 320, height: 180)
2021-06-11 00:05:59 +00:00
HStack {
VStack(alignment: .leading) {
Text(video.title)
.foregroundColor(.primary)
.bold()
.lineLimit(1)
2021-06-10 22:50:10 +00:00
2021-06-11 00:05:59 +00:00
Text("\(video.author)")
.foregroundColor(.secondary)
.bold()
.lineLimit(1)
HStack(spacing: 8) {
Image(systemName: "calendar")
Text(video.published)
Image(systemName: "eye")
Text(video.viewsCount)
}
2021-06-10 22:50:10 +00:00
.foregroundColor(.secondary)
2021-06-11 00:05:59 +00:00
.padding(.top)
}
.padding()
Spacer()
2021-06-10 22:50:10 +00:00
2021-06-11 00:05:59 +00:00
HStack(spacing: 8) {
Image(systemName: "clock")
Text(video.playTime ?? "-")
.fontWeight(.bold)
}
.foregroundColor(.secondary)
}
.frame(minHeight: 180)
2021-06-10 22:50:10 +00:00
}
}
}
}
2021-06-14 18:05:02 +00:00
// struct VideoThumbnailView_Previews: PreviewProvider {
// static var previews: some View {
// VideoThumbnailView(video: Video(
// id: "A",
// title: "A very very long text which",
// thumbnailURL: URL(string: "https://invidious.home.arekf.net/vi/yXohcxCKqvo/maxres.jpg")!,
// author: "Bear",
// length: 240,
// published: "2 days ago",
// channelID: ""
// )).frame(maxWidth: 350)
// }
// }