Skip to content

Commit

Permalink
Address Kevin's comments
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenhuy committed Oct 11, 2018
1 parent 2daeff6 commit fbd6276
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions Source/ASTextNode2.mm
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,16 @@ - (CGSize)calculateSizeThatFits:(CGSize)constrainedSize
_textContainer.size = constrainedSize;
[self _ensureTruncationText];

// If constrained width is max/inf, the text node is calculating its intrinsic size.
const BOOL calculatingIntrinsicSize = (_textContainer.size.width >= ASTextContainerMaxSize.width);
// If the constrained size has max/inf value on the text's forward direction, the text node is calculating its intrinsic size.
BOOL isCalculatingIntrinsicSize;
if (_textContainer.isVerticalForm) {
isCalculatingIntrinsicSize = (_textContainer.size.height >= ASTextContainerMaxSize.height);
} else {
isCalculatingIntrinsicSize = (_textContainer.size.width >= ASTextContainerMaxSize.width);
}

NSMutableAttributedString *mutableText = [_attributedText mutableCopy];
[self prepareAttributedString:mutableText forIntrinsicSize:calculatingIntrinsicSize];
[self prepareAttributedString:mutableText isForIntrinsicSize:isCalculatingIntrinsicSize];
ASTextLayout *layout = [ASTextNode2 compatibleLayoutWithContainer:_textContainer text:mutableText];

return layout.textBoundingSize;
Expand Down Expand Up @@ -324,7 +329,7 @@ - (NSArray *)exclusionPaths
return _textContainer.exclusionPaths;
}

- (void)prepareAttributedString:(NSMutableAttributedString *)attributedString forIntrinsicSize:(BOOL)isForIntrinsicSize
- (void)prepareAttributedString:(NSMutableAttributedString *)attributedString isForIntrinsicSize:(BOOL)isForIntrinsicSize
{
ASLockScopeSelf();

Expand Down Expand Up @@ -381,7 +386,7 @@ - (NSObject *)drawParametersForAsyncLayer:(_ASDisplayLayer *)layer
[copiedContainer makeImmutable];
NSMutableAttributedString *mutableText = [_attributedText mutableCopy] ?: [[NSMutableAttributedString alloc] init];

[self prepareAttributedString:mutableText forIntrinsicSize:NO];
[self prepareAttributedString:mutableText isForIntrinsicSize:NO];

return @{
@"container": copiedContainer,
Expand Down

0 comments on commit fbd6276

Please sign in to comment.