iOS: optimize chapters list to render at current chapter instantly

- Added custom init to ChaptersListSheet that sets scrollPosition state before view appears
- Removed onAppear scroll position update (now set in init)
- List renders directly at current chapter position without any scroll animation
- Better performance for books with 1000+ chapters (no initial render + animate delay)
This commit is contained in:
Admin
2026-03-08 13:42:23 +05:00
parent 71ba882858
commit 24cb18e0fe

View File

@@ -759,6 +759,16 @@ struct ChaptersListSheet: View {
let onChapterSelect: (Int) -> Void
@Environment(\.dismiss) private var dismiss
// Initialize scroll position to current chapter immediately (before view appears)
init(chapters: [ChapterIndexBrief], currentChapter: Int, onChapterSelect: @escaping (Int) -> Void) {
self.chapters = chapters
self.currentChapter = currentChapter
self.onChapterSelect = onChapterSelect
// Set initial scroll position state before view renders
_scrollPosition = State(initialValue: currentChapter)
}
@State private var scrollPosition: Int?
var body: some View {
@@ -815,10 +825,6 @@ struct ChaptersListSheet: View {
}
.listStyle(.plain)
.scrollPosition(id: $scrollPosition, anchor: .center)
.onAppear {
// Set initial scroll position without animation
scrollPosition = currentChapter
}
.navigationTitle("Chapters")
.navigationBarTitleDisplayMode(.inline)
.toolbar {