Skip to content

Commit

Permalink
Fix truncation token is wrong after attributed string is changing wit…
Browse files Browse the repository at this point in the history
…h different foreground color
  • Loading branch information
maicki committed Jun 13, 2019
1 parent 2de8eec commit aad6e3f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 16 deletions.
29 changes: 13 additions & 16 deletions Source/ASTextNode2.mm
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ @implementation AS_TN2_CLASSNAME {
NSAttributedString *_attributedText;
NSAttributedString *_truncationAttributedText;
NSAttributedString *_additionalTruncationMessage;
NSAttributedString *_composedTruncationText;
NSArray<NSNumber *> *_pointSizeScaleFactors;
NSLineBreakMode _truncationMode;

Expand Down Expand Up @@ -1355,22 +1354,20 @@ - (NSRange)_additionalTruncationMessageRangeWithVisibleRange:(NSRange)visibleRan
- (NSAttributedString *)_locked_composedTruncationText
{
DISABLED_ASAssertLocked(__instanceLock__);
if (_composedTruncationText == nil) {
if (_truncationAttributedText != nil && _additionalTruncationMessage != nil) {
NSMutableAttributedString *newComposedTruncationString = [[NSMutableAttributedString alloc] initWithAttributedString:_truncationAttributedText];
[newComposedTruncationString.mutableString appendString:@" "];
[newComposedTruncationString appendAttributedString:_additionalTruncationMessage];
_composedTruncationText = newComposedTruncationString;
} else if (_truncationAttributedText != nil) {
_composedTruncationText = _truncationAttributedText;
} else if (_additionalTruncationMessage != nil) {
_composedTruncationText = _additionalTruncationMessage;
} else {
_composedTruncationText = DefaultTruncationAttributedString();
}
_composedTruncationText = [self _locked_prepareTruncationStringForDrawing:_composedTruncationText];
NSAttributedString *composedTruncationText = nil;
if (_truncationAttributedText != nil && _additionalTruncationMessage != nil) {
NSMutableAttributedString *newComposedTruncationString = [[NSMutableAttributedString alloc] initWithAttributedString:_truncationAttributedText];
[newComposedTruncationString.mutableString appendString:@" "];
[newComposedTruncationString appendAttributedString:_additionalTruncationMessage];
composedTruncationText = newComposedTruncationString;
} else if (_truncationAttributedText != nil) {
composedTruncationText = _truncationAttributedText;
} else if (_additionalTruncationMessage != nil) {
composedTruncationText = _additionalTruncationMessage;
} else {
composedTruncationText = DefaultTruncationAttributedString();
}
return _composedTruncationText;
return [self _locked_prepareTruncationStringForDrawing:composedTruncationText];
}

/**
Expand Down
19 changes: 19 additions & 0 deletions Tests/ASTextNode2SnapshotTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -298,4 +298,23 @@ - (void)DISABLED_testThatTruncationTokenAttributesPrecedeThoseInheritedFromTextW
ASSnapshotVerifyNode(textNode, nil);
}

- (void)testThatDefaultTruncationTokenAttributesAreInheritedFromTextWhenTruncated_ASTextNode2
{
ASTextNode *textNode = [[ASTextNode alloc] init];
textNode.style.maxSize = CGSizeMake(20, 80);

// Set initial attributed text
textNode.attributedText = [[NSMutableAttributedString alloc] initWithString:@"Quality is an important thing" attributes:@{NSForegroundColorAttributeName : [UIColor greenColor]}];

// Trigger sizing for internal composed truncation text creation
ASDisplayNodeSizeToFitSizeRange(textNode, ASSizeRangeMake(CGSizeZero, CGSizeMake(INFINITY, INFINITY)));

// Change attributed text with different foreground color
textNode.attributedText = [[NSAttributedString alloc] initWithString:@"Quality is an important thing" attributes:@{NSForegroundColorAttributeName : [UIColor grayColor]}];

// Size again and verify snapshot
ASDisplayNodeSizeToFitSizeRange(textNode, ASSizeRangeMake(CGSizeZero, CGSizeMake(INFINITY, INFINITY)));
ASSnapshotVerifyNode(textNode, nil);
}

@end
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit aad6e3f

Please sign in to comment.