Fix recycled ScrollView inheriting stale contentInset on iOS#56832
Open
cbrevik wants to merge 1 commit into
Open
Fix recycled ScrollView inheriting stale contentInset on iOS#56832cbrevik wants to merge 1 commit into
cbrevik wants to merge 1 commit into
Conversation
|
@javache has imported this pull request. If you are a Meta employee, you can view this in D105294296. |
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 #55090
In Fabric,
prepareForRecycleresets contentInset to zero when aScrollViewis recycled. But the subsequent frame reset dance (required forcontentInsetAdjustmentBehaviorsee 27fe6f1) triggerscenterContentIfNeededwith the previous component's stale content size, silently overwriting the reset.As a result, a
ScrollViewwithcenterContent={true}that is unmounted and replaced by anotherScrollViewleaves behind a stale contentInset that the new component inherits causing displaced content if the newScrollViewdoes not havecenterContent={true}.Two fixes:
RCTScrollViewComponentViewIn updateProps, when
centerContenttransitions from true to false, explicitly resetcontentInsetto the prop value.centerContentIfNeededwill not self-correct oncecenterContentis disabled on the new component, so the reset must be forced. The existingcontentInsetprop check is also guarded with !centerContent to prevent it from overriding the inset calculated by centerContentIfNeeded when centering is active.RCTEnhancedScrollViewOverride
setCenterContent:andsetContentSize:to triggercenterContentIfNeeded. This ensures centering is re-applied with the correct new content size when the new component's content arrives viaupdateState:, and that togglingcenterContenttakes effect immediately.Changelog:
[IOS] [FIXED] - Fix recycled ScrollView inheriting stale contentInset from centerContent on Fabric
Test Plan:
Using the RNTester-app, replace
CenterContentListwith the following insideScrollViewExample.js:CenterContentList reproducer
Doing two different ScrollViews to force an unmount of the one with centerContent so the other inherits its insetsBefore the fix
Note that for both
ScrollViews the content is centered, even though one hascenterContent={false}.before-the-fix.mov
After the fix
One is properly centered, while the other has its content at the top.
after-the-fix.mov