Modal doesn't close when navigating to different screen
See original GitHub issueBug
This is not technically a bug, it’s just something that is not implemented and I am not sure how to implement this on my own. When using in combination with React Navigation, if you open a modal in one screen and then navigate to another, the modal in the first screen remains open. How would you recommend having the modals in a screen all dismiss when navigating away from the screen?
Environment info
Library | Version |
---|---|
“@gorhom/bottom-sheet” | “^2” |
“react-native” | “https://github.com/expo/react-native/archive/sdk-40.0.1.tar.gz” |
“react-native-reanimated” | “~1.13.0” |
“react-native-gesture-handler” | “~1.8.0” |
“@react-navigation/bottom-tabs” | “^5.11.3” |
“@react-navigation/material-top-tabs” | “^5.2.16” |
“@react-navigation/native” | “^5.9.0” |
“@react-navigation/stack” | “^5.12.6” |
Steps To Reproduce
Install React navigation and add the bottom sheet to each of the screens. When you navigate to another screen you would expect the modal to be gone, but it’s there if you navigate back to the original screen.
Reproducible sample code
yarn
😃
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
How to close modal when navigating back to my screen?
I use some states for modal visibility. However, the problem is that when I navigate from the modal to another screen and then...
Read more >Modal | React Native Navigation
A modal is a term used in native iOS world (full description here), while on Android, dialogs are often used to create similar...
Read more >Modal · Bootstrap v5.0
Modals are built with HTML, CSS, and JavaScript. · Clicking on the modal “backdrop” will automatically close the modal. · Bootstrap only supports...
Read more >Opening a modal - React Navigation
When set to modal , all modal screens animate-in from bottom to top rather than right to left by default. This applies to...
Read more >react-native-modal - npm
Unfortunately right now react-native doesn't allow multiple modals to be displayed at the same time. This means that, in react-native-modal , if ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
hi @kickbk, you can dismiss or close the
BottomSheet
whenever you leave the screen, read more about useFocusEffect 👍For anybody who might stumble on this, I fixed my modal with: