I am trying to display a modal when a list item is clicked. I set the state to false initially, then when a list item is clicked it sets the setModalVisible state to true and the modal should display. However, even though the state is true, checked by debugging, the modal does not display.
Initial State
this.state = {
setModalVisible: false,
};
Render List Item and toggle onPress
renderItem(item) {
return (
<ListItem bottomDivider={true}
onPress={() => this.showModal(item)}>
<View style={{flex: 1}} margin={5}>
<Avatar margin={5} rounded source={{uri: item.logo_url}} />
<View style={{flexDirection: 'row'}}>
<Text margin={50}>{item.rank}</Text>
<Text margin={50} style={styles.cryptoTitle}>
{item.name}
</Text>
<Text style={styles.cryptoPrice}> {'$' + item.price} </Text>
</View>
</View>
</ListItem>
);
}
Show Modal Function
showModal(item) {
this.setState({setModalVisible: true});
return (
<View>
<Modal
animationType="slide"
visible={this.state.setModalVisible}
onRequestClose={() => {
this.setState({setModalVisible: false});
}}>
<Text> Modal is Visible !</Text>
</Modal>
</View>
);
}