mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2026-01-03 11:44:46 +00:00
[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
This commit is contained in:
committed by
Adlai Holler
parent
e4c9878de7
commit
42b53c9331
@@ -1600,7 +1600,6 @@ ASLayoutElementFinalLayoutElementDefault
|
||||
NSAssert(node.isNodeLoaded == YES, @"Invalid node state");
|
||||
|
||||
NSArray<ASDisplayNode *> *removedSubnodes = [context removedSubnodes];
|
||||
NSMutableArray<UIView *> *removedViews = [NSMutableArray array];
|
||||
NSMutableArray<ASDisplayNode *> *insertedSubnodes = [[context insertedSubnodes] mutableCopy];
|
||||
NSMutableArray<ASDisplayNode *> *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];
|
||||
}];
|
||||
|
||||
Reference in New Issue
Block a user