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

[ios] fix text height problem in ios14 #3303

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
17 changes: 15 additions & 2 deletions ios/sdk/WeexSDK/Sources/Component/WXTextComponent.mm
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ - (CTLineRef)buildTruncatedLineWithRuns:(CFArrayRef)runs lines:(NSMutableArray*)
attrs = attrs ? attrs.mutableCopy : [NSMutableDictionary new];
CTFontRef font = (__bridge CTFontRef)(attrs[(id)kCTFontAttributeName]);
CGFloat fontSize = font ? CTFontGetSize(font):32 * self.weexInstance.pixelScaleFactor;
UIFont * uiFont = [UIFont systemFontOfSize:fontSize];
UIFont *uiFont = [WXUtility fontWithSize:fontSize textWeight:_fontWeight textStyle:WXTextStyleNormal fontFamily:self.fontFamily scaleFactor:self.weexInstance.pixelScaleFactor useCoreText:[self useCoreText]];
if (uiFont) {
font = CTFontCreateWithFontDescriptor((__bridge CTFontDescriptorRef)uiFont.fontDescriptor, uiFont.pointSize, NULL);
}
Expand Down Expand Up @@ -1079,6 +1079,8 @@ - (CGSize)calculateTextHeightWithWidth:(CGFloat)aWidth
CGFloat ascent = 0;
CGFloat descent = 0;
CGFloat leading = 0;
CGPoint lineOrigins[lineCount];
CTFrameGetLineOrigins(frameRef, CFRangeMake(0, 0), lineOrigins);

// height = ascent + descent + lineCount*leading
// ignore linespaing
Expand All @@ -1091,7 +1093,6 @@ - (CGSize)calculateTextHeightWithWidth:(CGFloat)aWidth
totalHeight += ascent + descent;
actualLineCount ++;
}

totalHeight = totalHeight + actualLineCount * leading;
CFRelease(frameRef);

Expand All @@ -1102,6 +1103,18 @@ - (CGSize)calculateTextHeightWithWidth:(CGFloat)aWidth
}
return CGSizeMake(aWidth, suggestSize.height);
}
if (WX_SYS_VERSION_GREATER_THAN_OR_EQUAL_TO(@"14.0")) {
if (lineCount <= 1) {
return CGSizeMake(aWidth, totalHeight);
}
if (_lines && lineCount > _lines) {
actualLineCount = _lines;
} else {
actualLineCount = lineCount;
}
CGFloat actualLineHeight = lineOrigins[0].y - lineOrigins[1].y;
return CGSizeMake(aWidth, actualLineCount * actualLineHeight);
}
return CGSizeMake(aWidth, totalHeight);
}

Expand Down