Skip to content

Commit 7380296

Browse files
committed
Merge pull request facebookarchive#877 from soniccat/master
[ASTextNode] Possible layout fix (fixes a case with Interface Builder initialization ordering)
2 parents 745f724 + ad28213 commit 7380296

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

AsyncDisplayKit/ASTextNode.mm

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -223,25 +223,13 @@ - (void)didLoad
223223
- (void)setFrame:(CGRect)frame
224224
{
225225
[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];
233227
}
234228

235229
- (void)setBounds:(CGRect)bounds
236230
{
237231
[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];
245233
}
246234

247235
#pragma mark - Renderer Management
@@ -283,6 +271,27 @@ - (void)_invalidateRenderer
283271
_renderer = nil;
284272
}
285273

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+
286295
#pragma mark - Modifying User Text
287296

288297
- (void)setAttributedString:(NSAttributedString *)attributedString {
@@ -377,6 +386,8 @@ + (void)drawRect:(CGRect)bounds withParameters:(ASTextNodeDrawParameters *)param
377386

378387
- (NSObject *)drawParametersForAsyncLayer:(_ASDisplayLayer *)layer
379388
{
389+
[self _invalidateRendererIfNeeded];
390+
380391
// Offset the text origin by any shadow padding
381392
UIEdgeInsets shadowPadding = [self shadowPadding];
382393
CGPoint textOrigin = CGPointMake(self.bounds.origin.x - shadowPadding.left, self.bounds.origin.y - shadowPadding.top);

0 commit comments

Comments
 (0)