From 6f1d2d1f1d511217ff5f69f779166a9fc6c0c1d9 Mon Sep 17 00:00:00 2001 From: Adlai Holler Date: Fri, 9 Mar 2018 14:23:27 -0800 Subject: [PATCH] [ASTextNode] Fix locking, add test for issue #trivial (#825) * A few small fixes plus a failing test for ASTextNode * Change the approach * Update changelog * Eh screw null_resettable * No need for changelog now --- Source/ASTextNode.mm | 7 +++++++ Tests/ASTextNodeSnapshotTests.m | 17 +++++++++++++++++ ...nheritedFromTextWhenTruncateTailMode@2x.png | Bin 0 -> 2396 bytes 3 files changed, 24 insertions(+) create mode 100644 Tests/ReferenceImages_iOS_10/ASTextNodeSnapshotTests/testThatTruncationTokenAttributesPrecedeThoseInheritedFromTextWhenTruncateTailMode@2x.png diff --git a/Source/ASTextNode.mm b/Source/ASTextNode.mm index e2a594b05..522ebabed 100644 --- a/Source/ASTextNode.mm +++ b/Source/ASTextNode.mm @@ -177,6 +177,7 @@ @implementation ASTextNode { NSArray *_exclusionPaths; NSAttributedString *_attributedText; + NSAttributedString *_truncationAttributedText; NSAttributedString *_composedTruncationText; NSString *_highlightedLinkAttributeName; @@ -1189,6 +1190,12 @@ - (UIEdgeInsets)shadowPadding return defaultTruncationAttributedString; } +- (NSAttributedString *)truncationAttributedText +{ + ASDN::MutexLocker l(__instanceLock__); + return _truncationAttributedText; +} + - (void)setTruncationAttributedText:(NSAttributedString *)truncationAttributedText { { diff --git a/Tests/ASTextNodeSnapshotTests.m b/Tests/ASTextNodeSnapshotTests.m index 0d86a7274..c81f5241a 100644 --- a/Tests/ASTextNodeSnapshotTests.m +++ b/Tests/ASTextNodeSnapshotTests.m @@ -120,4 +120,21 @@ - (void)testShadowing ASSnapshotVerifyNode(textNode, nil); } +/** + * https://github.com/TextureGroup/Texture/issues/822 + */ +- (void)DISABLED_testThatTruncationTokenAttributesPrecedeThoseInheritedFromTextWhenTruncateTailMode +{ + ASTextNode *textNode = [[ASTextNode alloc] init]; + textNode.style.maxSize = CGSizeMake(20, 80); + NSMutableAttributedString *mas = [[NSMutableAttributedString alloc] initWithString:@"Quality is an important "]; + [mas appendAttributedString:[[NSAttributedString alloc] initWithString:@"thing" attributes:@{ NSBackgroundColorAttributeName : UIColor.yellowColor}]]; + textNode.attributedText = mas; + textNode.truncationMode = NSLineBreakByTruncatingTail; + + textNode.truncationAttributedText = [[NSAttributedString alloc] initWithString:@"\u2026" attributes:@{ NSBackgroundColorAttributeName: UIColor.greenColor }]; + ASDisplayNodeSizeToFitSizeRange(textNode, ASSizeRangeMake(CGSizeZero, CGSizeMake(INFINITY, INFINITY))); + ASSnapshotVerifyNode(textNode, nil); +} + @end diff --git a/Tests/ReferenceImages_iOS_10/ASTextNodeSnapshotTests/testThatTruncationTokenAttributesPrecedeThoseInheritedFromTextWhenTruncateTailMode@2x.png b/Tests/ReferenceImages_iOS_10/ASTextNodeSnapshotTests/testThatTruncationTokenAttributesPrecedeThoseInheritedFromTextWhenTruncateTailMode@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..40351ad62b1b5757f6367d86c7d3a20fa42f676d GIT binary patch literal 2396 zcmV-i38VIjP)z1^@s6*eVE!00001b5ch_0Itp) z=>Px#32;bRa{vGqB>(^xB>_oNB=7(L032yVPgDQ^00IC20000007U=*04M+e07U=* z07U=*1n#vhrDp&D1iDE?K~#7F?3rtbRaF>+l_?7F-s(vw*G&{4o`} zGZgBi`9_L+DmZst;M7#a#Mg#GoitxfvCjtQt_w8x52?_tp-?By&r{rr;5;D$-%5oZ z4Tah@_rl@#6nA5A9!sEKUwORJB6%_eei#b1YhDzJof@38fU-q$bcmS|V%jzrhQP~O zc%MlBYv3lr+4~3-vjw7Mfqt16?E*UTcqM@*dOHPg<#?DK1zW?p$-jpOQrq((i1rO9 z_Fot~Q~T~T=6Gd+3kdovB~V1MfcMXXY1{%5S1+fd_9A~B^8-bj&&den*vbM;<|W80 z+C)2G6FdfMVH@NE9@oJ%h;{=f*~hE$5V#2aN%VLATX1}j1QOSGIJ^w;)8>L6KZD!h z3-H{%V{t*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