Merge pull request #1304 from garrettmoon/betterSkipClearContents

[ASDisplayNode] Coalesce -clearContents onto the next runloop, so it can be skipped if re-added to hierarchy in move operation.
This commit is contained in:
appleguy 2016-03-01 17:38:36 -08:00
commit 47d2981487
2 changed files with 17 additions and 26 deletions

View File

@ -1227,7 +1227,7 @@ static bool disableNotificationsForMovingBetweenParents(ASDisplayNode *from, ASD
if (isMovingEquivalentParents) {
[subnode __incrementVisibilityNotificationsDisabled];
}
[subnode removeFromSupernodeMovingBetweenNodes:YES];
[subnode removeFromSupernode];
if (!_subnodes)
_subnodes = [[NSMutableArray alloc] init];
@ -1497,11 +1497,6 @@ static NSInteger incrementIfFound(NSInteger i) {
}
- (void)removeFromSupernode
{
[self removeFromSupernodeMovingBetweenNodes:NO];
}
- (void)removeFromSupernodeMovingBetweenNodes:(BOOL)movingBetweenNodes
{
ASDisplayNodeAssertThreadAffinity(self);
BOOL shouldRemoveFromSuperviewOrSuperlayer = NO;
@ -1531,18 +1526,11 @@ static NSInteger incrementIfFound(NSInteger i) {
if (shouldRemoveFromSuperviewOrSuperlayer) {
ASPerformBlockOnMainThread(^{
ASDN::MutexLocker l(_propertyLock);
if (movingBetweenNodes) {
_flags.isMovingBetweenNodes = YES;
}
if (_flags.layerBacked) {
[_layer removeFromSuperlayer];
} else {
[_view removeFromSuperview];
}
if (movingBetweenNodes) {
_flags.isMovingBetweenNodes = NO;
}
});
}
}
@ -1982,14 +1970,6 @@ void recursivelyTriggerDisplayForLayer(CALayer *layer, BOOL shouldBlock)
- (void)clearContents
{
// No-op if these haven't been created yet, as that guarantees they don't have contents that needs to be released.
{
ASDN::MutexLocker l(_propertyLock);
//Do not clear contents if we're mearly moving between nodes
if (_flags.isMovingBetweenNodes) {
return;
}
}
_layer.contents = nil;
_placeholderLayer.contents = nil;
_placeholderImage = nil;
@ -2103,8 +2083,14 @@ void recursivelyTriggerDisplayForLayer(CALayer *layer, BOOL shouldBlock)
[self setDisplaySuspended:NO];
} else {
[self setDisplaySuspended:YES];
//schedule clear contents on next runloop
dispatch_async(dispatch_get_main_queue(), ^{
ASDN::MutexLocker l(_propertyLock);
if (ASInterfaceStateIncludesDisplay(_interfaceState) == NO) {
[self clearContents];
}
});
}
} else {
// NOTE: This case isn't currently supported as setInterfaceState: isn't exposed externally, and all
// internal use cases are range-managed. When a node is visible, don't mess with display - CA will start it.
@ -2115,8 +2101,14 @@ void recursivelyTriggerDisplayForLayer(CALayer *layer, BOOL shouldBlock)
[ASDisplayNode scheduleNodeForRecursiveDisplay:self];
} else {
[[self asyncLayer] cancelAsyncDisplay];
//schedule clear contents on next runloop
dispatch_async(dispatch_get_main_queue(), ^{
ASDN::MutexLocker l(_propertyLock);
if (ASInterfaceStateIncludesDisplay(_interfaceState) == NO) {
[self clearContents];
}
});
}
}
}
}

View File

@ -82,7 +82,6 @@ FOUNDATION_EXPORT NSString * const ASRenderingEngineDidDisplayNodesScheduledBefo
unsigned isEnteringHierarchy:1;
unsigned isExitingHierarchy:1;
unsigned isInHierarchy:1;
unsigned isMovingBetweenNodes:1;
unsigned visibilityNotificationsDisabled:VISIBILITY_NOTIFICATIONS_DISABLED_BITS;
} _flags;