|
23 | 23 |
|
24 | 24 | #import "ASInternalHelpers.h"
|
25 | 25 | #import "ASEqualityHelpers.h"
|
| 26 | +#import "ASLayout.h" |
26 | 27 |
|
27 | 28 | static const NSTimeInterval ASTextNodeHighlightFadeOutDuration = 0.15;
|
28 | 29 | static const NSTimeInterval ASTextNodeHighlightFadeInDuration = 0.1;
|
@@ -290,7 +291,29 @@ - (void)_invalidateRendererIfNeeded:(CGSize)newSize
|
290 | 291 |
|
291 | 292 | - (BOOL)_needInvalidateRenderer:(CGSize)newSize
|
292 | 293 | {
|
293 |
| - return !CGSizeEqualToSize(newSize, _constrainedSize); |
| 294 | + if (!_renderer) { |
| 295 | + return YES; |
| 296 | + } |
| 297 | + |
| 298 | + // If the size is not the same as the constraint we provided to the renderer, start out assuming we need |
| 299 | + // a new one. However, there are common cases where the constrained size doesn't need to be the same as calculated. |
| 300 | + CGSize oldSize = _renderer.constrainedSize; |
| 301 | + |
| 302 | + if (CGSizeEqualToSize(newSize, oldSize)) { |
| 303 | + return NO; |
| 304 | + } else { |
| 305 | + // It is very common to have a constrainedSize with a concrete, specific width but +Inf height. |
| 306 | + // In this case, as long as the text node has bounds as large as the full calculatedLayout suggests, |
| 307 | + // it means that the text has all the room it needs (as it was not vertically bounded). So, we will not |
| 308 | + // experience truncation and don't need to recreate the renderer with the size it already calculated, |
| 309 | + // as this would essentially serve to set its constrainedSize to be its calculatedSize (unnecessary). |
| 310 | + ASLayout *layout = self.calculatedLayout; |
| 311 | + if (layout != nil && CGSizeEqualToSize(newSize, layout.size)) { |
| 312 | + return NO; |
| 313 | + } else { |
| 314 | + return YES; |
| 315 | + } |
| 316 | + } |
294 | 317 | }
|
295 | 318 |
|
296 | 319 | #pragma mark - Modifying User Text
|
|
0 commit comments