Skip to content

Add double scrollTo to fix List scroll restoration inconsistency #1548

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ struct List<Root: RootRegistry>: View {
}
}
}
.opacity((id == nil || didAttemptRestoration) ? 1 : 0) // prevent flickering when restoring
.task {
defer { didAttemptRestoration = true }

Expand All @@ -216,6 +217,12 @@ struct List<Root: RootRegistry>: View {
else { return }

scrollProxy.scrollTo(restoreID, anchor: .top)

// wait for the next runloop and try to scroll again
// it seems that the scroll won't work if the elements are not laid-out yet
try! await Task.sleep(for: .nanoseconds(0))

scrollProxy.scrollTo(restoreID, anchor: .top)
}
}
}
Expand Down
Loading