mirror of
https://github.com/yattee/yattee.git
synced 2025-08-05 02:04:07 +00:00
Channels search, add SDWebImage framework
This commit is contained in:
@@ -1,96 +0,0 @@
|
||||
import SwiftUI
|
||||
|
||||
struct DetailBadge: View {
|
||||
enum Style {
|
||||
case `default`, prominent, outstanding, informational
|
||||
}
|
||||
|
||||
struct StyleModifier: ViewModifier {
|
||||
let style: Style
|
||||
|
||||
func body(content: Content) -> some View {
|
||||
Group {
|
||||
switch style {
|
||||
case .prominent:
|
||||
content.modifier(ProminentStyleModifier())
|
||||
case .outstanding:
|
||||
content.modifier(OutstandingStyleModifier())
|
||||
case .informational:
|
||||
content.modifier(InformationalStyleModifier())
|
||||
default:
|
||||
content.modifier(DefaultStyleModifier())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct DefaultStyleModifier: ViewModifier {
|
||||
func body(content: Content) -> some View {
|
||||
content
|
||||
.background(.thinMaterial)
|
||||
}
|
||||
}
|
||||
|
||||
struct ProminentStyleModifier: ViewModifier {
|
||||
var font: Font {
|
||||
Font.system(.body).weight(.semibold)
|
||||
}
|
||||
|
||||
func body(content: Content) -> some View {
|
||||
content
|
||||
.font(font)
|
||||
.modifier(DefaultStyleModifier())
|
||||
}
|
||||
}
|
||||
|
||||
struct OutstandingStyleModifier: ViewModifier {
|
||||
var backgroundColor: Color {
|
||||
Color("DetailBadgeOutstandingStyleBackgroundColor")
|
||||
}
|
||||
|
||||
func body(content: Content) -> some View {
|
||||
content
|
||||
.textCase(.uppercase)
|
||||
.background(backgroundColor)
|
||||
.foregroundColor(.white)
|
||||
}
|
||||
}
|
||||
|
||||
struct InformationalStyleModifier: ViewModifier {
|
||||
var backgroundColor: Color {
|
||||
Color("DetailBadgeInformationalStyleBackgroundColor")
|
||||
}
|
||||
|
||||
func body(content: Content) -> some View {
|
||||
content
|
||||
.background(backgroundColor)
|
||||
.foregroundColor(.white)
|
||||
}
|
||||
}
|
||||
|
||||
var text: String
|
||||
var style: Style = .default
|
||||
|
||||
var body: some View {
|
||||
Text(text)
|
||||
.lineLimit(1)
|
||||
.truncationMode(.middle)
|
||||
.padding(10)
|
||||
.modifier(StyleModifier(style: style))
|
||||
.mask(RoundedRectangle(cornerRadius: 12))
|
||||
}
|
||||
}
|
||||
|
||||
struct DetailBadge_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
VStack {
|
||||
DetailBadge(text: "Live", style: .outstanding)
|
||||
DetailBadge(text: "Premieres", style: .informational)
|
||||
DetailBadge(text: "Booyah", style: .prominent)
|
||||
DetailBadge(
|
||||
text: "Donec in neque mi. Phasellus quis sapien metus. Ut felis ante, posuere."
|
||||
)
|
||||
}
|
||||
.frame(maxWidth: 500)
|
||||
}
|
||||
}
|
@@ -1,18 +1,18 @@
|
||||
import Defaults
|
||||
import SwiftUI
|
||||
|
||||
struct VideosCellsHorizontal: View {
|
||||
struct HorizontalCells: View {
|
||||
#if os(iOS)
|
||||
@Environment(\.verticalSizeClass) private var verticalSizeClass
|
||||
#endif
|
||||
|
||||
var videos = [Video]()
|
||||
var items = [ContentItem]()
|
||||
|
||||
var body: some View {
|
||||
ScrollView(.horizontal, showsIndicators: false) {
|
||||
LazyHStack(spacing: 20) {
|
||||
ForEach(videos) { video in
|
||||
VideoView(video: video)
|
||||
ForEach(items) { item in
|
||||
ContentItemView(item: item)
|
||||
.environment(\.horizontalCells, true)
|
||||
#if os(tvOS)
|
||||
.frame(width: 580)
|
||||
@@ -42,9 +42,9 @@ struct VideosCellsHorizontal: View {
|
||||
}
|
||||
}
|
||||
|
||||
struct VideoCellsHorizontal_Previews: PreviewProvider {
|
||||
struct HorizontalCells_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
VideosCellsHorizontal(videos: Video.allFixtures)
|
||||
HorizontalCells(items: ContentItem.array(of: Video.allFixtures))
|
||||
.injectFixtureEnvironmentObjects()
|
||||
}
|
||||
}
|
@@ -1,29 +1,23 @@
|
||||
import Defaults
|
||||
import SwiftUI
|
||||
|
||||
struct VideosCellsVertical: View {
|
||||
struct VerticalCells: View {
|
||||
#if os(iOS)
|
||||
@Environment(\.verticalSizeClass) private var verticalSizeClass
|
||||
#endif
|
||||
|
||||
var videos = [Video]()
|
||||
var items = [ContentItem]()
|
||||
|
||||
var body: some View {
|
||||
ScrollView(.vertical, showsIndicators: scrollViewShowsIndicators) {
|
||||
LazyVGrid(columns: items, alignment: .center) {
|
||||
ForEach(videos) { video in
|
||||
VideoView(video: video)
|
||||
#if os(tvOS)
|
||||
.padding(.horizontal)
|
||||
#endif
|
||||
LazyVGrid(columns: columns, alignment: .center) {
|
||||
ForEach(items.sorted { $0 < $1 }) { item in
|
||||
ContentItemView(item: item)
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
}
|
||||
.id(UUID())
|
||||
#if os(tvOS)
|
||||
.padding(.horizontal, 10)
|
||||
#endif
|
||||
.edgesIgnoringSafeArea(.horizontal)
|
||||
#if os(macOS)
|
||||
.background()
|
||||
@@ -31,9 +25,9 @@ struct VideosCellsVertical: View {
|
||||
#endif
|
||||
}
|
||||
|
||||
var items: [GridItem] {
|
||||
var columns: [GridItem] {
|
||||
#if os(tvOS)
|
||||
videos.count < 3 ? Array(repeating: GridItem(.fixed(540)), count: [videos.count, 1].max()!) : adaptiveItem
|
||||
items.count < 3 ? Array(repeating: GridItem(.fixed(540)), count: [items.count, 1].max()!) : adaptiveItem
|
||||
#else
|
||||
adaptiveItem
|
||||
#endif
|
||||
@@ -64,7 +58,7 @@ struct VideosCellsVertical: View {
|
||||
|
||||
struct VideoCellsVertical_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
VideosCellsVertical(videos: Video.allFixtures)
|
||||
VerticalCells(items: ContentItem.array(of: Video.allFixtures))
|
||||
.injectFixtureEnvironmentObjects()
|
||||
}
|
||||
}
|
@@ -1,4 +1,5 @@
|
||||
import Foundation
|
||||
import SDWebImageSwiftUI
|
||||
import SwiftUI
|
||||
|
||||
struct VideoBanner: View {
|
||||
@@ -35,22 +36,12 @@ struct VideoBanner: View {
|
||||
}
|
||||
|
||||
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")
|
||||
WebImage(url: video.thumbnailURL(quality: .medium))
|
||||
.resizable()
|
||||
.placeholder {
|
||||
ProgressView()
|
||||
}
|
||||
}
|
||||
.background(.gray)
|
||||
.indicator(.activity)
|
||||
#if os(tvOS)
|
||||
.frame(width: 177, height: 100)
|
||||
.mask(RoundedRectangle(cornerRadius: 12))
|
||||
|
@@ -1,10 +1,12 @@
|
||||
import Defaults
|
||||
import SDWebImageSwiftUI
|
||||
import SwiftUI
|
||||
|
||||
struct VideoView: View {
|
||||
struct VideoCell: View {
|
||||
var video: Video
|
||||
|
||||
@State private var playerNavigationLinkActive = false
|
||||
@State private var lowQualityThumbnail = false
|
||||
|
||||
@Environment(\.inNavigationView) private var inNavigationView
|
||||
|
||||
@@ -181,7 +183,7 @@ struct VideoView: View {
|
||||
|
||||
var thumbnail: some View {
|
||||
ZStack(alignment: .leading) {
|
||||
thumbnailImage(quality: .maxresdefault)
|
||||
thumbnailImage(quality: lowQualityThumbnail ? .medium : .maxresdefault)
|
||||
|
||||
VStack {
|
||||
HStack(alignment: .top) {
|
||||
@@ -212,27 +214,20 @@ struct VideoView: View {
|
||||
}
|
||||
|
||||
func thumbnailImage(quality: Thumbnail.Quality) -> some View {
|
||||
Group {
|
||||
if let url = video.thumbnailURL(quality: quality) {
|
||||
AsyncImage(url: url) { image in
|
||||
image
|
||||
.resizable()
|
||||
} placeholder: {
|
||||
HStack {
|
||||
ProgressView()
|
||||
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Image(systemName: "exclamationmark.square")
|
||||
WebImage(url: video.thumbnailURL(quality: quality))
|
||||
.resizable()
|
||||
.placeholder {
|
||||
Rectangle().fill(Color("PlaceholderColor"))
|
||||
}
|
||||
}
|
||||
.background(.gray)
|
||||
.mask(RoundedRectangle(cornerRadius: 12))
|
||||
.onFailure { _ in
|
||||
lowQualityThumbnail = true
|
||||
}
|
||||
.indicator(.progress)
|
||||
.mask(RoundedRectangle(cornerRadius: 12))
|
||||
.modifier(AspectRatioModifier())
|
||||
#if os(tvOS)
|
||||
.frame(minHeight: 320)
|
||||
#endif
|
||||
.modifier(AspectRatioModifier())
|
||||
}
|
||||
|
||||
func videoDetail(_ text: String, lineLimit: Int = 1) -> some View {
|
||||
@@ -257,3 +252,13 @@ struct VideoView: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct VideoView_Preview: PreviewProvider {
|
||||
static var previews: some View {
|
||||
Group {
|
||||
VideoCell(video: Video.fixture)
|
||||
}
|
||||
.frame(maxWidth: 300, maxHeight: 200)
|
||||
.injectFixtureEnvironmentObjects()
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user