2022-12-13 10:40:08 +00:00
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct ChannelListItem: View {
|
|
|
|
var channel: Channel
|
|
|
|
|
|
|
|
@Environment(\.inChannelView) private var inChannelView
|
|
|
|
@Environment(\.inNavigationView) private var inNavigationView
|
|
|
|
@Environment(\.navigationStyle) private var navigationStyle
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
channelControl
|
|
|
|
.contentShape(Rectangle())
|
|
|
|
}
|
|
|
|
|
|
|
|
@ViewBuilder private var channelControl: some View {
|
|
|
|
if !channel.name.isEmpty {
|
|
|
|
#if os(tvOS)
|
|
|
|
channelButton
|
|
|
|
#else
|
|
|
|
if navigationStyle == .tab, inNavigationView {
|
|
|
|
channelNavigationLink
|
|
|
|
} else {
|
|
|
|
channelButton
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@ViewBuilder private var channelNavigationLink: some View {
|
|
|
|
NavigationLink(destination: ChannelVideosView(channel: channel)) {
|
|
|
|
label
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@ViewBuilder private var channelButton: some View {
|
|
|
|
Button {
|
|
|
|
guard !inChannelView else { return }
|
|
|
|
|
|
|
|
NavigationModel.shared.openChannel(
|
|
|
|
channel,
|
|
|
|
navigationStyle: navigationStyle
|
|
|
|
)
|
|
|
|
} label: {
|
|
|
|
label
|
|
|
|
}
|
|
|
|
#if os(tvOS)
|
|
|
|
.buttonStyle(.card)
|
|
|
|
#else
|
|
|
|
.buttonStyle(.plain)
|
|
|
|
#endif
|
|
|
|
.help("\(channel.name) Channel")
|
|
|
|
}
|
|
|
|
|
|
|
|
@ViewBuilder private var displayAuthor: some View {
|
|
|
|
if !channel.name.isEmpty {
|
|
|
|
Text(channel.name)
|
|
|
|
.fontWeight(.semibold)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private var label: some View {
|
|
|
|
HStack(alignment: .top, spacing: 12) {
|
|
|
|
VStack {
|
2023-07-22 17:02:59 +00:00
|
|
|
ChannelAvatarView(channel: channel, subscribedBadge: false)
|
|
|
|
.id("channel-avatar-\(channel.id)")
|
2022-12-13 10:40:08 +00:00
|
|
|
#if os(tvOS)
|
|
|
|
.frame(width: 90, height: 90)
|
|
|
|
#else
|
|
|
|
.frame(width: 60, height: 60)
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
.frame(width: thumbnailWidth)
|
|
|
|
|
|
|
|
displayAuthor
|
|
|
|
.multilineTextAlignment(.leading)
|
|
|
|
}
|
|
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
|
|
#if os(tvOS)
|
|
|
|
.frame(minHeight: 120)
|
|
|
|
#else
|
|
|
|
.frame(minHeight: 60)
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
private var thumbnailWidth: Double {
|
|
|
|
#if os(tvOS)
|
|
|
|
250
|
|
|
|
#else
|
|
|
|
100
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ChannelListItem_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
|
|
|
ChannelListItem(channel: Video.fixture.channel)
|
|
|
|
}
|
|
|
|
}
|