Skip to content

fix: Handle offscreen scrollToLocation in SectionList scrollTo example#9716

Open
MatiPl01 wants to merge 1 commit into
mainfrom
@MatiPl01/fix-sectionlist-scrolltolocation
Open

fix: Handle offscreen scrollToLocation in SectionList scrollTo example#9716
MatiPl01 wants to merge 1 commit into
mainfrom
@MatiPl01/fix-sectionlist-scrolltolocation

Conversation

@MatiPl01

Copy link
Copy Markdown
Member

Description

The SectionList tab of the scrollTo example crashed with scrollToIndex should be used in conjunction with getItemLayout or onScrollToIndexFailed when "Scroll from JS" targeted a section/item outside the rendered window.

This is React Native's VirtualizedList contract for index-based scrolling to a row that has not been measured yet, not a Reanimated issue: a plain SectionList with a plain ref reproduces the identical crash (same invariant, same call stack), and it has been present since the example was added. Without getItemLayout or onScrollToIndexFailed, RN throws when the target index is beyond the highest measured cell.

This adds an onScrollToIndexFailed handler that scrolls to the approximate offset so the target row renders, then retries the precise scrollToLocation, so the scroll lands instead of throwing.

Test plan

Open the scrollTo example, select the SectionList tab, and press "Scroll from JS" repeatedly. It now scrolls to the target section instead of throwing the red box.

scrollToLocation to an unmeasured row throws React Native's scrollToIndex invariant when the list has no getItemLayout. Add an onScrollToIndexFailed handler that scrolls to the approximate offset and retries, so the scroll lands instead of crashing.
@MatiPl01 MatiPl01 self-assigned this Jun 20, 2026
@MatiPl01 MatiPl01 requested a review from tomekzaw June 22, 2026 11:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant