highlight current chapter

This commit is contained in:
Toni Förster
2023-11-28 16:45:36 +01:00
parent fb5cd0f681
commit 4ec6f35c5d
3 changed files with 40 additions and 10 deletions

View File

@@ -30,8 +30,10 @@ struct ChaptersView: View {
#else
ScrollView(.horizontal) {
LazyHStack(spacing: 20) {
ForEach(chapters) { chapter in
ChapterView(chapter: chapter)
ForEach(Array(chapters.indices), id: \.self) { index in
let chapter = chapters[index]
let nextChapterStart: Double? = index < chapters.count - 1 ? chapters[index + 1].start : nil
ChapterView(chapter: chapter, nextChapterStart: nextChapterStart, chapterIndex: index)
}
}
.padding(.horizontal, 15)
@@ -39,8 +41,10 @@ struct ChaptersView: View {
#endif
} else if expand {
Section {
ForEach(chapters) { chapter in
ChapterView(chapter: chapter)
ForEach(Array(chapters.indices), id: \.self) { index in
let chapter = chapters[index]
let nextChapterStart: Double? = index < chapters.count - 1 ? chapters[index + 1].start : nil
ChapterView(chapter: chapter, nextChapterStart: nextChapterStart, chapterIndex: index)
}
}
.padding(.horizontal)
@@ -60,8 +64,10 @@ struct ChaptersView: View {
var contents: some View {
Section {
ForEach(chapters.prefix(3).indices, id: \.self) { index in
ChapterView(chapter: chapters[index])
ForEach(Array(chapters.prefix(3).indices), id: \.self) { index in
let chapter = chapters[index]
let nextChapterStart: Double? = index < chapters.count - 1 ? chapters[index + 1].start : nil
ChapterView(chapter: chapter, nextChapterStart: nextChapterStart, chapterIndex: index)
.allowsHitTesting(expand)
.opacity(index == 0 ? 1.0 : 0.3)
}