mirror of
https://github.com/yattee/yattee.git
synced 2025-08-09 20:24:06 +00:00
Add list views for channels, playlists and placeholders
This commit is contained in:
80
Shared/Channels/ChannelCell.swift
Normal file
80
Shared/Channels/ChannelCell.swift
Normal file
@@ -0,0 +1,80 @@
|
||||
import Foundation
|
||||
import SDWebImageSwiftUI
|
||||
import SwiftUI
|
||||
|
||||
struct ChannelCell: View {
|
||||
let channel: Channel
|
||||
|
||||
@Environment(\.navigationStyle) private var navigationStyle
|
||||
|
||||
var body: some View {
|
||||
#if os(tvOS)
|
||||
button
|
||||
#else
|
||||
if navigationStyle == .tab {
|
||||
navigationLink
|
||||
} else {
|
||||
button
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
var navigationLink: some View {
|
||||
NavigationLink(destination: ChannelVideosView(channel: channel).modifier(PlayerOverlayModifier())) {
|
||||
labelContent
|
||||
}
|
||||
}
|
||||
|
||||
var button: some View {
|
||||
Button {
|
||||
NavigationModel.shared.openChannel(
|
||||
channel,
|
||||
navigationStyle: navigationStyle
|
||||
)
|
||||
} label: {
|
||||
labelContent
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
|
||||
var label: some View {
|
||||
labelContent
|
||||
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity)
|
||||
.contentShape(RoundedRectangle(cornerRadius: 12))
|
||||
}
|
||||
|
||||
var labelContent: some View {
|
||||
VStack {
|
||||
WebImage(url: channel.thumbnailURL, options: [.lowPriority])
|
||||
.resizable()
|
||||
.placeholder {
|
||||
Rectangle().fill(Color("PlaceholderColor"))
|
||||
}
|
||||
.indicator(.activity)
|
||||
.frame(width: 88, height: 88)
|
||||
.clipShape(Circle())
|
||||
|
||||
DetailBadge(text: channel.name, style: .prominent)
|
||||
|
||||
Group {
|
||||
if let subscriptions = channel.subscriptionsString {
|
||||
Text("\(subscriptions) subscribers")
|
||||
.foregroundColor(.secondary)
|
||||
} else {
|
||||
Text("")
|
||||
}
|
||||
}
|
||||
.frame(height: 20)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct ChannelSearchItem_Preview: PreviewProvider {
|
||||
static var previews: some View {
|
||||
Group {
|
||||
ChannelCell(channel: Video.fixture.channel)
|
||||
}
|
||||
.frame(maxWidth: 300, maxHeight: 200)
|
||||
.injectFixtureEnvironmentObjects()
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user