yattee/Shared/Views/ChannelCell.swift

89 lines
2.4 KiB
Swift
Raw Normal View History

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(
2021-12-17 16:34:55 +00:00
channel,
2022-06-30 08:05:32 +00:00
navigationStyle: navigationStyle
2021-12-17 16:34:55 +00:00
)
} 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 {
2021-10-22 23:04:03 +00:00
HStack(alignment: .top, spacing: 3) {
Image(systemName: "person.crop.rectangle")
2022-12-04 12:43:09 +00:00
Text("Channel".localized().uppercased())
2021-10-22 23:04:03 +00:00
.fontWeight(.light)
.opacity(0.6)
}
.foregroundColor(.secondary)
2022-09-11 19:33:08 +00:00
2022-11-10 18:11:19 +00:00
WebImage(url: channel.thumbnailURL, options: [.lowPriority])
2022-09-11 19:33:08 +00:00
.resizable()
.placeholder {
Rectangle().fill(Color("PlaceholderColor"))
}
2022-09-11 19:33:08 +00:00
.indicator(.activity)
.frame(width: 88, height: 88)
.clipShape(Circle())
2021-10-22 23:04:03 +00:00
DetailBadge(text: channel.name, style: .prominent)
2021-10-22 23:04:03 +00:00
Group {
if let subscriptions = channel.subscriptionsString {
Text("\(subscriptions) subscribers")
.foregroundColor(.secondary)
} else {
Text("")
}
}
2021-10-22 23:04:03 +00:00
.frame(height: 20)
}
}
}
struct ChannelSearchItem_Preview: PreviewProvider {
static var previews: some View {
Group {
ChannelCell(channel: Video.fixture.channel)
}
.frame(maxWidth: 300, maxHeight: 200)
.injectFixtureEnvironmentObjects()
}
}