Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React native TouchableOpacity onPress not working on Android

TouchabelOpacity works fine on iOS but the onPress method does not work on Android for me.

My react-native version: 0.57.4

My code:

const initDrawer = navigation => (   <TouchableOpacity     style={{ left: 16 }}     onPress={() => onPressDrawerButton(navigation)}   >     <Ionicons name="ios-menu" color="white" size={30} />   </TouchableOpacity> ); 
like image 515
user3653164 Avatar asked Nov 29 '18 22:11

user3653164


People also ask

Does Touchableopacity work on Android?

TouchabelOpacity works fine on iOS but the onPress method does not work on Android for me. I can confirm it works fine on Android with version 0.57. 7.

What is the difference between Pressable and Touchableopacity?

Pressable is all-in-one touchable components Pressable component has all the features of Touchable components. Therefore, we can replace all TouchableOpacity, TouchableHighlight, TouchableNativeFeedback and TouchableWithoutFeedback with a single component.

How do you reduce opacity of Touchableopacity in React Native?

On press down, the opacity of the wrapped view is decreased, dimming it. Opacity is controlled by wrapping the children in an Animated. View , which is added to the view hierarchy.

How do I make an image touchable in React Native?

To add image and onPress into touchable with React Native, we can set the onPress prop on the TouchableHighlight and put the Image the TouchableHighlight . to set onPress to a function that logs 'pressed' . And we put the Image inside. Asa a result, we see 'pressed' logged when we click on the image.


2 Answers

I had similar problem. Pay attention from where import your "TouchableOpacity". When I changed "TouchableOpacity" from "react-native-gesture-handler" to "react-native", it worked for me (for Android platform)

like image 192
Ali Avatar answered Sep 22 '22 03:09

Ali


I had the same issue, all TouchableOpacity buttons were working fine in iOS build, but there was one in Android that did not fire. I stumbled upon this answer here that mentioned that position: absolute would mess up the trigger. It solved my issue.

like image 26
Chris Avatar answered Sep 22 '22 03:09

Chris