有个需求需要加载网络数据的时候显示加载中,然后请求结束后显示modal,伪代码如下,为什么在数据请求回来之后setstate重新render无法显示modal呢?
render: function() {
if (!this.props.data) {
return (<View style={{flex:1}}>
<Text>loading</Text>
</View>);
}
return (
<View style={{flex:1, width:screenWidth}}>
<Modal
visible={true}
transparent={true}
onRequestClose={()=>{
}}
onShow={()=>{
}}>
<View
style={{flex:1,justifyContent:'center',alignItems:'center',backgroundColor:'rgba(0, 0, 0, 0.3)'}}>
<View style={{height:200,width:275,backgroundColor:'white'}}>
<Button title='confirm' onPress={()=>{}}/>
<Button title='cancel' onPress={()=>{}}/>
</View>
</View>
</Modal>
</View>
);
}