Fix one-frame jump after maintainVisibleContentPosition adjustment on Android - #58187
Open
Critteros wants to merge 1 commit into
Open
Fix one-frame jump after maintainVisibleContentPosition adjustment on Android#58187Critteros wants to merge 1 commit into
Critteros wants to merge 1 commit into
Conversation
Critteros
marked this pull request as ready for review
August 28, 2026 15:54
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.
Summary:
Fixes #58186.
On Android, a
ScrollViewwithmaintainVisibleContentPositionshows a one-frame jump when items are prepended. The visible rows move down by the height of the new item for one frame, then move back. In a chat app this happens on every incoming messageFabric moves the children and
MaintainVisibleScrollPositionHelpercorrects the scroll offset in the same UI thread pass. The moved children invalidate themselves, so the frame is drawn right away.View.scrollToonly posts an invalidation for the next frame. The current frame replays theScrollViewdisplay list with the previous offset, and the content is drawn shifted by the adjustmentThe bug needs two conditions. The anchor and the items move in one mount. Nothing in that mount changes the size of the content container, so no layout pass invalidates the
ScrollView. This is the case for lists that set the container height through anAnimated.Value, such as LegendListThis change invalidates the
ScrollViewright afterscrollToPreservingMomentuminMaintainVisibleScrollPositionHelper.updateScrollPositionInternal, so the display list is recorded again in the same frame.Changelog:
[ANDROID] [FIXED] - Fix one-frame content jump when maintainVisibleContentPosition adjusts the scroll offset during a mount
Test Plan:
Added
MaintainVisibleScrollPositionHelperTest. It builds the view tree from the reproduction with aReactScrollView, wiresmaintainVisibleContentPositionthroughsetMaintainVisibleContentPosition, and runs the two-mount prepend. It asserts that the scroll offset is corrected and that theScrollViewis flagged for display list recording (PFLAG_INVALIDATED) in the same mount../gradlew :packages:react-native:ReactAndroid:testDebugUnitTest --tests "com.facebook.react.views.scroll.MaintainVisibleScrollPositionHelperTest"Also tested in the reproduction app from #58186 (Expo SDK 57, React Native 0.86.3, LegendList with
maintainVisibleContentPosition):v0.86.3tag and cherry-picked this commit on top./gradlew publishAllToMavenTempLocal. This writesreact-android:0.86.3to/tmp/maven-localallprojects { repositories { mavenCentral() } }inandroid/build.gradle. This block runs before the React Native Gradle plugin adds its repositories, soreact.internal.mavenLocalRepoalone is not sufficient. The local repository must be the first entry in that block