You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by gu...@apache.org on 2017/11/20 15:16:20 UTC

incubator-weex git commit: [WEEX-132][iOS] support text writing direction from right to left

Repository: incubator-weex
Updated Branches:
  refs/heads/master 5a7b10d3a -> 564447f19


[WEEX-132][iOS] support text writing direction from right to left

 It is a common sense that people have different writing tradition, especially on
writing direction, so text component must consider about the writing direction,
if specify the direction in style is `rtl`, then the text writing direction will be right
to left and right aligned, 	`ltr` or doesn't specify any direction value, the direction
will be left to right default.

Bug: 132


Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/564447f1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/564447f1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/564447f1

Branch: refs/heads/master
Commit: 564447f191c28e5cba3b15040b888e6d143758be
Parents: 5a7b10d
Author: acton393 <zh...@gmail.com>
Authored: Fri Nov 17 18:03:58 2017 +0800
Committer: gurisxie <27...@qq.com>
Committed: Mon Nov 20 23:06:01 2017 +0800

----------------------------------------------------------------------
 .../WeexSDK/Sources/Component/WXTextComponent.m | 30 ++++++++++++++++++++
 1 file changed, 30 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/564447f1/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.m b/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.m
index e426a6bd..32828c3 100644
--- a/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.m
+++ b/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.m
@@ -120,6 +120,7 @@ CGFloat WXTextDefaultLineThroughWidth = 1.2;
     WXTextStyle _fontStyle;
     NSUInteger _lines;
     NSTextAlignment _textAlign;
+    NSString *_direction;
     WXTextDecoration _textDecoration;
     NSString *_textOverflow;
     CGFloat _lineHeight;
@@ -234,6 +235,7 @@ do {\
     WX_STYLE_FILL_TEXT_PIXEL(lineHeight, lineHeight, YES)
     WX_STYLE_FILL_TEXT_PIXEL(letterSpacing, letterSpacing, YES)
     WX_STYLE_FILL_TEXT(wordWrap, wordWrap, NSString, YES);
+    WX_STYLE_FILL_TEXT(direction, direction, NSString, YES)
     
     UIEdgeInsets padding = {
         WXFloorPixelValue(self.cssNode->style.padding[CSS_TOP] + self.cssNode->style.border[CSS_TOP]),
@@ -440,6 +442,20 @@ do {\
     
     NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle new];
     
+    // handle text direction style, default ltr
+    if ([_direction isEqualToString:@"rtl"]) {
+        if (0 == _textAlign) {
+            //force text right-align if don't specified any align.
+            _textAlign = NSTextAlignmentRight;
+        }
+        paragraphStyle.baseWritingDirection = NSWritingDirectionRightToLeft;
+    } else {
+        //if you specify NSWritingDirectionNaturalDirection, the receiver resolves the writing
+        //directionto eitherNSWritingDirectionLeftToRight or NSWritingDirectionRightToLeft,
+        //depending on the direction for the user’s language preference setting.
+        paragraphStyle.baseWritingDirection =  NSWritingDirectionNatural;
+    }
+    
     if (_textAlign) {
         paragraphStyle.alignment = _textAlign;
     }
@@ -521,6 +537,20 @@ do {\
     
     NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle new];
 
+    // handle text direction style, default ltr
+    if ([_direction isEqualToString:@"rtl"]) {
+        if (0 == _textAlign) {
+            //force text right-align if don't specified any align.
+            _textAlign = NSTextAlignmentRight;
+        }
+        paragraphStyle.baseWritingDirection = NSWritingDirectionRightToLeft;
+    } else {
+        //if you specify NSWritingDirectionNaturalDirection, the receiver resolves the writing
+        //directionto eitherNSWritingDirectionLeftToRight or NSWritingDirectionRightToLeft,
+        //depending on the direction for the user’s language preference setting.
+        paragraphStyle.baseWritingDirection =  NSWritingDirectionNatural;
+    }
+    
     if (_textAlign) {
         paragraphStyle.alignment = _textAlign;
     }