Skip to content

Commit cb5302e

Browse files
committed
fix(ios): align text to the right by default in RTL
1 parent eb4d389 commit cb5302e

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

  • packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager

packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTAttributedTextUtils.mm

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@
1818

1919
using namespace facebook::react;
2020

21-
inline static TextAlignment RCTResolveTextAlignment(TextAlignment textAlignment, LayoutDirection layoutDirection)
21+
inline static TextAlignment RCTResolveTextAlignment(TextAlignment textAlignment, bool isRTL)
2222
{
23-
const bool isRTL = layoutDirection == LayoutDirection::RightToLeft;
2423
switch (textAlignment) {
24+
case TextAlignment::Natural:
25+
return isRTL ? TextAlignment::Right : TextAlignment::Left;
2526
case TextAlignment::Start:
2627
return isRTL ? TextAlignment::Right : TextAlignment::Left;
2728
case TextAlignment::End:
@@ -212,10 +213,10 @@ inline static CGFloat RCTEffectiveFontSizeMultiplierFromTextAttributes(const Tex
212213
// Paragraph Style
213214
NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle new];
214215
BOOL isParagraphStyleUsed = NO;
215-
if (textAttributes.alignment.has_value()) {
216-
TextAlignment textAlignment = RCTResolveTextAlignment(
217-
textAttributes.alignment.value_or(TextAlignment::Natural),
218-
textAttributes.layoutDirection.value_or(LayoutDirection::LeftToRight));
216+
const bool isRTL = textAttributes.layoutDirection == LayoutDirection::RightToLeft;
217+
if (textAttributes.alignment.has_value() || isRTL) {
218+
TextAlignment textAlignment =
219+
RCTResolveTextAlignment(textAttributes.alignment.value_or(TextAlignment::Natural), isRTL);
219220

220221
paragraphStyle.alignment = RCTNSTextAlignmentFromTextAlignment(textAlignment);
221222
isParagraphStyleUsed = YES;

0 commit comments

Comments
 (0)