Skip to content

Commit 6b7ef31

Browse files
benslimanhmeta-codesync[bot]
authored andcommitted
fix(iOS): correct RTL ScrollView offset on recycle in Fabric (#55804)
Summary: Fixes #55768 When a `ScrollView` is recycled in RTL mode, resetting `_scrollView.zoomScale = 1.0` inside `prepareForRecycle` causes UIKit to mutate `_containerView.frame`, pushing the content off-screen. Because the old `_contentSize` still matches the new `contentSize`, `updateState:` hits an early return optimization and fails to correct the mutated frame. This PR invalidates the cached `_contentSize` by setting it to `CGSizeZero` immediately after the `zoomScale` reset. This bypasses the early return and forces a correct recalculation of the frame. *Credit: Full credit to kligarski for debugging and pinpointing the exact mechanism in the original issue.* ## Changelog: [IOS] [FIXED] - Fixed RTL ScrollView offset bug upon recycling in Fabric Pull Request resolved: #55804 Test Plan: 1. Ran the reproducer app provided in issue #55768. 2. Verified that navigating (Push/Pop) multiple times with a `ScrollView` in an RTL layout no longer causes the content to offset to the left of the window. The ScrollView remains correctly positioned. Reviewed By: cipolleschi Differential Revision: D94682107 Pulled By: javache fbshipit-source-id: 3603824dcf37858f2924c9414a0ad4fcca2aea68
1 parent 0eb5e65 commit 6b7ef31

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

packages/react-native/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,9 @@ - (void)prepareForRecycle
684684
_scrollView.contentOffset = RCTCGPointFromPoint(props.contentOffset);
685685
// Reset zoom scale to default
686686
_scrollView.zoomScale = 1.0;
687+
// Invalidate cached content size so that updateState: recalculates the
688+
// container frame after zoomScale reset (which may have mutated it in RTL).
689+
_contentSize = CGSizeZero;
687690
// Reset contentInset to prevent stale insets leaking into recycled scroll views.
688691
_scrollView.contentInset = UIEdgeInsetsZero;
689692
// We set the default behavior to "never" so that iOS

0 commit comments

Comments
 (0)