mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2026-01-06 13:12:49 +00:00
Factor in constrained size for final size calculation of ASTextNode (#2146)
This commit is contained in:
committed by
Adlai Holler
parent
9c3b688a87
commit
905508e9be
@@ -354,6 +354,7 @@ static NSArray *DefaultLinkAttributeNames = @[ NSLinkAttributeName ];
|
||||
if (layout != nil) {
|
||||
ASDN::MutexLocker l(__instanceLock__);
|
||||
CGSize layoutSize = layout.size;
|
||||
|
||||
//Apply textContainerInset
|
||||
layoutSize.width -= (_textContainerInset.left + _textContainerInset.right);
|
||||
layoutSize.height -= (_textContainerInset.top + _textContainerInset.bottom);
|
||||
@@ -367,12 +368,15 @@ static NSArray *DefaultLinkAttributeNames = @[ NSLinkAttributeName ];
|
||||
|
||||
- (CGSize)calculateSizeThatFits:(CGSize)constrainedSize
|
||||
{
|
||||
ASDN::MutexLocker l(__instanceLock__);
|
||||
|
||||
ASDisplayNodeAssert(constrainedSize.width >= 0, @"Constrained width for text (%f) is too narrow", constrainedSize.width);
|
||||
ASDisplayNodeAssert(constrainedSize.height >= 0, @"Constrained height for text (%f) is too short", constrainedSize.height);
|
||||
|
||||
ASDN::MutexLocker l(__instanceLock__);
|
||||
// Cache the original constrained size for final size calculateion
|
||||
CGSize originalConstrainedSize = constrainedSize;
|
||||
|
||||
//remove textContainerInset
|
||||
// Adjust constrainedSize for textContainerInset before assigning it
|
||||
constrainedSize.width -= (_textContainerInset.left + _textContainerInset.right);
|
||||
constrainedSize.height -= (_textContainerInset.top + _textContainerInset.bottom);
|
||||
|
||||
@@ -395,11 +399,12 @@ static NSArray *DefaultLinkAttributeNames = @[ NSLinkAttributeName ];
|
||||
}
|
||||
}
|
||||
|
||||
//add textContainerInset
|
||||
// Add the constrained size back textContainerInset
|
||||
size.width += (_textContainerInset.left + _textContainerInset.right);
|
||||
size.height += (_textContainerInset.top + _textContainerInset.bottom);
|
||||
|
||||
return size;
|
||||
return CGSizeMake(std::fmin(size.width, originalConstrainedSize.width),
|
||||
std::fmin(size.height, originalConstrainedSize.height));
|
||||
}
|
||||
|
||||
#pragma mark - Modifying User Text
|
||||
|
||||
@@ -31,6 +31,28 @@
|
||||
ASSnapshotVerifyNode(textNode, nil);
|
||||
}
|
||||
|
||||
- (void)testTextContainerInsetIsIncludedWithSmallerConstrainedSize
|
||||
{
|
||||
UIView *backgroundView = [[UIView alloc] initWithFrame:CGRectZero];
|
||||
backgroundView.layer.as_allowsHighlightDrawing = YES;
|
||||
|
||||
ASTextNode *textNode = [[ASTextNode alloc] init];
|
||||
textNode.attributedText = [[NSAttributedString alloc] initWithString:@"judar judar judar judar judar judar"
|
||||
attributes:@{ NSFontAttributeName : [UIFont systemFontOfSize:30] }];
|
||||
|
||||
[textNode measureWithSizeRange:ASSizeRangeMake(CGSizeZero, CGSizeMake(100, 80))];
|
||||
textNode.frame = CGRectMake(50, 50, textNode.calculatedSize.width, textNode.calculatedSize.height);
|
||||
textNode.textContainerInset = UIEdgeInsetsMake(10, 10, 10, 10);
|
||||
|
||||
[backgroundView addSubview:textNode.view];
|
||||
backgroundView.frame = UIEdgeInsetsInsetRect(textNode.bounds, UIEdgeInsetsMake(-50, -50, -50, -50));
|
||||
|
||||
textNode.highlightRange = NSMakeRange(0, textNode.attributedText.length);
|
||||
|
||||
[ASSnapshotTestCase hackilySynchronouslyRecursivelyRenderNode:textNode];
|
||||
FBSnapshotVerifyLayer(backgroundView.layer, nil);
|
||||
}
|
||||
|
||||
- (void)testTextContainerInsetHighlight
|
||||
{
|
||||
UIView *backgroundView = [[UIView alloc] initWithFrame:CGRectZero];
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 5.9 KiB |
Reference in New Issue
Block a user