Is it possible to close react native modal by clicking on overlay when transparent
option is true
? Documentation doesn't provide anything about it. Is it possible?
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- Can php detect if javascript is on or not?
this code is my solution.
If I understood correctly, you want to close the modal when the user clicks outside of it, right ?
If yes, I searched for this some time ago and the only solution that I remember was this one (which is the one that I've been using so far):
Explanation
This is basically using a TouchableOpacity in the whole screen to get when the user clicks to close the modal. The TouchableWithoutFeedback is to avoid the TouchableOpacity to work inside of the Modal.
If you have a better solution, please share here.
Here is my simple implementation:
I use TouchableWithoutFeedback since i do not want to change the background color when clicking on it. I also added onStartShouldSetResponder on the modal view to prevent closing the modal when you click inside the view.
I am also not using the Modal component because i done it using react-navigation.
Another solution:
Usage example:
We can work it out by adding:
under the window and another one above and change the layout style to fit your screen.
Explanation:
You will make 2 big hidden buttons to catch the user touch and change the modal visibility state to false.