From 42b53c9331cd5aaa89585cd3f9110252dde081ef Mon Sep 17 00:00:00 2001 From: Michael Schneider Date: Mon, 6 Feb 2017 15:29:37 -0800 Subject: [PATCH] [ASLayoutTransition] Remove taking a snapshot in the default layout transition code (#2940) * Remove taking a snapshot in the default default layout transition code * Set groupOpacity for root node of animation to true before and restore after animation finished --- AsyncDisplayKit/ASDisplayNode.mm | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/AsyncDisplayKit/ASDisplayNode.mm b/AsyncDisplayKit/ASDisplayNode.mm index b9b9d9ca20..16edd098c1 100644 --- a/AsyncDisplayKit/ASDisplayNode.mm +++ b/AsyncDisplayKit/ASDisplayNode.mm @@ -1600,7 +1600,6 @@ ASLayoutElementFinalLayoutElementDefault NSAssert(node.isNodeLoaded == YES, @"Invalid node state"); NSArray *removedSubnodes = [context removedSubnodes]; - NSMutableArray *removedViews = [NSMutableArray array]; NSMutableArray *insertedSubnodes = [[context insertedSubnodes] mutableCopy]; NSMutableArray *movedSubnodes = [NSMutableArray array]; @@ -1613,15 +1612,6 @@ ASLayoutElementFinalLayoutElementDefault CGRect fromFrame = [context initialFrameForNode:subnode]; CGRect toFrame = [context finalFrameForNode:subnode]; if (CGSizeEqualToSize(fromFrame.size, toFrame.size) == NO) { - // To crossfade resized subnodes, show a snapshot of it on top. - // The node itself can then be treated as a newly-inserted one. - UIView *snapshotView = [subnode.view snapshotViewAfterScreenUpdates:YES]; - snapshotView.frame = [context initialFrameForNode:subnode]; - snapshotView.alpha = 1; - - [node.view insertSubview:snapshotView aboveSubview:subnode.view]; - [removedViews addObject:snapshotView]; - [insertedSubnodes addObject:subnode]; } if (CGPointEqualToPoint(fromFrame.origin, toFrame.origin) == NO) { @@ -1643,15 +1633,16 @@ ASLayoutElementFinalLayoutElementDefault insertedSubnode.frame = [context finalFrameForNode:insertedSubnode]; insertedSubnode.alpha = 0; } + + // Adjust groupOpacity for animation + BOOL originAllowsGroupOpacity = node.allowsGroupOpacity; + node.allowsGroupOpacity = YES; [UIView animateWithDuration:self.defaultLayoutTransitionDuration delay:self.defaultLayoutTransitionDelay options:self.defaultLayoutTransitionOptions animations:^{ // Fade removed subnodes and views out for (ASDisplayNode *removedSubnode in removedSubnodes) { removedSubnode.alpha = 0; } - for (UIView *removedView in removedViews) { - removedView.alpha = 0; - } // Fade inserted subnodes in for (_ASAnimatedTransitionContext *insertedSubnodeContext in insertedSubnodeContexts) { @@ -1674,9 +1665,10 @@ ASLayoutElementFinalLayoutElementDefault for (_ASAnimatedTransitionContext *removedSubnodeContext in removedSubnodeContexts) { removedSubnodeContext.node.alpha = removedSubnodeContext.alpha; } - for (UIView *removedView in removedViews) { - [removedView removeFromSuperview]; - } + + // Restore group opacity + node.allowsGroupOpacity = originAllowsGroupOpacity; + // Subnode removals are automatically performed [context completeTransition:finished]; }];