From bbc957bce5801f32f794adcbae9866e2cfb06f0d Mon Sep 17 00:00:00 2001 From: Michael Schneider Date: Thu, 14 Jul 2016 14:38:57 -0700 Subject: [PATCH] Throw away all subcomponents of the text kit renderer if constraints are changing Throw away the all subcomponents to create them with the new constrained size new as well as let the truncater do it's job again for the new constrained size. This is necessary as after a truncation did happen the context would use the truncated string and not the original string to truncate based on the new constrained size --- AsyncDisplayKit/ASTextNode.mm | 7 +++++-- AsyncDisplayKit/TextKit/ASTextKitRenderer.mm | 16 ++++++++-------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/AsyncDisplayKit/ASTextNode.mm b/AsyncDisplayKit/ASTextNode.mm index 28fb35764a..a8c91761b8 100644 --- a/AsyncDisplayKit/ASTextNode.mm +++ b/AsyncDisplayKit/ASTextNode.mm @@ -326,8 +326,10 @@ static NSArray *DefaultLinkAttributeNames = @[ NSLinkAttributeName ]; if (layout != nil) { ASDN::MutexLocker l(_propertyLock); - _constrainedSize = layout.size; - _renderer.constrainedSize = layout.size; + if (CGSizeEqualToSize(_constrainedSize, layout.size) == NO) { + _constrainedSize = layout.size; + _renderer.constrainedSize = layout.size; + } } } @@ -397,6 +399,7 @@ static NSArray *DefaultLinkAttributeNames = @[ NSLinkAttributeName ]; // Tell the display node superclasses that the cached layout is incorrect now [self invalidateCalculatedLayout]; + // Force display to create renderer with new size and redisplay with new string [self setNeedsDisplay]; diff --git a/AsyncDisplayKit/TextKit/ASTextKitRenderer.mm b/AsyncDisplayKit/TextKit/ASTextKitRenderer.mm index 4cbb3552d7..020f825781 100755 --- a/AsyncDisplayKit/TextKit/ASTextKitRenderer.mm +++ b/AsyncDisplayKit/TextKit/ASTextKitRenderer.mm @@ -123,14 +123,14 @@ static NSCharacterSet *_defaultAvoidTruncationCharacterSet() if (!CGSizeEqualToSize(constrainedSize, _constrainedSize)) { _sizeIsCalculated = NO; _constrainedSize = constrainedSize; - // If the context isn't created yet, it will be initialized with the appropriate size when next accessed. - if (_context || _fontSizeAdjuster) { - // If we're updating an existing context, make sure to use the same inset logic used during initialization. - // This codepath allows us to reuse the - CGSize shadowConstrainedSize = [[self shadower] insetSizeWithConstrainedSize:constrainedSize]; - if (_context) _context.constrainedSize = shadowConstrainedSize; - if (_fontSizeAdjuster) _fontSizeAdjuster.constrainedSize = shadowConstrainedSize; - } + + // Throw away the all subcomponents to create them with the new constrained size new as well as let the + // truncater do it's job again for the new constrained size. This is necessary as after a truncation did happen + // the context would use the truncated string and not the original string to truncate based on the new + // constrained size + _context = nil; + _truncater = nil; + _fontSizeAdjuster = nil; } }