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, Paper): prevent double modal dismissal #2568

Merged
merged 3 commits into from
Dec 11, 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
25 changes: 22 additions & 3 deletions apps/src/tests/TestModalNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ type StackParamList = {
Home: undefined;
NestedStack: undefined;
MainStackScreen: undefined;
MainStackScreen2: undefined;
Screen1: undefined;
Screen2: undefined;
Screen3: undefined;
};


function HomeScreen({
navigation,
}: NativeStackScreenProps<StackParamList, 'Home'>) {
Expand All @@ -34,6 +36,22 @@ function MainStackScreen({ navigation }: NativeStackScreenProps<StackParamList,
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Text>Main stack screen</Text>
<Button
title="Go to second modal"
onPress={() => navigation.navigate('MainStackScreen2')}
/>
<Button
title="goBack"
onPress={() => navigation.goBack()}
/>
</View>
);
}

function MainStackScreen2({ navigation }: NativeStackScreenProps<StackParamList, 'MainStackScreen2'>) {
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Text>Main stack screen 2</Text>
<Button
title="goBack"
onPress={() => navigation.goBack()}
Expand All @@ -54,7 +72,7 @@ function Screen1({
/>
</View>
);
};
}

function Screen2({
navigation,
Expand All @@ -72,7 +90,7 @@ function Screen2({
/>
</View>
);
};
}

function Screen3({
navigation,
Expand All @@ -90,7 +108,7 @@ function Screen3({
/>
</View>
);
};
}

const Stack = createNativeStackNavigator<StackParamList>();
const NestedStack = createNativeStackNavigator<StackParamList>();
Expand All @@ -101,6 +119,7 @@ function RootStack() {
<Stack.Screen name="Home" component={HomeScreen} />
<Stack.Screen name="NestedStack" component={NestedStackScreen} options={{ headerShown: true, presentation: 'modal' }} />
<Stack.Screen name="MainStackScreen" component={MainStackScreen} options={{ headerShown: true, presentation: 'modal' }} />
<Stack.Screen name="MainStackScreen2" component={MainStackScreen2} options={{ headerShown: true, presentation: 'modal' }} />
</Stack.Navigator>
);
}
Expand Down
2 changes: 1 addition & 1 deletion ios/RNSScreenStack.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1281,7 +1281,7 @@ - (void)invalidate
// with modal presentation or foreign modal presented from inside a Screen.
- (void)dismissAllRelatedModals
{
[_controller dismissViewControllerAnimated:YES completion:nil];
[_controller.presentedViewController 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
Loading