Reputation: 595
I have 3 simple react components-
First the actual view(let us name this screen A)-
return(
<ImageBackground
...
>
<ScrollView>
<ChildButton
onPress={this.someFunction.bind(this)}
/>
</ScrollView>
</ImageBackground>
)
Then there is the ChildButton component---
return(
<ChildButton>
<Button
style={...someStyleObject}
onPress={this.props.onPress}
>
</Button>
</ChildButton>
)
and then there is Button component ---
return (
<TouchableOpacity
onPress={this.props.onPress}
>
{this.props.children}
</TouchableOpacity>
)
The main problem here is my onPress is not getting called from screen A, only on Android. It is working fine on iOS. What are the possible causes here?
Note: I've put consoles inside ChildButton and Button component and they are not getting printed.
Upvotes: 8
Views: 5318
Reputation: 29
import {TouchableOpacity} from 'react-native'
works fine in both android and iOS
import {TouchableOpacity} from 'react-native-gesture-handler'
Does not work in android, but works in iOS.
So better to user react-native imports.
onPress event is not calling in android if TouchableOpacity imported from react-native-gesture-handler.
Upvotes: 2
Reputation: 1416
I also ran into this issue when I inherited a RN project in progress. I didn't realize we had this "react-native-gesture-handler" package installed and accidentally let VS Code auto import it.
Always check your imports! :)
Upvotes: 3
Reputation: 714
I ran into this issue when I accidentally imported TouchableOpacity
from "react-native-gesture-handler" instead of from "react-native". If this is the case for you, change so TouchableOpacity
is imported from "react-native" and remove the import from "react-native-gesture-handler" and it should work!
Upvotes: 14