在发送另一个Alert.alert()之前,有没有办法判断屏幕上是否已经出现了这个the ()?
我有这个函数:
CheckInternet(){
if(this.props.json.undefined){
Alert.alert("Check your internet connection");
}
}
ComponentDidUpdate(){
this.CheckInternet();
}问题是我在这个函数中做了其他的事情,我只是写了相关的代码,所以我不能在ComponentDidUpdate之外使用CheckInternet函数。
问题是组件在获得json后会更新两次,因此会发送两次警报。我想通过使用一个条件来防止同时出现两个警报,该条件可以让我知道屏幕上是否已经有警报。我似乎在Alert文档中找不到任何类似的东西。有什么想法吗?
发布于 2017-03-03 08:57:05
试试这个:
CheckInternet(){
if (!this.alertPresent) {
this.alertPresent = true;
if (this.props.json.undefined) {
Alert.alert("", "Check your internet connection", [{text: 'OK', onPress: () => { this.alertPresent = false } }], { cancelable: false });
} else {
this.alertPresent = false;
}
}
}
ComponentDidUpdate(){
this.CheckInternet();
}https://stackoverflow.com/questions/42567063
复制相似问题