Reputation: 1687
Hello I have this Lisview and on the renderRow I have this return statement :
<TouchableHighlight onPress={this._onPressWidget(rowData)}>
<View>
<View style={style}>
<Text style={styles.text}>
{rowData}
</Text>
</View>
</View>
</TouchableHighlight>
The thing is that the onPress function is launched automatically without pressing the button. Can anyone tell me why is that? I'm doing this with react native
Thank you in advance!
Upvotes: 1
Views: 517
Reputation: 91
seriously save my hours!! thx a lot. I should share the tips here:
let returnView = this.props.item.map((v,i ) => {
return <TouchableHighlight onPress={() => this._fireEventToParent(v.id)}>
<View style={ListItemStyles.liPiece}>
<Image style={[ListItemStyles.liPieceImage} source={{uri: v.itemImage }} />
<Text style={ListItemStyles.liPieceTxt}>{v.itemName}</Text>
</View>
</TouchableHighlight>;
});
only map can work here, I tried forEach, cannot work.
Upvotes: 0
Reputation: 35890
You are calling the _onPressWidget
during rendering. What you need to do is pass a callback function that calls it, once the callback executes.
<TouchableHighlight onPress={() => this._onPressWidget(rowData)}>
Upvotes: 2