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

* [ios] support max-width when drawing text #834

Merged
merged 7 commits into from
Nov 9, 2017
19 changes: 10 additions & 9 deletions ios/sdk/WeexSDK/Sources/Component/WXTextComponent.m
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,16 @@ - (UIImage *)drawRect:(CGRect)rect;
return ^CGSize (CGSize constrainedSize) {
CGSize computedSize = CGSizeZero;
NSTextStorage *textStorage = nil;

//TODO:more elegant way to use max and min constrained size
if (!isnan(weakSelf.cssNode->style.minDimensions[CSS_WIDTH])) {
constrainedSize.width = MAX(constrainedSize.width, weakSelf.cssNode->style.minDimensions[CSS_WIDTH]);
}

if (!isnan(weakSelf.cssNode->style.maxDimensions[CSS_WIDTH])) {
constrainedSize.width = MIN(constrainedSize.width, weakSelf.cssNode->style.maxDimensions[CSS_WIDTH]);
}

if (![self useCoreText]) {
textStorage = [weakSelf textStorageWithWidth:constrainedSize.width];
NSLayoutManager *layoutManager = textStorage.layoutManagers.firstObject;
Expand All @@ -325,15 +335,6 @@ - (UIImage *)drawRect:(CGRect)rect;
} else {
computedSize = [weakSelf calculateTextHeightWithWidth:constrainedSize.width];
}

//TODO:more elegant way to use max and min constrained size
if (!isnan(weakSelf.cssNode->style.minDimensions[CSS_WIDTH])) {
computedSize.width = MAX(computedSize.width, weakSelf.cssNode->style.minDimensions[CSS_WIDTH]);
}

if (!isnan(weakSelf.cssNode->style.maxDimensions[CSS_WIDTH])) {
computedSize.width = MIN(computedSize.width, weakSelf.cssNode->style.maxDimensions[CSS_WIDTH]);
}

if (!isnan(weakSelf.cssNode->style.minDimensions[CSS_HEIGHT])) {
computedSize.height = MAX(computedSize.height, weakSelf.cssNode->style.minDimensions[CSS_HEIGHT]);
Expand Down