-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
iOS can't dismiss Modal! #29319
Comments
I think you might want to use the |
The possibility to swipe to dismiss modals was removed in 0.63 due to problems with it. It was broken and needed hacks to function properly, but sad that it was removed. 😕 |
after updating react native from 0.62 to 0.63 , my modal component closes on onRequestClose method but after that every click/touch on screen fails, seems like modal is still open in background. i checked with react-native-modal , react-native-translucent-modal , it behaves same. |
Yes, same bug there and no solution so far: react-native-modal/react-native-modal#447 |
Same issue, pageSheet Modal cannot be dismissed on swipe down |
+1 |
a workaround for this is in when you are setting visible state to true on press of a button, check if it is false initially and if so, toggle it twice (one with a timeout). There is one pending PR for this. so you can make those changes in native code when compiling with Xcode. |
managed to implement a working solution using react-native-modal with both scrollable contents and swipe-to-dismiss functionality. I recommend looking at the ScrollableModal example in the react-native-modal examples repo: https://github.com/react-native-modal/react-native-modal/blob/master/example/src/modals/ScrollableModal.tsx |
Just had an idea to wrap the modal in a navigator which seem to work fine except for https://github.com/satya164/react-navigation-native-modal#readme |
Not a solution to this issue, but a perfectly working alternative for some: React Navigation's createNativeStackNavigator with a Edit: Some more information on how to implement a modal like this can be found in the React Navigation docs: Opening a full-screen modal. |
This patch works for me react-native+0.63.3.patch |
Hi all, how about this issue, i still find this issue on RN. 0.63.4 |
Implemented the solution suggested by @alexandersandberg and it works! Combine Here's my code. You should be able to paste this in and have it work (assuming you have the correct dependencies) import React from 'react'
import { NavigationContainer } from '@react-navigation/native'
import { createStackNavigator } from '@react-navigation/stack'
import {
View,
Text,
Button
} from 'react-native'
import { createNativeStackNavigator } from 'react-native-screens/native-stack'
import { enableScreens } from 'react-native-screens'
enableScreens()
const MainStack = createStackNavigator()
const RootStack = createNativeStackNavigator()
function HomeScreen({ navigation }) {
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Text style={{ fontSize: 30 }}>This is the home screen!</Text>
<Button
onPress={() => navigation.navigate('MyModal')}
title="Open Modal"
/>
</View>
)
}
function DetailsScreen() {
return (
<View>
<Text>Details</Text>
</View>
)
}
function MainStackScreen() {
return (
<MainStack.Navigator>
<MainStack.Screen name="Home" component={HomeScreen} />
<MainStack.Screen name="Details" component={DetailsScreen} />
</MainStack.Navigator>
)
}
function ModalScreen({ navigation }) {
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Text style={{ fontSize: 30 }}>This is a modal!</Text>
<Button onPress={() => navigation.goBack()} title="Dismiss" />
</View>
)
}
// We use React Navigation's modal to be able to use swipeable native modals
function RootStackScreen() {
return (
<RootStack.Navigator
mode="modal"
screenOptions={{
headerShown: false,
stackPresentation: 'formSheet'
}}
>
<RootStack.Screen
name="Main"
component={MainStackScreen}
options={{ headerShown: false }}
/>
<RootStack.Screen
name="MyModal"
component={ModalScreen}
/>
</RootStack.Navigator>
)
}
export default function AppNavigator() {
return (
<NavigationContainer>
<RootStackScreen />
</NavigationContainer>
)
} |
Hi, is someone able to dismiss the modal with React Native 0.64? I upgraded, and this is not working for me… I just tried with a brand new project and it’s not working. Here’s my example code: import React, {useState} from 'react';
import {SafeAreaView, StatusBar, Text, Modal, Button} from 'react-native';
const App = () => {
const [visible, setVisible] = useState(false);
return (
<SafeAreaView>
<StatusBar barStyle="light-content" />
<Button title="Open" onPress={() => setVisible(true)} />
<Modal
visible={visible}
presentationStyle="pageSheet"
animationType="slide"
onRequestClose={() => {
console.log('close');
setVisible(false);
}}
onDismiss={() => {
console.log('dismiss');
setVisible(false);
}}>
<Text>Modal</Text>
</Modal>
</SafeAreaView>
);
};
export default App; Unfortunately, neither function is firing. Is there anything I missed? Everything is fine in yarn global add react-native
react-native init ExampleProject Then just changed the |
Summary: This PR aims to resolve iOS can't dismiss Modal on swipe gesture. #29319 When modal presentationStyle is pageSheet, iOS allows to dismiss the modal using swipe gesture. This PR adds support for that feature ## Changelog <!-- Help reviewers and the release process by writing your own changelog entry. For an example, see: https://github.com/facebook/react-native/wiki/Changelog --> [iOS] [Added] - Support for onRequestClose for iOS Modal component. Pull Request resolved: #31500 Test Plan: - If onRequestClose updates the visibility state, modal will be closed. ``` <Modal visible={visible} animationType="slide" presentationStyle="pageSheet" onRequestClose={dismiss}> </Modal> ``` https://user-images.githubusercontent.com/23293248/117590263-36cd7f00-b14c-11eb-940c-86e700c0b8e7.mov ## Notes - In this PR, only support for partial drag is added. i.e. user can't drag the modal up and down completely. I added full user dragging but reverted in this [commit](bb65b9a) to support controllable onRequestClose. If someone has any suggestion to have full draggable support + controllable onRequestClose, please let me know. <!-- the code is solid. Example: The exact commands you ran and their output, screenshots / videos if the pull request changes the user interface. --> Reviewed By: p-sun Differential Revision: D30041625 Pulled By: sammy-SC fbshipit-source-id: 9675da760bd5c070c4f0e1d30271c8af5c50b998
I was having a similar issue (modals would stick in the app and pretty much freeze the application) and was able to fix it with this change. Use |
@ghivert nope, I can't get |
This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
This issue was closed because it has been stalled for 7 days with no activity. |
Any updates on this issue? I'm on 0.72 and I still see the issue. |
Description
On iOS the
<Modal>
component cannot be dismissed by dragging down. (gesture is a native behaviour on iOS)The reason for that being is that the
onDismiss
oronRequestClose
function is never called. It is only being called on tvOS.React Native version:
Steps To Reproduce
<Modal>
component and setvisible
andonRequestClose
propertiesvisible
totrue
Expected Results
Modal should be dragged down and
onDismiss
oronRequestClose
should be calledSnack, code example, screenshot, or link to a repository:
The text was updated successfully, but these errors were encountered: