Repository navigation
Open a list or virtual list at a row with auto-scroll-to - #174
Open
wojt-janowski wants to merge 1 commit into
Open
wojt-janowski wants to merge 1 commit into
wojt-janowski wants to merge 1 commit into
Conversation
auto-scroll-to on native:list and native:virtual-list puts that row at the top when the list is created, for a relaunch, a deep link or a new record. It scrolls again only when the index changes, so re-renders don't pull the list away from where the reader scrolled. The request last applied is saved with the list, so a list restored by going back isn't moved either. Rows count as end-reached and visible-range count them. Works on iOS and Android. Amp-Thread-ID: https://ampcode.com/threads/T-01a1724b-7f88-71f2-a62f-4eae107d3dda Co-authored-by: Amp <amp@ampcode.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
An app can't choose where a list opens. A screen restored after a relaunch, a deep link to a record, or a list that should show the record just added all open at row 0, and
ScrollView::autoScrollTo()has no counterpart onnative:listornative:virtual-list.Change
auto-scroll-to(andautoScrollTo(int)) onnative:listandnative:virtual-list, named afterScrollView::autoScrollTo()and behaving like it:on-end-reachedandon-visible-rangecount them: from 0, with a section's rows in their place. On Android the row is mapped to its lazy item past section headers, gaps, footers, sticky headers and a pager header. On iOS the row is found by its node id throughScrollViewReader. A virtual list's slot id is its absolute index.rememberSaveable, so a list restored by going back isn't moved either. On iOS the modifier's@Statelives as long as the level does.For a virtual list the window has to hold the row. NativePHP/mobile-air#608 adds
HasVirtualListWindow::scrollVirtualListTo(), which moves the window and sets$virtualScrollTofor:auto-scroll-to. The prop itself doesn't depend on that PR: with an explicit window it works on its own. This PR doesn't restore positions on back. On Android that is NativePHP/mobile-air#588 (preserving native screen state); iOS's NavigationStack already keeps the level below alive.README and the Boost skill table document it.
Evidence
Firstlight showcase
main(33aa94b), pointed at this branch and a mobile-air branch that, when these were captured, also carried an Android state-restore change since dropped in favour of #588. Android emulator API 37.2, iOS Simulator iPhone 17 Pro on iOS 27.0. Posts is afirstlight:list(which renders with thisListRenderer) with:auto-scroll-to="8". Contacts is a 5,000-rownative:virtual-listwhosemount()callsscrollVirtualListTo(2500).Opens at the row on both platforms:
Doesn't fight the reader. After scrolling past the window, which triggers
on-window-changere-renders, the list stays where it was scrolled rather than jumping back to the row. The shots also open a contact and go back: on iOS that is stock behaviour; on Android the kept place came from the state-restore change, now #588's job, so read the Android "back" panel as needing #588. Posts behaves the same whileon-end-reachedloads page 2. Reopening Posts from Recipes opens at row 8 again.Tests: four new Pest cases in
ListTestandCollectorElementsTest. The suite passes (407) and Pint is clean.Not verified on a device: the animated re-scroll when PHP changes the index on a list that's already showing, horizontal lists, sectioned lists, lists under a pager header, and physical devices. I checked these index paths by reading the code, not by running them.
Reported from https://ampcode.com/threads/T-01a1717b-73af-7263-867e-a12595969c54