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

Clean up timing of layout tree flattening/ copying of unflattened tree for Weaver #1157

Merged
merged 6 commits into from
Oct 3, 2018
Merged
Show file tree
Hide file tree
Changes from 4 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
12 changes: 0 additions & 12 deletions Source/ASDisplayNode+Layout.mm
Original file line number Diff line number Diff line change
Expand Up @@ -993,12 +993,6 @@ - (void)_pendingLayoutTransitionDidComplete
_pendingLayoutTransition = nil;
}

- (void)_setCalculatedDisplayNodeLayout:(const ASDisplayNodeLayout &)displayNodeLayout
Copy link
Member

@nguyenhuy nguyenhuy Oct 2, 2018

Choose a reason for hiding this comment

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

For the record, this method is not called anywhere.

{
ASDN::MutexLocker l(__instanceLock__);
[self _locked_setCalculatedDisplayNodeLayout:displayNodeLayout];
}

- (void)_locked_setCalculatedDisplayNodeLayout:(const ASDisplayNodeLayout &)displayNodeLayout
{
ASAssertLocked(__instanceLock__);
Expand All @@ -1007,12 +1001,6 @@ - (void)_locked_setCalculatedDisplayNodeLayout:(const ASDisplayNodeLayout &)disp
ASDisplayNodeAssertTrue(displayNodeLayout.layout.size.height >= 0.0);

_calculatedDisplayNodeLayout = displayNodeLayout;

// Flatten the layout if it wasn't done before (@see -calculateLayoutThatFits:).
if ([ASDisplayNode shouldStoreUnflattenedLayouts]) {
_unflattenedLayout = _calculatedDisplayNodeLayout.layout;
_calculatedDisplayNodeLayout.layout = [_unflattenedLayout filteredNodeLayoutTree];
}
}

@end
7 changes: 3 additions & 4 deletions Source/ASDisplayNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1220,11 +1220,10 @@ - (ASLayout *)calculateLayoutThatFits:(ASSizeRange)constrainedSize
}
ASDisplayNodeLogEvent(self, @"computedLayout: %@", layout);

// Return the (original) unflattened layout if it needs to be stored. The layout will be flattened later on (@see _locked_setCalculatedDisplayNodeLayout:).
// Otherwise, flatten it right away.
if (! [ASDisplayNode shouldStoreUnflattenedLayouts]) {
layout = [layout filteredNodeLayoutTree];
if ([ASDisplayNode shouldStoreUnflattenedLayouts]) {
_unflattenedLayout = layout;
Copy link
Member

@nguyenhuy nguyenhuy Oct 2, 2018

Choose a reason for hiding this comment

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

As discussed offline, there is a risk that the layout here will not be used/applied later on, and Weaver (or any other users of this API) will end up with a wrong unflattened layout. But given it's a debugging feature and should not be used in producation, the risk is small and doesn't warrant the complexity of previous implementation.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add some comment about this fact?

}
layout = [layout filteredNodeLayoutTree];

return layout;
}
Expand Down