ReactNative Image | setNativeprops 无法更改源代码



我已经为网络图像实现了图像onError方法,并且错误地尝试使用默认图像更新视图,但源属性不起作用

onLoadError=(event)=>{
alert('Img load error');
this.imgPayIcn.setNativeProps({
source :{uri:'https://facebook.github.io/react/img/logo_og.png'} //not able to update view with new image... no effect

});

呈现方法

<Image ref={(ref) => this.imgPayIcn = ref} source={this.props.source} style={{height:50,width:50}} resizeMode='cover' onError={this.onLoadError}/>

将图像包装在处理错误的组件中:

class ImageWithFallback extends Component {
state = {
failed: false,
}
render() {
if (this.state.failed) {
return <Image source={require('imageFallback.png')} />
}
return <Image {...this.props} onError={() => this.setState({ failed: true })} />
}
}

最新更新