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): fix quick modal presentation sequence where foreign modal is being dismissed #2671

Merged
merged 3 commits into from
Feb 6, 2025
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
63 changes: 63 additions & 0 deletions apps/src/tests/Test2668.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { NavigationContainer, ParamListBase } from '@react-navigation/native';
import { NativeStackNavigationProp, createNativeStackNavigator } from '@react-navigation/native-stack';
import React from 'react';
import { Button, Modal, Text, View } from 'react-native';
import { SafeAreaView } from 'react-native-safe-area-context';

const Stack = createNativeStackNavigator();

function Home({ navigation }: { navigation: NativeStackNavigationProp<ParamListBase> }) {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>1. Open owned modal</Text>
<Button title="Show modal" onPress={() => navigation.navigate('Modal')} />
</View>
);
}

function Second({ navigation }: { navigation: NativeStackNavigationProp<ParamListBase> }) {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>4. This should be presented modally without any glitches</Text>
<Button title="PopTo Home" onPress={() => {
navigation.popTo('Home');
}} />
</View>
);
}

function ModalScreen({ navigation }: { navigation: NativeStackNavigationProp<ParamListBase> }) {
const [modalVisible, setModalVisible] = React.useState(false);
return (
<View style={{ flex: 1 }}>
<Text>2. Click "ShowModal" to open foreign modal</Text>
<Button title="Show modal" onPress={() => setModalVisible(true)} />
<Button title="PopTo Second" onPress={() => {
//setModalVisible(false);
//navigation.popTo('Second');
navigation.navigate('Second');
}} />
<Modal visible={modalVisible} transparent={true} animationType="fade">
<View style={{ flex: 1, backgroundColor: 'rgba(0, 0, 0, 0.5)', justifyContent: 'center' }}>
<Text>3. Dismiss foreign modal and present owned one in single transaction</Text>
<Button title="Hide modal and navigate" onPress={() => {
setModalVisible(false);
navigation.navigate('Second');
}} />
</View>
</Modal>
</View>
);
}

export default function App() {
return (
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen name="Home" component={Home} />
<Stack.Screen name="Modal" component={ModalScreen} options={{ presentation: 'modal', headerShown: false }} />
<Stack.Screen name="Second" component={Second} options={{ headerShown: false }} />
</Stack.Navigator>
</NavigationContainer>
);
}
1 change: 1 addition & 0 deletions apps/src/tests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export { default as Test2395 } from './Test2395';
export { default as Test2466 } from './Test2466';
export { default as Test2552 } from './Test2552';
export { default as Test2631 } from './Test2631';
export { default as Test2668 } from './Test2668';
export { default as TestScreenAnimation } from './TestScreenAnimation';
export { default as TestScreenAnimationV5 } from './TestScreenAnimationV5';
export { default as TestHeader } from './TestHeader';
Expand Down
13 changes: 12 additions & 1 deletion ios/RNSScreenStack.mm
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,18 @@ - (void)setModalViewControllers:(NSArray<UIViewController *> *)controllers
// See: https://github.com/software-mansion/react-native-screens/issues/2048
// For now, to mitigate the issue, we also decide to trigger its dismissal before
// starting the presentation chain down below in finish() callback.
[changeRootController dismissViewControllerAnimated:shouldAnimate completion:finish];
if (!firstModalToBeDismissed.isBeingDismissed) {
[changeRootController dismissViewControllerAnimated:shouldAnimate completion:finish];
} else {
// We need to wait for its dismissal and then run our presentation code.
// This happens, e.g. when we have foreign modal presented on top of owned one & we dismiss foreign one and
// immediately present another owned one. Dismissal of the foreign one will be triggered by foreign controller.
[[firstModalToBeDismissed transitionCoordinator]
animateAlongsideTransition:nil
completion:^(id<UIViewControllerTransitionCoordinatorContext> _) {
finish();
}];
}
return;
}
}
Expand Down
Loading