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:
@@ -759,6 +759,16 @@ struct ChaptersListSheet: View {
|
|||||||
let onChapterSelect: (Int) -> Void
|
let onChapterSelect: (Int) -> Void
|
||||||
|
|
||||||
@Environment(\.dismiss) private var dismiss
|
@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?
|
@State private var scrollPosition: Int?
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
@@ -815,10 +825,6 @@ struct ChaptersListSheet: View {
|
|||||||
}
|
}
|
||||||
.listStyle(.plain)
|
.listStyle(.plain)
|
||||||
.scrollPosition(id: $scrollPosition, anchor: .center)
|
.scrollPosition(id: $scrollPosition, anchor: .center)
|
||||||
.onAppear {
|
|
||||||
// Set initial scroll position without animation
|
|
||||||
scrollPosition = currentChapter
|
|
||||||
}
|
|
||||||
.navigationTitle("Chapters")
|
.navigationTitle("Chapters")
|
||||||
.navigationBarTitleDisplayMode(.inline)
|
.navigationBarTitleDisplayMode(.inline)
|
||||||
.toolbar {
|
.toolbar {
|
||||||
|
|||||||
Reference in New Issue
Block a user