question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Modal doesn't close when navigating to different screen

See original GitHub issue

Bug

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:closed
  • Created 3 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
gorhomcommented, Jan 23, 2021

hi @kickbk, you can dismiss or close the BottomSheet whenever you leave the screen, read more about useFocusEffect 👍

0reactions
liquidvisualcommented, Mar 21, 2022

For anybody who might stumble on this, I fixed my modal with:

handlePress = () => {
   navigation.goBack();
   navigation.navigate("SomeScreen", { id: 123});
}
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found