mirror of
https://github.com/yattee/yattee.git
synced 2024-11-10 08:18:19 +00:00
77 lines
2.3 KiB
Swift
77 lines
2.3 KiB
Swift
import Foundation
|
|
import SDWebImageSwiftUI
|
|
import SwiftUI
|
|
|
|
struct ChaptersView: View {
|
|
@ObservedObject private var player = PlayerModel.shared
|
|
@Binding var expand: Bool
|
|
|
|
var chapters: [Chapter] {
|
|
player.videoForDisplay?.chapters ?? []
|
|
}
|
|
|
|
var chaptersHaveImages: Bool {
|
|
chapters.allSatisfy { $0.image != nil }
|
|
}
|
|
|
|
var body: some View {
|
|
if !chapters.isEmpty {
|
|
if expand || chaptersHaveImages {
|
|
#if os(tvOS)
|
|
List {
|
|
Section {
|
|
ForEach(chapters) { chapter in
|
|
ChapterView(chapter: chapter)
|
|
}
|
|
}
|
|
.listRowBackground(Color.clear)
|
|
}
|
|
.listStyle(.plain)
|
|
#else
|
|
if chaptersHaveImages {
|
|
ScrollView(.horizontal) {
|
|
LazyHStack(spacing: 20) {
|
|
ForEach(chapters) { chapter in
|
|
ChapterView(chapter: chapter)
|
|
}
|
|
}
|
|
.padding(.horizontal, 15)
|
|
}
|
|
.frame(minHeight: ChapterView.thumbnailHeight + 100)
|
|
} else {
|
|
contents
|
|
}
|
|
#endif
|
|
} else {
|
|
#if os(iOS)
|
|
Button(action: {
|
|
self.expand.toggle()
|
|
}) {
|
|
contents
|
|
}
|
|
#else
|
|
contents
|
|
#endif
|
|
}
|
|
}
|
|
}
|
|
|
|
var contents: some View {
|
|
Section {
|
|
ForEach(chapters.prefix(3).indices, id: \.self) { index in
|
|
ChapterView(chapter: chapters[index])
|
|
.allowsHitTesting(expand)
|
|
.opacity(index == 0 ? 1.0 : 0.3)
|
|
}
|
|
}
|
|
.padding(.horizontal)
|
|
}
|
|
}
|
|
|
|
struct ChaptersView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
ChaptersView(expand: .constant(false))
|
|
.injectFixtureEnvironmentObjects()
|
|
}
|
|
}
|