Skip to content

Commit bbc957b

Browse files
committed
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
1 parent f95790f commit bbc957b

2 files changed

Lines changed: 13 additions & 10 deletions

File tree

AsyncDisplayKit/ASTextNode.mm

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,10 @@ - (void)calculatedLayoutDidChange
326326

327327
if (layout != nil) {
328328
ASDN::MutexLocker l(_propertyLock);
329-
_constrainedSize = layout.size;
330-
_renderer.constrainedSize = layout.size;
329+
if (CGSizeEqualToSize(_constrainedSize, layout.size) == NO) {
330+
_constrainedSize = layout.size;
331+
_renderer.constrainedSize = layout.size;
332+
}
331333
}
332334
}
333335

@@ -397,6 +399,7 @@ - (void)setAttributedText:(NSAttributedString *)attributedText
397399
// Tell the display node superclasses that the cached layout is incorrect now
398400
[self invalidateCalculatedLayout];
399401

402+
// Force display to create renderer with new size and redisplay with new string
400403
[self setNeedsDisplay];
401404

402405

AsyncDisplayKit/TextKit/ASTextKitRenderer.mm

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,14 @@ - (void)setConstrainedSize:(CGSize)constrainedSize
123123
if (!CGSizeEqualToSize(constrainedSize, _constrainedSize)) {
124124
_sizeIsCalculated = NO;
125125
_constrainedSize = constrainedSize;
126-
// If the context isn't created yet, it will be initialized with the appropriate size when next accessed.
127-
if (_context || _fontSizeAdjuster) {
128-
// If we're updating an existing context, make sure to use the same inset logic used during initialization.
129-
// This codepath allows us to reuse the
130-
CGSize shadowConstrainedSize = [[self shadower] insetSizeWithConstrainedSize:constrainedSize];
131-
if (_context) _context.constrainedSize = shadowConstrainedSize;
132-
if (_fontSizeAdjuster) _fontSizeAdjuster.constrainedSize = shadowConstrainedSize;
133-
}
126+
127+
// Throw away the all subcomponents to create them with the new constrained size new as well as let the
128+
// truncater do it's job again for the new constrained size. This is necessary as after a truncation did happen
129+
// the context would use the truncated string and not the original string to truncate based on the new
130+
// constrained size
131+
_context = nil;
132+
_truncater = nil;
133+
_fontSizeAdjuster = nil;
134134
}
135135
}
136136

0 commit comments

Comments
 (0)