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:
97
Shared/Channels/ChannelListItem.swift
Normal file
97
Shared/Channels/ChannelListItem.swift
Normal file
@@ -0,0 +1,97 @@
|
||||
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 {
|
||||
ChannelAvatarView(channel: channel)
|
||||
#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)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user