TextureGroup / Texture

Smooth asynchronous user interfaces for iOS apps.
https://texturegroup.org/
Other
8.02k stars 1.29k forks source link

[ASTextNode] truncationAttributedText / additionalTruncationMessage don't always fit. #142

Open garrettmoon opened 7 years ago

garrettmoon commented 7 years ago

From @Yue-Wang-Google on August 25, 2016 20:5

Test case:

Apply the following patch to the Kittens example:

--- /Users/wangyue/Downloads/AsyncDisplayKit-master/examples/Kittens/Sample/KittenNode.mm   2016-08-25 10:03:06.000000000 -0700
+++ Sample/KittenNode.mm    2016-08-25 13:00:22.000000000 -0700
@@ -98,8 +98,12 @@

   // lorem ipsum text, plus some nice styling
   _textNode = [[ASTextNode alloc] init];
+  _textNode.truncationMode = NSLineBreakByTruncatingTail;
+  _textNode.maximumNumberOfLines = 2;
   _textNode.attributedString = [[NSAttributedString alloc] initWithString:[self kittyIpsum]
                                                                attributes:[self textStyle]];
+  _textNode.truncationAttributedText = [[NSAttributedString alloc] initWithString:@"\u2026 More"
+                                                                       attributes:[self textStyle]];
   [self addSubnode:_textNode];

   // hairline cell separator

See the first node in the following screenshot.

screen shot 2016-08-25 at 1 04 44 pm

Copied from original issue: facebookarchive/AsyncDisplayKit#2140

garrettmoon commented 7 years ago

From @Yue-Wang-Google on August 31, 2016 21:27

OK it seems ASDK calculate the truncation point either too early or too late. When using NSLineBreakByTruncatingTail, seems the line truncates too late. When using without, it happens too early. In a few cases two or three more words can be crammed to the last line, but ASDK just truncate a lot earlier.

garrettmoon commented 7 years ago

From @abbasmousavi on October 8, 2016 22:40

I have the same problem, It seems the line truncates too late, When using NSLineBreakByTruncatingTail and truncates too early when using NSLineBreakByWordWrapping.

Also when NSLineBreakByTruncatingTail breaks the line too late, it displays default truncate message instead of truncationAttributedText or additionalTruncationMessage.

Do you have any solution @Yue-Wang-Google ?

garrettmoon commented 7 years ago

From @abbasmousavi on October 23, 2016 20:0

@appleguy Could you please take a look at this issue?

garrettmoon commented 7 years ago

From @jdee on October 27, 2016 22:58

I'm also using .ByTruncatingTail. I'm adding an NSLinkAttributeName to the truncationAttributedText in order to get taps in textNodeTappedTruncationToken() in my delegate. It works perfectly if there are also linked URLs in the attributedText (with NSLinkAttributeNames). The token is consistently absent if there are no linked URLs in the attributedText. It just trails off with an ellipsis, not the specified truncationAttributedText, like the first cell in the image above.

garrettmoon commented 7 years ago

From @maicki on November 9, 2016 3:34

Related Issue: #1284

garrettmoon commented 7 years ago

@Adlai-Holler can you take a stab at figuring out if we can fix this in the 2.0 milestone?

nishu-priya commented 6 years ago

Any answer on it?? I am also facing this issue

nishu-priya commented 6 years ago

I am using trucationMode = .byWordWrapping in case I set truncationAttributedText, and to the surprise, its working perfectly