Skip to content

Commit e29461d

Browse files
committed
Mirror only horizontal ScrollViews in RTL on iOS
In RTL, RCTScrollViewComponentView mirrored every scroll view. A vertical one gains nothing from it, and UIKit's views added to the scroll view outside the content view were left mirrored: on iOS 26 the navigation bar's large title is one of them, so it showed up mirrored at the left edge.
1 parent 32e6daa commit e29461d

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,11 +309,18 @@ - (void)updateLayoutMetrics:(const LayoutMetrics &)layoutMetrics
309309
oldLayoutMetrics:(const LayoutMetrics &)oldLayoutMetrics
310310
{
311311
[super updateLayoutMetrics:layoutMetrics oldLayoutMetrics:oldLayoutMetrics];
312-
if (layoutMetrics.layoutDirection != oldLayoutMetrics.layoutDirection) {
313-
CGAffineTransform transform = (layoutMetrics.layoutDirection == LayoutDirection::LeftToRight)
314-
? CGAffineTransformIdentity
315-
: CGAffineTransformMakeScale(-1, 1);
312+
[self _updateRightToLeftTransform];
313+
}
316314
315+
// In RTL, a horizontal scroll view is mirrored (with its content view mirrored back) so it starts at the right edge.
316+
// A vertical one is left as is: mirroring it also mirrors the views UIKit adds to the scroll view outside the
317+
// content view, such as the navigation bar's large title on iOS 26.
318+
- (void)_updateRightToLeftTransform
319+
{
320+
const auto &scrollViewProps = static_cast<const ScrollViewProps &>(*_props);
321+
BOOL mirrored = _layoutMetrics.layoutDirection == LayoutDirection::RightToLeft && scrollViewProps.horizontal;
322+
CGAffineTransform transform = mirrored ? CGAffineTransformMakeScale(-1, 1) : CGAffineTransformIdentity;
323+
if (!CGAffineTransformEqualToTransform(_scrollView.transform, transform)) {
317324
_containerView.transform = transform;
318325
_scrollView.transform = transform;
319326
}
@@ -463,6 +470,7 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &
463470
}
464471
465472
[super updateProps:props oldProps:oldProps];
473+
[self _updateRightToLeftTransform];
466474
467475
// Must run after `super updateProps:` so it is based on the latest calculated view.
468476
((RCTEnhancedScrollView *)_scrollView).inverted = [self isInverted];

0 commit comments

Comments
 (0)