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 14:58:46 UTC

incubator-weex git commit: [WEEX-133][iOS] support word-wrap on iOS when drawing text

Repository: incubator-weex
Updated Branches:
  refs/heads/master 39704d41e -> 5a7b10d3a


[WEEX-133][iOS] support word-wrap on iOS when drawing text

 support word-wrap on text component, according to w3c rules, word-wrap
maybe normal or word-break value, and normal will just clip character, and
word break will break a new line.

w3c document: https://developer.mozilla.org/en-US/docs/Web/CSS/overflow-wrap

try case: http://dotwe.org/vue/5460408a9159fd13168f64bf0b046c4b

Bug:133


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

Branch: refs/heads/master
Commit: 5a7b10d3a93329638ba75a6b9cbab5dc85c32259
Parents: 39704d4
Author: acton393 <zh...@gmail.com>
Authored: Fri Nov 17 19:46:58 2017 +0800
Committer: gurisxie <27...@qq.com>
Committed: Mon Nov 20 22:54:57 2017 +0800

----------------------------------------------------------------------
 .../WeexSDK/Sources/Component/WXTextComponent.m | 22 +++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/5a7b10d3/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 2fbd925..e426a6bd 100644
--- a/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.m
+++ b/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.m
@@ -128,6 +128,7 @@ CGFloat WXTextDefaultLineThroughWidth = 1.2;
     
     BOOL _needsRemoveObserver;
     NSAttributedString * _ctAttributedString;
+    NSString *_wordWrap;
     
     pthread_mutex_t _ctAttributedStringMutex;
     pthread_mutexattr_t _propertMutexAttr;
@@ -232,6 +233,7 @@ do {\
     WX_STYLE_FILL_TEXT(textOverflow, textOverflow, NSString, NO)
     WX_STYLE_FILL_TEXT_PIXEL(lineHeight, lineHeight, YES)
     WX_STYLE_FILL_TEXT_PIXEL(letterSpacing, letterSpacing, YES)
+    WX_STYLE_FILL_TEXT(wordWrap, wordWrap, NSString, YES);
     
     UIEdgeInsets padding = {
         WXFloorPixelValue(self.cssNode->style.padding[CSS_TOP] + self.cssNode->style.border[CSS_TOP]),
@@ -442,8 +444,14 @@ do {\
         paragraphStyle.alignment = _textAlign;
     }
     
-    // set default lineBreakMode
-    paragraphStyle.lineBreakMode = NSLineBreakByCharWrapping;
+    if ([[_wordWrap lowercaseString] isEqualToString:@"break-word"]) {
+        paragraphStyle.lineBreakMode = NSLineBreakByWordWrapping;
+    } else if ([[_wordWrap lowercaseString] isEqualToString:@"normal"]){
+        paragraphStyle.lineBreakMode = NSLineBreakByClipping;
+    } else {
+         // set default lineBreakMode
+        paragraphStyle.lineBreakMode = NSLineBreakByCharWrapping;
+    }
     _truncationLine = NO;
     if (_textOverflow && [_textOverflow length] > 0) {
         if (_lines && [_textOverflow isEqualToString:@"ellipsis"])
@@ -563,7 +571,15 @@ do {\
     NSTextContainer *textContainer = [NSTextContainer new];
     textContainer.lineFragmentPadding = 0.0;
     
-    textContainer.lineBreakMode = NSLineBreakByClipping;
+    if ([[_wordWrap lowercaseString] isEqualToString:@"break-word"]) {
+        textContainer.lineBreakMode = NSLineBreakByWordWrapping;
+    } else if ([[_wordWrap lowercaseString] isEqualToString:@"normal"]){
+        textContainer.lineBreakMode = NSLineBreakByClipping;
+    } else {
+        // set default lineBreakMode
+        textContainer.lineBreakMode = NSLineBreakByCharWrapping;
+    }
+    
     if (_textOverflow && [_textOverflow length] > 0) {
         if ([_textOverflow isEqualToString:@"ellipsis"])
             textContainer.lineBreakMode = NSLineBreakByTruncatingTail;