diff --git a/Source/ASTextNode2.mm b/Source/ASTextNode2.mm index b49cde7a6..c4cf059a7 100644 --- a/Source/ASTextNode2.mm +++ b/Source/ASTextNode2.mm @@ -164,7 +164,6 @@ @implementation AS_TN2_CLASSNAME { NSAttributedString *_attributedText; NSAttributedString *_truncationAttributedText; NSAttributedString *_additionalTruncationMessage; - NSAttributedString *_composedTruncationText; NSArray *_pointSizeScaleFactors; NSLineBreakMode _truncationMode; @@ -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]; } /** diff --git a/Tests/ASTextNode2SnapshotTests.mm b/Tests/ASTextNode2SnapshotTests.mm index 9b48a82e4..76eaf77ad 100644 --- a/Tests/ASTextNode2SnapshotTests.mm +++ b/Tests/ASTextNode2SnapshotTests.mm @@ -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 diff --git a/Tests/ReferenceImages_iOS_10/ASTextNode2SnapshotTests/testThatDefaultTruncationTokenAttributesAreInheritedFromTextWhenTruncated_ASTextNode2@2x.png b/Tests/ReferenceImages_iOS_10/ASTextNode2SnapshotTests/testThatDefaultTruncationTokenAttributesAreInheritedFromTextWhenTruncated_ASTextNode2@2x.png new file mode 100644 index 000000000..18266450f Binary files /dev/null and b/Tests/ReferenceImages_iOS_10/ASTextNode2SnapshotTests/testThatDefaultTruncationTokenAttributesAreInheritedFromTextWhenTruncated_ASTextNode2@2x.png differ