Pressable not working in react-native android
See original GitHub issueDescription
When a child of a pressable component is pressed (such as an image), the function passed to the onPress prop does not execute on android. Works as expected on iOS.
React Native version:
0.63.2
Steps To Reproduce
- Open a new expo snack
- Create a Pressable component that is the parent of some other component (A text or image)
- Set the onPress prop to call a function that has a visual effect. (Like an alert)
- Switch to the android tab, and click ‘Tap to play’
Expected Results
The function is called and the effect (an Alert) is fired
Snack, code example, screenshot, or link to a repository:
https://snack.expo.io/@razorshnegax/6c7be3
Code example:
import React from 'react';
import { View, Pressable, Image, Alert } from 'react-native';
export default class Index extends React.Component {
render() {
// The onPress function fires in iOS, but not android
return (
<View>
<Pressable onPress={() => {Alert.alert("Yeep")}}>
<Image source={require('./greatknight.png')} style={{
// So that the image is more centered
top: 100,
left: 100
}}/>
</Pressable>
</View>
);
}
}
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:5
Top Results From Across the Web
Pressable not working in react-native android - Stack Overflow
Open a new expo snack · Create a Pressable component that is the parent of some other component (A text or image) ·...
Read more >Please tell me why my Pressable simple code is not working
Please tell me why my Pressable simple code is not working. I've tried even alerting or consoling logging without the handlePress function. What ......
Read more >Pressable - React Native
Pressable is a Core Component wrapper that can detect various stages of press interactions on any of its defined children.
Read more >Why We Should Use Pressable In React Native
Every React Native developer is familiar with Touchable components. As a React Native developer, you've probably visited the documentation ...
Read more >How to use Pressable Component in React Native - YouTube
Facebook's React Native user interface (UI) design which is designed to support IOS and Android OS both platforms. React Native allows ...
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
Yes, @RicardoBrito1938. Turns out that the positioning of the pressable is skewered in android. All you need to do is set the Pressable’s style to whatever position you want the child’s (an Image’s, so to say), and then set the child’s postion to top: 0, left: 0, position: relative. The pressable then should work. Here is the link to my stack overflow post if you need reference. I can add a snack example if you need more help,
Code example would be really helpful.