Reputation: 362
Can some help me with this issue. On press not working in Flatlist render function. here my code. i checked other screens touch case working fine but when i try it in Flatlist it's not working
render(){
return (
<View style={styles.container} >
<FlatList
data={this.state.categories}
numColumns={2}
keyExtractor={item => item.id}
renderItem={item => this.renderItem(item)}
/>
</View>
);
}
renderItem = ({item,index}) => {
return (
<TouchableOpacity onPress={() => this.moveToLocation(item.id)} style={styles.items}>
<Image source={{uri:item.img}}
resizeMode="center"
style={styles.itemsimg} />
<Text style={{textAlign:'center',fontSize:20, }} onPress={() => this.moveToLocation(item.id)}>{item.name}</Text>
</TouchableOpacity>
);
}
Upvotes: 7
Views: 5638
Reputation: 1817
For me, I just imported TouchableOpacity
from react-native-gesture-handler
instead of react-native
and I got it work
import { TouchableOpacity } from "react-native-gesture-handler";
Upvotes: 0
Reputation: 193
if onPress is not workingin the flatlist's render method try using onTouchStart method of the components if they have in the flatList's render method.
Upvotes: 1
Reputation: 180
You need to wrap your row element (inside your renderItem method) inside tag. TouchableWithoutFeedback takes onPress as it's prop where you can provide onPress event.
For TouchableWithoutFeedback refer https://facebook.github.io/react-native/docs/touchablewithoutfeedback.html
Upvotes: 3