Open mrousavy opened 4 years ago
I think you might want to use the react-native-modal
package. The React Native team I think has tried to keep the included Modal component fairly basic. The other package expands on that with a lot of functionality.
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. even after app reload its doesnt work. every time requires new build.
i checked with react-native-modal , react-native-translucent-modal , it behaves same.
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. even after app reload its doesnt work. every time requires new build.
i checked with react-native-modal , react-native-translucent-modal , it behaves same.
Yes, same bug there and no solution so far: https://github.com/react-native-community/react-native-modal/issues/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 pageSheet
/formSheet
modals because of the issue. If it worked, we'd have a native modal style navigator without any extra libraries.
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 stackPresentation
set to modal
, formSheet
, or whatever you prefer.
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 https://reactnavigation.org/docs/modal with https://stackoverflow.com/questions/62283000/is-it-possible-to-present-modals-with-the-uimodalpresentationpagesheet-or-uimoda
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 react-native doctor
, and I started the new project with react-native
globally installed:
yarn global add react-native
react-native init ExampleProject
Then just changed the App.js
.
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 yarn patch-package
to do so.
@ghivert nope, I can't get onRequestClose
to fire.
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: