yattee/Shared/Player/Video Details/ChaptersView.swift

68 lines
2.0 KiB
Swift
Raw Normal View History

import Foundation
import SDWebImageSwiftUI
import SwiftUI
struct ChaptersView: View {
@ObservedObject private var player = PlayerModel.shared
@Binding var expand: Bool
2023-04-22 18:06:30 +00:00
var chapters: [Chapter] {
player.videoForDisplay?.chapters ?? []
}
2023-04-24 10:08:58 +00:00
var chaptersHaveImages: Bool {
chapters.allSatisfy { $0.image != nil }
}
var body: some View {
if expand && !chapters.isEmpty {
2023-04-22 18:06:30 +00:00
#if os(tvOS)
List {
Section {
ForEach(chapters) { chapter in
ChapterView(chapter: chapter)
}
}
2023-04-22 18:06:30 +00:00
.listRowBackground(Color.clear)
}
2023-04-22 18:06:30 +00:00
.listStyle(.plain)
2022-06-24 23:39:29 +00:00
#else
2023-04-24 10:08:58 +00:00
if chaptersHaveImages {
ScrollView(.horizontal) {
LazyHStack(spacing: 20) {
ForEach(chapters) { chapter in
ChapterView(chapter: chapter)
}
}
.padding(.horizontal, 15)
}
.frame(minHeight: ChapterView.thumbnailHeight + 100)
} else {
Section {
2023-04-22 18:06:30 +00:00
ForEach(chapters) { chapter in
ChapterView(chapter: chapter)
}
}
2023-04-24 10:08:58 +00:00
.padding(.horizontal)
2023-04-22 18:06:30 +00:00
}
2022-06-24 23:39:29 +00:00
#endif
} else if !chapters.isEmpty {
Section {
ChapterView(chapter: chapters[0])
if chapters.count > 1 {
ChapterView(chapter: chapters[1])
.opacity(0.3)
}
}
.padding(.horizontal)
2022-06-24 23:39:29 +00:00
}
}
}
2022-08-20 21:05:40 +00:00
struct ChaptersView_Previews: PreviewProvider {
static var previews: some View {
ChaptersView(expand: .constant(false))
.injectFixtureEnvironmentObjects()
}
}