Reputation: 25
I'm trying to press on a row in the FlatList and make the app navigate to another page, and I'm trying to do this without creating new methods for each render.
Using React I would just get the value from event.target
but I'm having trouble doing this in react native
Here's what I have so far:
constructor(props){
super(props)
this._renderListItem = ({ item }) => this.renderListItem(item)
this._onPressListItem = () => this.onPressListItem()
}
onPressListItem() {
// Right here I need to know which row I pressed
this.props.navigation.navigate('ChatScreen', {})
}
renderListItem(item) {
return (
<TouchableNativeFeedback onPress={this._onPressListItem}>
<View style={{ height: 50, backgroundColor: 'red' }}>
<Text>{item.name}</Text>
</View>
</TouchableNativeFeedback>
)
}
Upvotes: 0
Views: 164
Reputation: 2927
In render part you just need to define the item when press TouchableNativeFeedback like this
renderListItem(item) {
return (
<TouchableNativeFeedback onPress={()=>{this._onPressListItem(item)}}>
<View style={{ height: 50, backgroundColor: 'red' }}>
<Text>{item.name}</Text>
</View>
</TouchableNativeFeedback>
)
}
And then you can find out which particular row as been clicked
onPressListItem(items) {
console.log(items)
}
In console you will get the value for that par item pressed in the row try may be this can help you
Upvotes: 1