mirror of
https://github.com/yattee/yattee.git
synced 2025-01-08 22:07:10 +00:00
jump to current chapter in horizontal view
This commit is contained in:
parent
7c50db426f
commit
ebc48fde90
@ -12,7 +12,10 @@ import SwiftUI
|
|||||||
var showThumbnail: Bool
|
var showThumbnail: Bool
|
||||||
|
|
||||||
var isCurrentChapter: Bool {
|
var isCurrentChapter: Bool {
|
||||||
player.currentChapterIndex == chapterIndex
|
if let currentChapterIndex = player.currentChapterIndex {
|
||||||
|
return currentChapterIndex == chapterIndex
|
||||||
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
|
@ -27,7 +27,22 @@ struct ChaptersView: View {
|
|||||||
.listStyle(.plain)
|
.listStyle(.plain)
|
||||||
#else
|
#else
|
||||||
ScrollView(.horizontal) {
|
ScrollView(.horizontal) {
|
||||||
LazyHStack(spacing: 20) { chapterViews(for: chapters[...]) }.padding(.horizontal, 15)
|
ScrollViewReader { scrollViewProxy in
|
||||||
|
LazyHStack(spacing: 20) {
|
||||||
|
chapterViews(for: chapters[...], scrollViewProxy: scrollViewProxy)
|
||||||
|
}
|
||||||
|
.padding(.horizontal, 15)
|
||||||
|
.onAppear {
|
||||||
|
if let currentChapterIndex = player.currentChapterIndex {
|
||||||
|
scrollViewProxy.scrollTo(currentChapterIndex, anchor: .center)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.onChange(of: player.currentChapterIndex) { currentChapterIndex in
|
||||||
|
if let index = currentChapterIndex {
|
||||||
|
scrollViewProxy.scrollTo(index, anchor: .center)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
} else if expand {
|
} else if expand {
|
||||||
@ -65,10 +80,11 @@ struct ChaptersView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if !os(tvOS)
|
#if !os(tvOS)
|
||||||
private func chapterViews(for chaptersToShow: ArraySlice<Chapter>, opacity: Double = 1.0, clickable: Bool = true) -> some View {
|
private func chapterViews(for chaptersToShow: ArraySlice<Chapter>, opacity: Double = 1.0, clickable: Bool = true, scrollViewProxy: ScrollViewProxy? = nil) -> some View {
|
||||||
ForEach(Array(chaptersToShow.indices), id: \.self) { index in
|
ForEach(Array(chaptersToShow.indices), id: \.self) { index in
|
||||||
let chapter = chaptersToShow[index]
|
let chapter = chaptersToShow[index]
|
||||||
ChapterView(chapter: chapter, chapterIndex: index, showThumbnail: showThumbnails)
|
ChapterView(chapter: chapter, chapterIndex: index, showThumbnail: showThumbnails)
|
||||||
|
.id(index)
|
||||||
.opacity(index == 0 ? 1.0 : opacity)
|
.opacity(index == 0 ? 1.0 : opacity)
|
||||||
.allowsHitTesting(clickable)
|
.allowsHitTesting(clickable)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user