Skip to content

Commit

Permalink
Provide RTL support for RCTShadowText
Browse files Browse the repository at this point in the history
Reviewed By: majak

Differential Revision: D3524891

fbshipit-source-id: e67c35cc85b2764ab2eea3b14f7970afa06154b5
  • Loading branch information
MengjueW authored and Facebook Github Bot 6 committed Jul 16, 2016
1 parent 7aeaf7d commit 9e142a1
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Libraries/Text/RCTShadowText.m
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,24 @@ - (void)_setParagraphStyleOnAttributedString:(NSMutableAttributedString *)attrib
}

NSTextAlignment newTextAlign = _textAlign ?: NSTextAlignmentNatural;

// The part below is to address textAlign for RTL language before setting paragraph style
// Since we can't get layout directly because this logic is currently run just before layout is calculatede
// We will climb up to the first node which style has been setted as non-inherit
if (newTextAlign == NSTextAlignmentRight || newTextAlign == NSTextAlignmentLeft) {
RCTShadowView *view = self;
while (view != nil && view.cssNode->style.direction == CSS_DIRECTION_INHERIT) {
view = [view reactSuperview];
}
if (view != nil && view.cssNode->style.direction == CSS_DIRECTION_RTL) {
if (newTextAlign == NSTextAlignmentRight) {
newTextAlign = NSTextAlignmentLeft;
} else if (newTextAlign == NSTextAlignmentLeft) {
newTextAlign = NSTextAlignmentRight;
}
}
}

if (self.textAlign != newTextAlign) {
self.textAlign = newTextAlign;
}
Expand Down

0 comments on commit 9e142a1

Please sign in to comment.