Skip to content

Commit

Permalink
fix(iOS,Paper): fix broken modal go-back animation (#2496)
Browse files Browse the repository at this point in the history
## Description

We recently fixed left-out modals dismissal when reloading react-native.
For some reason
calling in `dismissViewControllerAnimated:completion:` on **nested**
UINavigationController
(the one responsible for displaying the navigation bar in modal, not the
one reponsible for presentation)
during invalidation messes up with the animation. 

I'm not really sure why this is the case. Earlier we were calling
dismiss on all presented modals,
but not on UINavigationController itself and it worked like a charm. 

I've found out that simply animating the change solves the situation -
we fix the animation and keep nice
modal dismissal on reload.

Fixes #2488

## Changes

:point_up:

## Test code and steps to reproduce

`TestModalNavigation`

## Checklist

- [ ] Included code example that can be used to test this change
- [ ] Updated TS types
- [ ] Updated documentation: <!-- For adding new props to native-stack
-->
- [ ]
https://github.com/software-mansion/react-native-screens/blob/main/guides/GUIDE_FOR_LIBRARY_AUTHORS.md
- [ ]
https://github.com/software-mansion/react-native-screens/blob/main/native-stack/README.md
- [ ]
https://github.com/software-mansion/react-native-screens/blob/main/src/types.tsx
- [ ]
https://github.com/software-mansion/react-native-screens/blob/main/src/native-stack/types.tsx
- [ ] Ensured that CI passes
  • Loading branch information
kkafar authored Nov 13, 2024
1 parent b84fd63 commit 68e3d73
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion apps/src/tests/TestModalNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,22 @@ function HomeScreen({
title="Navigate to Screen 1"
onPress={() => navigation.navigate('NestedStack')}
/>
<Button
title="Navigate to Screen (same stack)"
onPress={() => navigation.navigate('MainStackScreen')}
/>
</View>
);
}

function MainStackScreen() {
function MainStackScreen({ navigation }: NativeStackScreenProps<StackParamList, 'MainStackScreen'>) {
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Text>Main stack screen</Text>
<Button
title="goBack"
onPress={() => navigation.goBack()}
/>
</View>
);
}
Expand Down
2 changes: 1 addition & 1 deletion ios/RNSScreenStack.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1288,7 +1288,7 @@ - (void)invalidate
// with modal presentation or foreign modal presented from inside a Screen.
- (void)dismissAllRelatedModals
{
[_controller dismissViewControllerAnimated:NO completion:nil];
[_controller dismissViewControllerAnimated:YES completion:nil];

// This loop seems to be excessive. Above message send to `_controller` should
// be enough, because system dismisses the controllers recursively,
Expand Down

0 comments on commit 68e3d73

Please sign in to comment.