diff --git a/Libraries/Text/RCTShadowText.m b/Libraries/Text/RCTShadowText.m index 00770dea9..fe2b03772 100644 --- a/Libraries/Text/RCTShadowText.m +++ b/Libraries/Text/RCTShadowText.m @@ -38,7 +38,7 @@ static CGFloat const kAutoSizeGranularity = 0.001f; CGFloat _cachedTextStorageWidthMode; NSAttributedString *_cachedAttributedString; CGFloat _effectiveLetterSpacing; - UIUserInterfaceLayoutDirection _cachedEffectiveLayoutDirection; + UIUserInterfaceLayoutDirection _cachedLayoutDirection; } static YGSize RCTMeasure(YGNodeRef node, float width, YGMeasureMode widthMode, float height, YGMeasureMode heightMode) @@ -72,7 +72,7 @@ static YGSize RCTMeasure(YGNodeRef node, float width, YGMeasureMode widthMode, f _fontSizeMultiplier = 1.0; _textAlign = NSTextAlignmentNatural; _writingDirection = NSWritingDirectionNatural; - _cachedEffectiveLayoutDirection = UIUserInterfaceLayoutDirectionLeftToRight; + _cachedLayoutDirection = UIUserInterfaceLayoutDirectionLeftToRight; YGNodeSetMeasureFunc(self.yogaNode, RCTMeasure); @@ -198,7 +198,7 @@ static YGSize RCTMeasure(YGNodeRef node, float width, YGMeasureMode widthMode, f _cachedTextStorage && (width == _cachedTextStorageWidth || (isnan(width) && isnan(_cachedTextStorageWidth))) && widthMode == _cachedTextStorageWidthMode && - _cachedEffectiveLayoutDirection == self.effectiveLayoutDirection + _cachedLayoutDirection == self.layoutDirection ) { return _cachedTextStorage; } @@ -272,12 +272,12 @@ static YGSize RCTMeasure(YGNodeRef node, float width, YGMeasureMode widthMode, f if ( ![self isTextDirty] && _cachedAttributedString && - _cachedEffectiveLayoutDirection == self.effectiveLayoutDirection + _cachedLayoutDirection == self.layoutDirection ) { return _cachedAttributedString; } - _cachedEffectiveLayoutDirection = self.effectiveLayoutDirection; + _cachedLayoutDirection = self.layoutDirection; if (_fontSize && !isnan(_fontSize)) { fontSize = @(_fontSize); @@ -419,7 +419,7 @@ static YGSize RCTMeasure(YGNodeRef node, float width, YGMeasureMode widthMode, f // Text alignment NSTextAlignment textAlign = _textAlign; if (textAlign == NSTextAlignmentRight || textAlign == NSTextAlignmentLeft) { - if (_cachedEffectiveLayoutDirection == UIUserInterfaceLayoutDirectionRightToLeft) { + if (_cachedLayoutDirection == UIUserInterfaceLayoutDirectionRightToLeft) { if (textAlign == NSTextAlignmentRight) { textAlign = NSTextAlignmentLeft; } else { diff --git a/RNTester/js/TextExample.ios.js b/RNTester/js/TextExample.ios.js index 5e5cee093..1980ced73 100644 --- a/RNTester/js/TextExample.ios.js +++ b/RNTester/js/TextExample.ios.js @@ -15,13 +15,56 @@ const Platform = require('Platform'); var React = require('react'); var createReactClass = require('create-react-class'); var ReactNative = require('react-native'); -var { - Image, - StyleSheet, - Text, - View, - LayoutAnimation, -} = ReactNative; +var {Image, Text, View, LayoutAnimation, Button} = ReactNative; + +type TextAlignExampleRTLState = {| + isRTL: boolean, +|}; + +class TextAlignRTLExample extends React.Component<*, TextAlignExampleRTLState> { + constructor(...args: Array<*>) { + super(...args); + + this.state = { + isRTL: false, + }; + } + + render() { + const {isRTL} = this.state; + const toggleRTL = () => this.setState({isRTL: !isRTL}); + return ( + + auto (default) - english LTR + + {'\u0623\u062D\u0628 \u0627\u0644\u0644\u063A\u0629 ' + + '\u0627\u0644\u0639\u0631\u0628\u064A\u0629 auto (default) - arabic RTL'} + + + left left left left left left left left left left left left left left + left + + + center center center center center center center center center center + center + + + right right right right right right right right right right right + right right + + + justify: this text component{"'"}s contents are laid out with + "textAlign: justify" and as you can see all of the lines except the + last one span the available width of the parent container. + +