react-native: iOS can't dismiss Modal!
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
or onRequestClose
function is never called. It is only being called on tvOS.
React Native version:
info Fetching system and libraries information...
(node:10129) Warning: Accessing non-existent property 'padLevels' of module exports inside circular dependency
(Use `node --trace-warnings ...` to show where the warning was created)
System:
OS: macOS 10.15.5
CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
Memory: 2.78 GB / 32.00 GB
Shell: 5.7.1 - /bin/zsh
Binaries:
Node: 14.4.0 - /usr/local/bin/node
Yarn: 1.22.4 - /usr/local/bin/yarn
npm: 6.14.5 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.9.3 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: iOS 13.5, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2
Android SDK:
API Levels: 25, 28, 29
Build Tools: 28.0.3, 29.0.2, 29.0.3, 30.0.0, 30.0.0, 30.0.0
System Images: android-29 | Google APIs Intel x86 Atom, android-29 | Google Play Intel x86 Atom
Android NDK: 21.2.6472646
IDEs:
Android Studio: 4.0 AI-193.6911.18.40.6514223
Xcode: 11.5/11E608c - /usr/bin/xcodebuild
Languages:
Java: 1.8.0_252 - /usr/bin/javac
Python: 2.7.16 - /usr/bin/python
npmPackages:
@react-native-community/cli: Not Found
react: 16.13.1 => 16.13.1
react-native: 0.63.0 => 0.63.0
npmGlobalPackages:
*react-native*: Not Found
Steps To Reproduce
- Create
<Modal>
component and setvisible
andonRequestClose
properties - Open Modal by setting
visible
totrue
- Try to close Modal by dragging down
Expected Results
Modal should be dragged down and onDismiss
or onRequestClose
should be called
Snack, code example, screenshot, or link to a repository:
<Modal
presentationStyle="pageSheet"
visible={true}
onRequestClose={() => console.log("will never be called.")} />
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 32
- Comments: 19 (2 by maintainers)
Commits related to this issue
- Implement onRequestClose for iOS, fixes #29319 — committed to mrousavy/react-native by mrousavy 4 years ago
- fix#29319 - ios dismiss modal (#31500) Summary: This PR aims to resolve iOS can't dismiss Modal on swipe gesture. https://github.com/facebook/react-native/issues/29319 When modal presentationStyle i... — committed to facebook/react-native by intergalacticspacehighway 3 years ago
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)
Not a solution to this issue, but a perfectly working alternative for some:
React Navigation’s createNativeStackNavigator with a
stackPresentation
set tomodal
,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.
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:
Unfortunately, neither function is firing. Is there anything I missed? Everything is fine in
react-native doctor
, and I started the new project withreact-native
globally installed:Then just changed the
App.js
.Hi all, how about this issue, i still find this issue on RN. 0.63.4
Any updates on this issue? I’m on 0.72 and I still see the issue.
This patch works for me react-native+0.63.3.patch