ac84b22977
Opening a book chapter froze the app in an infinite render loop. Root
cause: the books screens used the eager `NavigationLink { destination }`
form inside `List`/`LazyVStack`. That form keeps the destination view
structurally parented to the source row, so `BookReaderView`'s ScrollView
got trapped inside a `List` row — a row sizes to intrinsic height, a
ScrollView has none, so the two never converge and re-measure forever.
Switch the whole books navigation chain to value-based navigation:
- practiceHomeView, BookLibraryView, BookChapterListView use
NavigationLink(value:).
- PracticeView's NavigationStack declares the BooksRoute, Book, and
BookChapter destinations once, at the stack root (mixing eager and
value-based pushes in one path caused pushed screens to pop back).
- BookReaderView is built from just a BookChapter; it resolves its Book
by slug via @Query.
Also:
- BookChapter gains a stored paragraphCount so the chapter list no longer
decodes the full paragraph JSON on every render (bookDataVersion -> 6
to re-seed).
- BookSpeechController builds its AVSpeechSynthesizer lazily.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
44 lines
1.4 KiB
Swift
44 lines
1.4 KiB
Swift
import SwiftUI
|
|
import SharedModels
|
|
import SwiftData
|
|
|
|
struct BookChapterListView: View {
|
|
let book: Book
|
|
|
|
@Query private var allChapters: [BookChapter]
|
|
|
|
init(book: Book) {
|
|
self.book = book
|
|
let slug = book.slug
|
|
_allChapters = Query(
|
|
filter: #Predicate<BookChapter> { $0.bookSlug == slug },
|
|
sort: \BookChapter.number
|
|
)
|
|
}
|
|
|
|
var body: some View {
|
|
List {
|
|
ForEach(allChapters) { chapter in
|
|
NavigationLink(value: chapter) {
|
|
HStack(spacing: 12) {
|
|
Text("\(chapter.number)")
|
|
.font(.subheadline.weight(.bold).monospacedDigit())
|
|
.foregroundStyle(.secondary)
|
|
.frame(width: 32, alignment: .trailing)
|
|
|
|
VStack(alignment: .leading, spacing: 2) {
|
|
Text(chapter.title)
|
|
.font(.subheadline.weight(.medium))
|
|
Text("\(chapter.paragraphCount) paragraph\(chapter.paragraphCount == 1 ? "" : "s")")
|
|
.font(.caption2)
|
|
.foregroundStyle(.tertiary)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
.navigationTitle(book.title.prefix(while: { $0 != ":" }).description)
|
|
.navigationBarTitleDisplayMode(.inline)
|
|
}
|
|
}
|