Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(iOS): restore behaviour of RNSScreenStackAnimationNone #2565

Merged
merged 6 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions apps/src/tests/TestAnimation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,18 @@ function Fifth({ navigation }: RoutePropBase<'Fifth'>): React.ReactNode {
);
}

function HeaderRight() {
return (
<Square size={20} color="blue" />
);
}

export default function App() {
return (
<NavigationContainer>
<Stack.Navigator screenOptions={{
fullScreenGestureEnabled: true,
animation: 'simple_push',
//animationMatchesGesture: true,
headerRight: HeaderRight,
}}>
<Stack.Screen name="Home" component={Home} />
<Stack.Screen name="Second" component={Second} options={{
Expand Down
2 changes: 2 additions & 0 deletions ios/RNSScreenStackAnimator.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma once

#import "RNSScreen.h"

@interface RNSScreenStackAnimator : NSObject <UIViewControllerAnimatedTransitioning>
Expand Down
85 changes: 61 additions & 24 deletions ios/RNSScreenStackAnimator.mm
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ - (NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)t
}

if (screen != nil && screen.stackAnimation == RNSScreenStackAnimationNone) {
return 0;
return 0.0;
}

if (screen != nil && screen.transitionDuration != nil && [screen.transitionDuration floatValue] >= 0) {
Expand All @@ -70,12 +70,6 @@ - (NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)t
return _transitionDuration;
}

//- (id<UIViewImplicitlyAnimating>)interruptibleAnimatorForTransition:
// (id<UIViewControllerContextTransitioning>)transitionContext
//{
// return _inFlightAnimator;
//}

- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext
{
UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
Expand Down Expand Up @@ -489,6 +483,38 @@ - (void)animateWithNoAnimation:(id<UIViewControllerContextTransitioning>)transit
}
}

- (void)animateNoneWithTransitionContext:(id<UIViewControllerContextTransitioning>)transitionContext
toVC:(UIViewController *)toViewController
fromVC:(UIViewController *)fromViewController
{
toViewController.view.frame = [transitionContext finalFrameForViewController:toViewController];

if (_operation == UINavigationControllerOperationPush) {
[[transitionContext containerView] addSubview:toViewController.view];
toViewController.view.alpha = 0.0;
[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<UITimingCurveProvider>)timingParamsForAnimationCompletion
Expand All @@ -509,24 +535,35 @@ - (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];
return;
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
Expand Down
Loading