From 1b92b02f99a3513a3ebe1526b090da9075b563ad Mon Sep 17 00:00:00 2001 From: Mathieu Acthernoene Date: Wed, 22 Jul 2026 13:07:59 -0700 Subject: [PATCH] fix(ios): align text to the right by default in RTL (#57634) Summary: On the new architecture, `` without an explicit `textAlign` behaves differently across platforms when the layout direction is RTL: - **Android**: text aligns to the right (follows the layout direction). - **iOS**: text stays left-aligned (ignores the layout direction). This is a regression from the old architecture, where both platforms left text alone when `textAlign` was unset. The new arch changed Android's default, and the two platforms are now inconsistent. This PR makes iOS match the current Android (new arch) behavior: without an explicit `textAlign`, text follows the layout direction and aligns to the right in RTL. On iOS, `Natural` alignment now resolves to `Right` under RTL. ### Open question I aligned iOS to Android's new default, but I'm not sure it's the right call (my guts feeling think that is the right thing to do, tho). The old-arch behavior (do nothing when `textAlign` is unset) may be what's actually expected, in which case the fix should go the other way: revert Android to leave text untouched and keep iOS as-is. Happy to flip the direction if reviewers prefer that. ## Changelog: [IOS] [FIXED] - Align text to the right by default in RTL when `textAlign` is not set, matching Android Pull Request resolved: https://github.com/react/react-native/pull/57634 Test Plan: Edit `RNTesterAppShared.js`, press the button, reload the app - comment / uncomment `Text` `textAlign` style: ```js /** * flow * format */ import { I18nManager, SafeAreaView, StyleSheet, Text, TouchableOpacity, View, } from 'react-native'; I18nManager.allowRTL(true); I18nManager.swapLeftAndRightInRTL(true); export default function App(): React.Node { const isRTL = I18nManager.isRTL; return ( I18nManager.isRTL: {String(isRTL)} I18nManager.forceRTL(!isRTL)} style={styles.button}> Toggle RTL + reload manually 1 2 3 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. ); } const styles = StyleSheet.create({ wrapper: { backgroundColor: 'white', flex: 1, }, content: { gap: 20, marginHorizontal: 20, }, info: { fontSize: 18, fontWeight: 'bold', }, button: { backgroundColor: '#007AFF', padding: 15, borderRadius: 8, }, buttonText: { color: 'white', textAlign: 'center', fontWeight: '600', }, row: { flexDirection: 'row', justifyContent: 'space-around', }, box: { width: 60, height: 60, alignItems: 'center', justifyContent: 'center', borderRadius: 8, }, boxText: { color: 'white', fontSize: 18, fontWeight: 'bold', }, }); ``` **Old architecture (baseline):** | Android | iOS | | --- | --- | | android - old arch | ios - old arch | **New architecture (before this PR, iOS diverges):** | Android | iOS | | --- | --- | | android - new arch | ios - new arch - not fixed | **New architecture (after this PR, iOS fixed):** | Android | iOS | | --- | --- | | android - new arch | ios - new arch - fixed | Reviewed By: javache Differential Revision: D113244783 Pulled By: Abbondanzo fbshipit-source-id: 75edbc2a2a2e1567de12c83375272672cc2683e9 --- .../textlayoutmanager/RCTAttributedTextUtils.mm | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTAttributedTextUtils.mm b/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTAttributedTextUtils.mm index 9e1b3e6dde8..3f55678f65c 100644 --- a/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTAttributedTextUtils.mm +++ b/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTAttributedTextUtils.mm @@ -18,10 +18,11 @@ using namespace facebook::react; -inline static TextAlignment RCTResolveTextAlignment(TextAlignment textAlignment, LayoutDirection layoutDirection) +inline static TextAlignment RCTResolveTextAlignment(TextAlignment textAlignment, bool isRTL) { - const bool isRTL = layoutDirection == LayoutDirection::RightToLeft; switch (textAlignment) { + case TextAlignment::Natural: + return isRTL ? TextAlignment::Right : TextAlignment::Left; case TextAlignment::Start: return isRTL ? TextAlignment::Right : TextAlignment::Left; case TextAlignment::End: @@ -212,10 +213,10 @@ NSMutableDictionary *RCTNSTextAttributesFromTextAttri // Paragraph Style NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle new]; BOOL isParagraphStyleUsed = NO; - if (textAttributes.alignment.has_value()) { - TextAlignment textAlignment = RCTResolveTextAlignment( - textAttributes.alignment.value_or(TextAlignment::Natural), - textAttributes.layoutDirection.value_or(LayoutDirection::LeftToRight)); + const bool isRTL = textAttributes.layoutDirection == LayoutDirection::RightToLeft; + if (textAttributes.alignment.has_value() || isRTL) { + TextAlignment textAlignment = + RCTResolveTextAlignment(textAttributes.alignment.value_or(TextAlignment::Natural), isRTL); paragraphStyle.alignment = RCTNSTextAlignmentFromTextAlignment(textAlignment); isParagraphStyleUsed = YES;