From 9e142a18dd6375f45d3fb4e8d767a1cbcfaa9567 Mon Sep 17 00:00:00 2001 From: Mengjue Wang Date: Fri, 15 Jul 2016 18:58:04 -0700 Subject: [PATCH] Provide RTL support for RCTShadowText Reviewed By: majak Differential Revision: D3524891 fbshipit-source-id: e67c35cc85b2764ab2eea3b14f7970afa06154b5 --- Libraries/Text/RCTShadowText.m | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Libraries/Text/RCTShadowText.m b/Libraries/Text/RCTShadowText.m index c111dbbd9bf..32e73997fac 100644 --- a/Libraries/Text/RCTShadowText.m +++ b/Libraries/Text/RCTShadowText.m @@ -372,6 +372,24 @@ static css_dim_t RCTMeasure(void *context, float width, css_measure_mode_t width } 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; }