Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ASTextNode2] Fix truncation token is wrong after attributed string is changing with different foreground color #1550

Merged
merged 1 commit into from
Jul 2, 2019
Merged
Show file tree
Hide file tree
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
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.