@@ -223,25 +223,13 @@ - (void)didLoad
223
223
- (void )setFrame : (CGRect)frame
224
224
{
225
225
[super setFrame: frame];
226
- if (!CGSizeEqualToSize (frame.size , _constrainedSize)) {
227
- // Our bounds have changed to a size that is not identical to our constraining size,
228
- // so our previous layout information is invalid, and TextKit may draw at the
229
- // incorrect origin.
230
- _constrainedSize = CGSizeMake (-INFINITY, -INFINITY);
231
- [self _invalidateRenderer ];
232
- }
226
+ [self _invalidateRendererIfNeeded: frame.size];
233
227
}
234
228
235
229
- (void )setBounds : (CGRect)bounds
236
230
{
237
231
[super setBounds: bounds];
238
- if (!CGSizeEqualToSize (bounds.size , _constrainedSize)) {
239
- // Our bounds have changed to a size that is not identical to our constraining size,
240
- // so our previous layout information is invalid, and TextKit may draw at the
241
- // incorrect origin.
242
- _constrainedSize = CGSizeMake (-INFINITY, -INFINITY);
243
- [self _invalidateRenderer ];
244
- }
232
+ [self _invalidateRendererIfNeeded: bounds.size];
245
233
}
246
234
247
235
#pragma mark - Renderer Management
@@ -283,6 +271,27 @@ - (void)_invalidateRenderer
283
271
_renderer = nil ;
284
272
}
285
273
274
+ - (void )_invalidateRendererIfNeeded
275
+ {
276
+ [self _invalidateRendererIfNeeded: self .bounds.size];
277
+ }
278
+
279
+ - (void )_invalidateRendererIfNeeded : (CGSize)newSize
280
+ {
281
+ if ([self _needInvalidateRenderer: newSize]) {
282
+ // Our bounds of frame have changed to a size that is not identical to our constraining size,
283
+ // so our previous layout information is invalid, and TextKit may draw at the
284
+ // incorrect origin.
285
+ _constrainedSize = CGSizeMake (-INFINITY, -INFINITY);
286
+ [self _invalidateRenderer ];
287
+ }
288
+ }
289
+
290
+ - (BOOL )_needInvalidateRenderer : (CGSize)newSize
291
+ {
292
+ return !CGSizeEqualToSize (newSize, _constrainedSize);
293
+ }
294
+
286
295
#pragma mark - Modifying User Text
287
296
288
297
- (void )setAttributedString : (NSAttributedString *)attributedString {
@@ -377,6 +386,8 @@ + (void)drawRect:(CGRect)bounds withParameters:(ASTextNodeDrawParameters *)param
377
386
378
387
- (NSObject *)drawParametersForAsyncLayer : (_ASDisplayLayer *)layer
379
388
{
389
+ [self _invalidateRendererIfNeeded ];
390
+
380
391
// Offset the text origin by any shadow padding
381
392
UIEdgeInsets shadowPadding = [self shadowPadding ];
382
393
CGPoint textOrigin = CGPointMake (self.bounds .origin .x - shadowPadding.left , self.bounds .origin .y - shadowPadding.top );
0 commit comments