Skip to content

Commit 68e3d73

Browse files
authored
fix(iOS,Paper): fix broken modal go-back animation (#2496)
## 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
1 parent b84fd63 commit 68e3d73

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

apps/src/tests/TestModalNavigation.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,22 @@ function HomeScreen({
2222
title="Navigate to Screen 1"
2323
onPress={() => navigation.navigate('NestedStack')}
2424
/>
25+
<Button
26+
title="Navigate to Screen (same stack)"
27+
onPress={() => navigation.navigate('MainStackScreen')}
28+
/>
2529
</View>
2630
);
2731
}
2832

29-
function MainStackScreen() {
33+
function MainStackScreen({ navigation }: NativeStackScreenProps<StackParamList, 'MainStackScreen'>) {
3034
return (
3135
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
3236
<Text>Main stack screen</Text>
37+
<Button
38+
title="goBack"
39+
onPress={() => navigation.goBack()}
40+
/>
3341
</View>
3442
);
3543
}

ios/RNSScreenStack.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1288,7 +1288,7 @@ - (void)invalidate
12881288
// with modal presentation or foreign modal presented from inside a Screen.
12891289
- (void)dismissAllRelatedModals
12901290
{
1291-
[_controller dismissViewControllerAnimated:NO completion:nil];
1291+
[_controller dismissViewControllerAnimated:YES completion:nil];
12921292

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

0 commit comments

Comments
 (0)