所以,我有一个上传功能,可以上传一张图片。有时(大约 50% 的时间)在图片上传后,会显示默认图片并调用 onError 方法。但是,由此产生的事件并没有提供任何关于出了什么问题的见解。
显示代码是这个
renderImage(){
const { photos, photoDir, onShowPhotoModal } = this.props;
const item = photos.get(0);
return (
<TouchableHighlight onPress={onShowPhotoModal}>
<Image
defaultSource={require('../../styles/images/default-post-image.png')}
resizeMode={Image.resizeMode.cover}
style={[styles.cardContentPhoto, localStyle.photo]}
source={{uri : this.state.imageUrl}}
onError={this.tryOneMoreTime}
/>
</TouchableHighlight>
);
}
render() {
const { loadNow, photos, onShowPhotoModal } = this.props;
const { index } = this.state;
if(photos.size === 0)
return null;
return (
<View>
<View style={localStyle.container}>
{this.renderImage()}
</View>
<CirclesIndicator length={photos.size} activeIndex={index}/>
</View>
);
}
如果我以模式打开图像然后返回,它会正确显示,但如果我尝试加载相同的图像并在调用错误事件几秒钟后强制重新渲染,使用随机 url,它仍然没有t 出现。
tryOneMoreTime(evt){
const { photos, photoDir, onShowPhotoModal } = this.props;
dbg(`Something went wrong loading image ${photoDir}/main_${photos.get(0).filename}`, evt);
if(this.state.tries === 0)
setTimeout(() =>
this.setState({
tries : 1,
imageUrl : utils.photoUrl(photoDir, photos.get(0).filename, 'main', true)
}), 2000);
}
在 iOS 模拟器上测试,RN 0.38.1
有任何想法吗?