Repository navigation
[iOS] Keep a ScrollView's overscroll when its frame changes during a drag - #60084
Open
jkasprzyk17 wants to merge 1 commit into
Open
jkasprzyk17 wants to merge 1 commit into
jkasprzyk17 wants to merge 1 commit into
Conversation
…n iOS When the frame of a ScrollView changed while a finger held its content past an edge, UIKit's -[UIScrollView setFrame:] clamped contentOffset to the new scrollable range, so the content snapped to the edge and the next pan update only restored about half of the pull. A content size change in the same situation already keeps the offset, as updateState: sets contentSize inside _preserveContentOffsetIfNeededWithBlock:. Resize the scroll view inside the same block, so a frame change during a user scroll keeps the offset too. Outside a user scroll the offset is clamped as before. Fixes react#59993
Visual regressionNo visual differences at android: no capture |
This branch has not been deployed
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 #59993.
On iOS (New Architecture), when a
ScrollView's frame changes while a finger holds its content past an edge, the content snaps to the edge. The next pan update restores only about half of the pull. In a layout that resizes the scroll view on every frame, for example one that follows the keyboard whilekeyboardDismissMode="interactive"drags it, the pull keeps falling behind the finger.The write comes from UIKit.
updateLayoutMetrics:sets the bounds ofRCTScrollViewComponentView. Autoresizing then sets the frame of the innerRCTEnhancedScrollView, and-[UIScrollView setFrame:]clampscontentOffsetto the new scrollable range. A content size change in the same situation already keeps the offset:updateState:setscontentSizeinside_preserveContentOffsetIfNeededWithBlock:, which "disables programmatical changing of ScrollView'scontentOffsetif a touch gesture is in progress".This change resizes the scroll view inside the same block. A frame change during a user scroll (drag and the deceleration after it) now keeps the offset, as a content size change does. Outside a user scroll, UIKit still clamps the offset as before.
Changelog:
[IOS] [FIXED] - ScrollView keeps its overscroll when its frame changes during a drag
Test Plan:
RNTester on an iOS 26.5 simulator (iPhone 17 Pro), New Architecture, Debug. The Playground ran the issue's reproducer (
605fc90): a footer under the list flips between 80 and 140 every second, which resizes theScrollView. I added an on-screen counter of "jumps", meaning an overscroll of more than 5 pt that becomes the edge in oneonScrollwhile the finger is down. The same gesture ran before and after: pull the list ~54 pt past its top and hold for ~5 s.onScrolllog (ms timestamp), before:After:
Regression checks, after the fix:
node scripts/clang-format.js --checkon the changed file passes.Videos, before and after (same gesture; the top line shows
y,jumpsandflips):Before:
59993-before.mp4
After:
59993-after.mp4
Not tested: a physical device, a real
keyboardDismissMode="interactive"keyboard flow, and the old architecture (the change is in the Fabric component view only).