You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi !
I have a little issue on Android, onGestureEvent is not trigger when GestureHandler components is on a modal on Android. When I change the modal to a View, it works perfectly 👌
Reacted by jklongi, César Guadarrama, Gustavo Aires, Harrison, Reza Sam Khaniani, xpertystanalyst, Jaime Deverall, Lucas Gomes, Júnior Nunes, Ruslan Dinullin and 3 more
I was using a standard React Native Modal and was experiencing this issue.
I worked around the problem by creating a new screen and displaying it as a modal. I'm using react-native-navigation, so:
I'm trying to call the RectButton inside a modal of createStackNavigator(@react-navigation/stack), on android the RectButton doesn't trigger onPress, IOS works perfectly
For me, I just installed the newest version 2.4.0. And then I use GestureHandlerRootView to wrapper the PanGestureHandler. It works. Remember that don't wrapper the view or others components. Wrapper thePanGestureHandler like below:
For me, I just installed the newest version 2.4.0. And then I use GestureHandlerRootView to wrapper the PanGestureHandler. It works. Remember that don't wrapper the view or others components. Wrapper thePanGestureHandler like below:
This happened to me too and belive it or not I solved it by setting backgroundColor of the GesturHandler content (the inner View) to transparent (or any value)
I'm guessing because react-native optimizes views only used for positioning their children and removes them or something and having a backgroundColor forces it to keep the view (please correct me if I'm wrong).
RNGH works in a react native Modal if you wrap ONLY the content of the Modal in the GestureHandlerRootView component (see RNGH docs, this comment and this pull request).
But if you wrap the whole app (or a screen that contains the Modal) in GestureHandlerRootView too, RNGH buttons stops working inside the Modal (see why below).
Examples
Example of GestureHandlerRootView used only inside a Modal:
constGHRVInsideModal: React.FC=()=>{const[visible,setVisible]=useState(false);return(<><TouchableOpacityonPress={()=>setVisible(true)}><Text>Open (it's RN button) - it works</Text></TouchableOpacity><ModalanimationType="slide"transparentvisible={visible}><Viewstyle={styles.modal}><RectButtononPress={()=>setVisible(false)}><Text>Close (it's RNGH button outside GestureHandlerRootView) - it does not work</Text></RectButton><GestureHandlerRootView><RectButtononPress={()=>setVisible(false)}><Text>Close (it's RNGH button inside GestureHandlerRootView) - it works</Text></RectButton></GestureHandlerRootView></View></Modal></>);};
Example of nested GestureHandlerRootView:
constNestedGHRV: React.FC=()=>{const[visible,setVisible]=useState(false);return(<GestureHandlerRootView><RectButtononPress={()=>setVisible(true)}><Text>Open (it's RNGH button) - it works</Text></RectButton><ModalanimationType="slide"transparentvisible={visible}><Viewstyle={styles.modal}><GestureHandlerRootView><RectButtononPress={()=>setVisible(false)}><Text>Close (it's RNGH button inside GestureHandlerRootView) - it does not work</Text></RectButton><TouchableOpacityonPress={()=>setVisible(false)}><Text>Close (it's RN button) - it works</Text></TouchableOpacity></GestureHandlerRootView></View></Modal></GestureHandlerRootView>);};
Video with two examples:
Screen.Recording.2021-06-29.at.15.06.01.mov
See this repo with two examples.
React navigation
If you create a Modal inside react-navigation's stack and wrap the content of the Modal in GestureHandlerRootView as the documentation says, it reproduces the second example and RNGH buttons in a Modal will not work.
This is happening because react-navigation wraps the stack content in GestureHandlerRootView and your GH root view in a Modal renders as a simple View.
How to fix
Why does the button in the Modal work in the first case, but not in the second?
If we look at the 17th line of the GestureHandlerRootView.android.tsx file we see, that nested gesture handler root views renders as View. If you try to delete 17-22 lines from the GestureHandlerRootView.android.tsx file the second example will start working.
Video reproduced what will be if you delete 17-22 lines from the GestureHandlerRootView.android.tsx file (uploaded to YouTube, because GitHub does not allow uploading large files):
As a result, if the nested GestureHandlerRootView is NOT rendered as a simple View, RNGH buttons in a Modal in Android will work. I created a pull request #1493 that fixes it.
2023, problem is still there, but this worked. Thanks!
Activity
[-][Android] Doesn't on a modal[/-][+][Android] Doesn't work on a modal[/+][-][Android] Doesn't work on a modal[/-][+][Android] Doesn't work in a modal[/+]mordaha commentedon Jun 8, 2018
+1
any workaround?
martinezguillaume commentedon Jun 8, 2018
I don’t use Modal for now, I just re-create it with a View in absolute position
mordaha commentedon Jun 8, 2018
using modal screen for now, after googling and chats Modal from RN considered too much buggy thing
csto commentedon Jun 20, 2018
+1
osdnk commentedon Jul 10, 2018
Hi, @martinezguillaume, @mordaha, @csto
I did take a look on this issue and I suppose it's not a matter of our library, but RN Core.
mars-lan commentedon Jul 14, 2018
@osdnk is this fixable?
ParhamZare commentedon Dec 11, 2018
+1 gesture does not work on modal
ewendel commentedon Jan 28, 2019
I also ran into this bug today.
Dmitrylolo commentedon Feb 26, 2019
Same for me. Tested react-native's PanResponder handlers on modal - works fine.
I have a thoughts about this: when we are linking this library to android project, we are doing next step
And we know that modal is separate package. May be theres sense to do something same with it?
samzmann commentedon Mar 26, 2019
I was using a standard React Native
Modaland was experiencing this issue.I worked around the problem by creating a new screen and displaying it as a modal. I'm using react-native-navigation, so:
Gestures are working as expected on both iOS and Android, and I still get transparent background that I wanted from my original modal.
osdnk commentedon Mar 26, 2019
I have dug into it for a while.
If someone wants and has time to do it, I'll happily review it and merge immediately if it would be workable and not too hacky.
@martinezguillaume @mordaha @csto @mars-lan @ParhamZare @ewendel @via-profit @Dmitrylolo @Lavielle
89 remaining items
eduardorfreitas93 commentedon Jan 19, 2022
I'm trying to call the RectButton inside a modal of createStackNavigator(@react-navigation/stack), on android the RectButton doesn't trigger onPress, IOS works perfectly
react-native-gesture-handler: 2.1.1
@react-navigation/native: ^6.0.6
@react-navigation/stack: ^6.0.11
Any solution?
Fix modals (software-mansion#1603)
thahermps commentedon May 2, 2022
Thanks a lot finally this solution worked for me. :)
prasanthmurugasamy commentedon Jul 4, 2022
need more assistance.! can you please help me with this?
zhaiyjgithub commentedon Jul 7, 2022
For me, I just installed the newest version 2.4.0. And then I use GestureHandlerRootView to wrapper the PanGestureHandler. It works. Remember that don't wrapper the view or others components. Wrapper thePanGestureHandler like below:
hugoh59 commentedon Aug 3, 2022
This fix does make the component scrollable but it's still super glitchy on android compared to when using the same component outside of a modal.
first-dev commentedon Aug 30, 2022
This happened to me too and belive it or not I solved it by setting
backgroundColorof theGesturHandlercontent (the innerView) totransparent(or any value)I'm guessing because react-native optimizes views only used for positioning their children and removes them or something and having a
backgroundColorforces it to keep the view (please correct me if I'm wrong).ser-emejia commentedon Jan 26, 2023
Still not working on Android 👎
usedlife commentedon Apr 18, 2023
Try this: https://docs.swmansion.com/react-native-gesture-handler/docs/installation/#usage-with-modals-on-android
Martijncvv commentedon Jul 7, 2023
2023, problem is still there, but this worked. Thanks!
Goowwy commentedon Aug 25, 2023
Thanks its working for me
ammarfaris commentedon Sep 14, 2023
Thanks for summarising @Goowwy . Works like a charm in Android modal! You all are life savers!
steniowagner commentedon Oct 13, 2023
"react": "18.2.0",
"react-native": "0.72.5",
"react-native-gesture-handler": "^2.13.1"
Wrapping the components that uses the RNGH stuff still works like a charm!
Thank you so much everyone!
fix (RNGH): BottomSheet buttons are not working
fix (RNGH): BottomSheet buttons are not working (#1056)