41 lines
1.4 KiB
Swift
41 lines
1.4 KiB
Swift
import SwiftUI
|
|
|
|
struct EpisodeListView: View {
|
|
let episodes: [Episode]
|
|
let selectedIndex: Int
|
|
let onSelect: (Int) -> Void
|
|
|
|
private let columns = [
|
|
GridItem(.adaptive(minimum: 70, maximum: 100), spacing: 8)
|
|
]
|
|
|
|
var body: some View {
|
|
VStack(alignment: .leading, spacing: 8) {
|
|
Text("选集 (\(episodes.count)集)")
|
|
.font(.headline)
|
|
|
|
LazyVGrid(columns: columns, spacing: 8) {
|
|
ForEach(Array(episodes.enumerated()), id: \.element.id) { index, episode in
|
|
Button {
|
|
onSelect(index)
|
|
} label: {
|
|
Text(episode.name)
|
|
.font(.caption)
|
|
.lineLimit(1)
|
|
.frame(maxWidth: .infinity)
|
|
.padding(.vertical, 8)
|
|
.background(
|
|
selectedIndex == index
|
|
? Color.accentColor
|
|
: Color.secondary.opacity(0.12),
|
|
in: RoundedRectangle(cornerRadius: 6)
|
|
)
|
|
.foregroundStyle(selectedIndex == index ? .white : .primary)
|
|
}
|
|
.buttonStyle(.plain)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|