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] Propagate traits before loading a subnode #1234

Merged
merged 1 commit into from
Nov 20, 2018
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
23 changes: 12 additions & 11 deletions Source/ASDisplayNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2139,6 +2139,18 @@ - (void)_setSupernode:(ASDisplayNode *)newSupernode
stateToEnterOrExit |= ASHierarchyStateRasterized;
}
if (newSupernode) {

// Now that we have a supernode, propagate its traits to self.
// This should be done before possibly forcing self to load so we have traits in -didLoad
ASTraitCollectionPropagateDown(self, newSupernode.primitiveTraitCollection);

if (!parentWasOrIsRasterized && newSupernode.nodeLoaded) {
// Trigger the subnode to load its layer, which will create its view if it needs one.
// By doing this prior to the downward propagation of newSupernode's interface state,
// we can guarantee that -didEnterVisibleState is only called with .isNodeLoaded = YES.
[self layer];
}

[self enterHierarchyState:stateToEnterOrExit];

// If a node was added to a supernode, the supernode could be in a layout pending state. All of the hierarchy state
Expand All @@ -2158,10 +2170,6 @@ - (void)_setSupernode:(ASDisplayNode *)newSupernode
}
}
}

// Now that we have a supernode, propagate its traits to self.
ASTraitCollectionPropagateDown(self, newSupernode.primitiveTraitCollection);

} else {
// If a node will be removed from the supernode it should go out from the layout pending state to remove all
// layout pending state related properties on the node
Expand Down Expand Up @@ -2260,13 +2268,6 @@ - (void)_insertSubnode:(ASDisplayNode *)subnode atSubnodeIndex:(NSInteger)subnod
_cachedSubnodes = nil;
__instanceLock__.unlock();

if (!isRasterized && self.nodeLoaded) {
// Trigger the subnode to load its layer, which will create its view if it needs one.
// By doing this prior to downward propagation of .interfaceState in _setSupernode:,
// we can guarantee that -didEnterVisibleState is only called with .isNodeLoaded = YES.
[subnode layer];
}

// This call will apply our .hierarchyState to the new subnode.
// If we are a managed hierarchy, as in ASCellNode trees, it will also apply our .interfaceState.
[subnode _setSupernode:self];
Expand Down