in ComponentKit/Components/CKTransitionComponent.mm [27:73]
static auto disappearingPreviousComponentAnimation(CAAnimation *disappearAnimation,
CKComponent *previousComponent,
CKComponent *newComponent) -> CKComponentAnimation
{
return CKComponentAnimationHooks{
.willRemount = ^{
auto const childView = [previousComponent viewForAnimation];
RCCAssertWithCategory(
childView != nil,
[previousComponent className],
@"Can't animate component without a view. "
"Check %@ is from the previousComponent tree, has a view and is mounted.",
[previousComponent className]
);
auto const snapshotView = [childView snapshotViewAfterScreenUpdates:NO];
snapshotView.layer.anchorPoint = childView.layer.anchorPoint;
snapshotView.userInteractionEnabled = NO;
return snapshotView;
},
.didRemount = ^UIView *(UIView *snapshotView) {
auto const newView = [newComponent viewForAnimation];
RCCAssertWithCategory(newView != nil, [newComponent className], @"Can't animate %@ without a view.", [newComponent className]);
if (newView == nil || snapshotView == nil) {
return nil; // Avoid crashing in insertSubview:aboveSubview:
}
auto const frame = CGRect{
newView.frame.origin,
snapshotView.bounds.size,
};
snapshotView.frame = frame;
[newView.superview insertSubview:snapshotView aboveSubview:newView];
[CATransaction begin];
[CATransaction setCompletionBlock:^{
[snapshotView removeFromSuperview];
}];
[snapshotView.layer addAnimation:disappearAnimation forKey:nil];
[CATransaction commit];
return snapshotView;
},
.cleanup = ^(UIView *snapshotView) {
[snapshotView removeFromSuperview];
},
};
}