fix: Handle offscreen scrollToLocation in SectionList scrollTo example#9716
Open
MatiPl01 wants to merge 1 commit into
Open
fix: Handle offscreen scrollToLocation in SectionList scrollTo example#9716MatiPl01 wants to merge 1 commit into
MatiPl01 wants to merge 1 commit into
Conversation
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.
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.
Description
The SectionList tab of the scrollTo example crashed with
scrollToIndex should be used in conjunction with getItemLayout or onScrollToIndexFailedwhen "Scroll from JS" targeted a section/item outside the rendered window.This is React Native's
VirtualizedListcontract for index-based scrolling to a row that has not been measured yet, not a Reanimated issue: a plainSectionListwith a plain ref reproduces the identical crash (same invariant, same call stack), and it has been present since the example was added. WithoutgetItemLayoutoronScrollToIndexFailed, RN throws when the target index is beyond the highest measured cell.This adds an
onScrollToIndexFailedhandler that scrolls to the approximate offset so the target row renders, then retries the precisescrollToLocation, 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.