mirror of
https://github.com/yattee/yattee.git
synced 2024-11-10 08:18:19 +00:00
86 lines
2.6 KiB
Swift
86 lines
2.6 KiB
Swift
import CachedAsyncImage
|
|
import Foundation
|
|
import SDWebImageSwiftUI
|
|
import SwiftUI
|
|
|
|
struct ChannelCell: View {
|
|
let channel: Channel
|
|
|
|
@Environment(\.navigationStyle) private var navigationStyle
|
|
|
|
@EnvironmentObject<NavigationModel> private var navigation
|
|
@EnvironmentObject<PlayerModel> private var player
|
|
@EnvironmentObject<RecentsModel> private var recents
|
|
|
|
var body: some View {
|
|
Button {
|
|
NavigationModel.openChannel(
|
|
channel,
|
|
player: player,
|
|
recents: recents,
|
|
navigation: navigation,
|
|
navigationStyle: navigationStyle
|
|
)
|
|
} label: {
|
|
content
|
|
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity)
|
|
.contentShape(RoundedRectangle(cornerRadius: 12))
|
|
}
|
|
.buttonStyle(.plain)
|
|
}
|
|
|
|
var content: some View {
|
|
VStack {
|
|
HStack(alignment: .top, spacing: 3) {
|
|
Image(systemName: "person.crop.rectangle")
|
|
Text("Channel".uppercased())
|
|
.fontWeight(.light)
|
|
.opacity(0.6)
|
|
}
|
|
.foregroundColor(.secondary)
|
|
|
|
Group {
|
|
if #available(iOS 15, macOS 12, *) {
|
|
CachedAsyncImage(url: channel.thumbnailURL) { image in
|
|
image
|
|
.resizable()
|
|
} placeholder: {
|
|
Rectangle().foregroundColor(Color("PlaceholderColor"))
|
|
}
|
|
} else {
|
|
WebImage(url: channel.thumbnailURL)
|
|
.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()
|
|
}
|
|
}
|