From 567242b2ab07c5351589b5595c041341660d9fa1 Mon Sep 17 00:00:00 2001 From: Kacper Kafara Date: Tue, 10 Dec 2024 13:04:15 +0100 Subject: [PATCH] Restore behaviour of StackAnimationNone - PoC (there is still some header animation) --- ios/RNSScreenStackAnimator.mm | 74 ++++++++++++++++++++++++++--------- 1 file changed, 56 insertions(+), 18 deletions(-) diff --git a/ios/RNSScreenStackAnimator.mm b/ios/RNSScreenStackAnimator.mm index 65a99f284..2a7f8c9b3 100644 --- a/ios/RNSScreenStackAnimator.mm +++ b/ios/RNSScreenStackAnimator.mm @@ -59,7 +59,7 @@ - (NSTimeInterval)transitionDuration:(id)t } if (screen != nil && screen.stackAnimation == RNSScreenStackAnimationNone) { - return 0; + return 0.0; } if (screen != nil && screen.transitionDuration != nil && [screen.transitionDuration floatValue] >= 0) { @@ -489,6 +489,34 @@ - (void)animateWithNoAnimation:(id)transit } } +- (void)animateNoneWithTransitionContext:(id)transitionContext + toVC:(UIViewController *)toViewController + fromVC:(UIViewController *)fromViewController +{ + if (_operation == UINavigationControllerOperationPush) { + [[transitionContext containerView] addSubview:toViewController.view]; + [UIView animateWithDuration:[self transitionDuration:transitionContext] + animations:^{ + toViewController.view.alpha = 1.0; + } + completion:^(BOOL finished) { + toViewController.view.alpha = 1.0; + [transitionContext completeTransition:![transitionContext transitionWasCancelled]]; + }]; + } else if (_operation == UINavigationControllerOperationPop) { + [[transitionContext containerView] insertSubview:toViewController.view belowSubview:fromViewController.view]; + + [UIView animateWithDuration:[self transitionDuration:transitionContext] + animations:^{ + fromViewController.view.alpha = 0.0; + } + completion:^(BOOL finished) { + fromViewController.view.alpha = 1.0; + [transitionContext completeTransition:![transitionContext transitionWasCancelled]]; + }]; + } +} + #pragma mark - Public API - (nullable id)timingParamsForAnimationCompletion @@ -509,24 +537,34 @@ - (void)animateTransitionWithStackAnimation:(RNSScreenStackAnimation)animation toVC:(UIViewController *)toVC fromVC:(UIViewController *)fromVC { - if (animation == RNSScreenStackAnimationSimplePush) { - [self animateSimplePushWithShadowEnabled:shadowEnabled transitionContext:transitionContext toVC:toVC fromVC:fromVC]; - return; - } else if (animation == RNSScreenStackAnimationSlideFromLeft) { - [self animateSlideFromLeftWithTransitionContext:transitionContext toVC:toVC fromVC:fromVC]; - return; - } else if (animation == RNSScreenStackAnimationFade || animation == RNSScreenStackAnimationNone) { - [self animateFadeWithTransitionContext:transitionContext toVC:toVC fromVC:fromVC]; - return; - } else if (animation == RNSScreenStackAnimationSlideFromBottom) { - [self animateSlideFromBottomWithTransitionContext:transitionContext toVC:toVC fromVC:fromVC]; - return; - } else if (animation == RNSScreenStackAnimationFadeFromBottom) { - [self animateFadeFromBottomWithTransitionContext:transitionContext toVC:toVC fromVC:fromVC]; - return; + switch (animation) { + case RNSScreenStackAnimationSimplePush: + [self animateSimplePushWithShadowEnabled:shadowEnabled + transitionContext:transitionContext + toVC:toVC + fromVC:fromVC]; + return; + case RNSScreenStackAnimationSlideFromLeft: + [self animateSlideFromLeftWithTransitionContext:transitionContext toVC:toVC fromVC:fromVC]; + return; + case RNSScreenStackAnimationFade: + [self animateFadeWithTransitionContext:transitionContext toVC:toVC fromVC:fromVC]; + return; + case RNSScreenStackAnimationSlideFromBottom: + [self animateSlideFromBottomWithTransitionContext:transitionContext toVC:toVC fromVC:fromVC]; + return; + case RNSScreenStackAnimationFadeFromBottom: + [self animateFadeFromBottomWithTransitionContext:transitionContext toVC:toVC fromVC:fromVC]; + return; + case RNSScreenStackAnimationNone: + [self animateNoneWithTransitionContext:transitionContext toVC:toVC fromVC:fromVC]; + default: + // simple_push is the default custom animation + [self animateSimplePushWithShadowEnabled:shadowEnabled + transitionContext:transitionContext + toVC:toVC + fromVC:fromVC]; } - // simple_push is the default custom animation - [self animateSimplePushWithShadowEnabled:shadowEnabled transitionContext:transitionContext toVC:toVC fromVC:fromVC]; } + (UISpringTimingParameters *)defaultSpringTimingParametersApprox