Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 25 additions & 14 deletions AsyncDisplayKit/ASTextNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -223,25 +223,13 @@ - (void)didLoad
- (void)setFrame:(CGRect)frame
{
[super setFrame:frame];
if (!CGSizeEqualToSize(frame.size, _constrainedSize)) {
// Our bounds have changed to a size that is not identical to our constraining size,
// so our previous layout information is invalid, and TextKit may draw at the
// incorrect origin.
_constrainedSize = CGSizeMake(-INFINITY, -INFINITY);
[self _invalidateRenderer];
}
[self _invalidateRendererIfNeeded:frame.size];
}

- (void)setBounds:(CGRect)bounds
{
[super setBounds:bounds];
if (!CGSizeEqualToSize(bounds.size, _constrainedSize)) {
// Our bounds have changed to a size that is not identical to our constraining size,
// so our previous layout information is invalid, and TextKit may draw at the
// incorrect origin.
_constrainedSize = CGSizeMake(-INFINITY, -INFINITY);
[self _invalidateRenderer];
}
[self _invalidateRendererIfNeeded:bounds.size];
}

#pragma mark - Renderer Management
Expand Down Expand Up @@ -283,6 +271,27 @@ - (void)_invalidateRenderer
_renderer = nil;
}

- (void)_invalidateRendererIfNeeded
{
[self _invalidateRendererIfNeeded:self.bounds.size];
}

- (void)_invalidateRendererIfNeeded:(CGSize)newSize
{
if ([self _needInvalidateRenderer:newSize]) {
// Our bounds of frame have changed to a size that is not identical to our constraining size,
// so our previous layout information is invalid, and TextKit may draw at the
// incorrect origin.
_constrainedSize = CGSizeMake(-INFINITY, -INFINITY);
[self _invalidateRenderer];
}
}

- (BOOL)_needInvalidateRenderer:(CGSize)newSize
{
return !CGSizeEqualToSize(newSize, _constrainedSize);
}

#pragma mark - Modifying User Text

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

- (NSObject *)drawParametersForAsyncLayer:(_ASDisplayLayer *)layer
{
[self _invalidateRendererIfNeeded];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick question to help my understanding of this path. Is there ever a point when the backing view has not loaded here and doesn't need to be in order for the params to be generated? /cc @appleguy

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@levi Now I see that drawParametersForAsyncLayer: call takes place from _ASDisplayLayer::display method. And this call chain happens only when we have a layer or a view.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@soniccat is correct. Though it is something I would like to change in the future, for a variety of reasons, it will be a complex change, so I'm not worried about relying on this for now. My main concern is that this could introduce some other inefficiency or behavior change from what clients have relied on to date, but it may be safe.


// Offset the text origin by any shadow padding
UIEdgeInsets shadowPadding = [self shadowPadding];
CGPoint textOrigin = CGPointMake(self.bounds.origin.x - shadowPadding.left, self.bounds.origin.y - shadowPadding.top);
Expand Down