mirror of
https://github.com/yattee/yattee.git
synced 2024-12-22 21:43:41 +00:00
fix regression and improve curentChapter handling
with #745 I left som testing changes in the PR that resulted in currentChapter index not being updated. This is fixed now. Also, the ScrollViewReader waiter 0.5s before jumping to the current Chapter. So it is always drawn correctly. Signed-off-by: Toni Förster <toni.foerster@gmail.com>
This commit is contained in:
parent
0b01adf6eb
commit
95d3170d31
@ -464,6 +464,8 @@ final class MPVBackend: PlayerBackend {
|
|||||||
timeObserverThrottle.execute {
|
timeObserverThrottle.execute {
|
||||||
self.model.updateWatch(time: self.currentTime)
|
self.model.updateWatch(time: self.currentTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.model.updateTime(self.currentTime!)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func stopClientUpdates() {
|
private func stopClientUpdates() {
|
||||||
|
@ -29,18 +29,14 @@ struct ChaptersView: View {
|
|||||||
ScrollView(.horizontal) {
|
ScrollView(.horizontal) {
|
||||||
ScrollViewReader { scrollViewProxy in
|
ScrollViewReader { scrollViewProxy in
|
||||||
LazyHStack(spacing: 20) {
|
LazyHStack(spacing: 20) {
|
||||||
chapterViews(for: chapters[...], scrollViewProxy: scrollViewProxy)
|
chapterViews(for: chapters[...])
|
||||||
}
|
}
|
||||||
.padding(.horizontal, 15)
|
.padding(.horizontal, 15)
|
||||||
.onAppear {
|
.onAppear {
|
||||||
if let currentChapterIndex = player.currentChapterIndex {
|
scrollToCurrentChapter(scrollViewProxy)
|
||||||
scrollViewProxy.scrollTo(currentChapterIndex, anchor: .center)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
.onChange(of: player.currentChapterIndex) { currentChapterIndex in
|
.onChange(of: player.currentChapterIndex) { _ in
|
||||||
if let index = currentChapterIndex {
|
scrollToCurrentChapter(scrollViewProxy)
|
||||||
scrollViewProxy.scrollTo(index, anchor: .center)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -53,7 +49,8 @@ struct ChaptersView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
Section { chapterViews(for: chapters[...]) }.padding(.horizontal)
|
Section { chapterViews(for: chapters[...]) }
|
||||||
|
.padding(.horizontal)
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
@ -80,7 +77,7 @@ struct ChaptersView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if !os(tvOS)
|
#if !os(tvOS)
|
||||||
private func chapterViews(for chaptersToShow: ArraySlice<Chapter>, opacity: Double = 1.0, clickable: Bool = true, scrollViewProxy _: ScrollViewProxy? = nil) -> some View {
|
private func chapterViews(for chaptersToShow: ArraySlice<Chapter>, opacity: Double = 1.0, clickable: Bool = true) -> 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)
|
||||||
@ -89,6 +86,14 @@ struct ChaptersView: View {
|
|||||||
.allowsHitTesting(clickable)
|
.allowsHitTesting(clickable)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func scrollToCurrentChapter(_ scrollViewProxy: ScrollViewProxy) {
|
||||||
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { // Slight delay to ensure the view is fully rendered
|
||||||
|
if let currentChapterIndex = player.currentChapterIndex {
|
||||||
|
scrollViewProxy.scrollTo(currentChapterIndex, anchor: .center)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user