Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions ios/sdk/WeexSDK/Sources/Component/WXTextComponent.m
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ @implementation WXTextComponent

BOOL _needsRemoveObserver;
NSAttributedString * _ctAttributedString;
NSString *_wordWrap;

pthread_mutex_t _ctAttributedStringMutex;
pthread_mutexattr_t _propertMutexAttr;
Expand Down Expand Up @@ -232,6 +233,7 @@ - (void)fillCSSStyles:(NSDictionary *)styles
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]),
Expand Down Expand Up @@ -442,8 +444,14 @@ - (NSMutableAttributedString *)buildCTAttributeString
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"])
Expand Down Expand Up @@ -563,7 +571,15 @@ - (NSTextStorage *)textStorageWithWidth:(CGFloat)width
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;
Expand Down