Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ASDisplayNode] Stop infinite layout in _u_measureNodeWithBoundsIfNecessary #1434

Merged
merged 1 commit into from
Apr 1, 2019
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
10 changes: 10 additions & 0 deletions Source/ASDisplayNode+Layout.mm
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,16 @@ - (void)_u_measureNodeWithBoundsIfNecessary:(CGRect)bounds
__instanceLock__.lock();
}

// If we request that our root layout we may generate a new _pendingDisplayNodeLayout.layout which has
// requestedLayoutFromAbove set to NO. If the pending layout has a different constrained size than nextLayout's
// and the layout sizes don't change we could end up back here asking the root to layout again causing an
// infinite layout loop. Instead, we nil out the _pendingDisplayNodeLayout.layout here because it can be
// considered an undesired artifact of the layout request. nextLayout will become _calculatedDisplayNodeLayout
// when the pending layout transition which will be created later in this method is applied.
// We will use _calculatedLayout the next time around, so requestedLayoutFromAbove will be set to YES and we
Copy link
Member

@nguyenhuy nguyenhuy Mar 30, 2019

Choose a reason for hiding this comment

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

Suggested change
// We will use _calculatedLayout the next time around, so requestedLayoutFromAbove will be set to YES and we
// We will use _calculatedDisplayNodeLayout the next time around, so requestedLayoutFromAbove will be set to YES and we

// will break out of this layout loop.
_pendingDisplayNodeLayout.layout = nil;

// Update the layout's version here because _u_setNeedsLayoutFromAbove calls __setNeedsLayout which in turn increases _layoutVersion
// Failing to do this will cause the layout to be invalid immediately
nextLayout.version = _layoutVersion;
Expand Down