[英]Image fails to render after successful fetch in React native
I'm attempting to render an image that is the result of a successful fetch. 我正在尝试渲染成功获取的图像。
It seems fairly simple and everything works, except the picture fails to render. 看起来相当简单,并且一切正常,除了图片无法渲染。
In my constructor: 在我的构造函数中:
constructor(props) {
super(props);
const deliveryManPic = Config.images.deliveryManPic;
this.state = {
callModal: false,
beepModal: false,
pictureForBackground: null,
finished: deliveryManPic,
secondPic: null,
};
this.batteryLevelIndicator = '';
this.pictureUrl = 'someURL';
}
In my ComponentWillMount: 在我的ComponentWillMount中:
componentWillMount() {
const urlForPicture = this.pictureUrl;
apiService.getPicture(urlForPicture, (res) => {
if (res !== null) {
// console.log('here is your response', res);
this.setState({ pictureForBackground: res, });
} else {
loggingService.debug('theres been a problem');
}
});
}
Finally, inside my render method: 最后,在我的render方法中:
<View style={styles.deliveryGuyView}>
<Image
resizeMode="cover"
style={styles.policeCarIcon}
defaultSource={{ uri: this.state.finished }}
source={{ uri: this.state.pictureForBackground }}
onLoadEnd={() => {
console.log('pic has finished loading');
}}
/>
</View>
I don't see any yellow messages or errors in the console.log, but I don't see the picture that was successfully fetched. 在console.log中没有看到任何黄色消息或错误,但是没有看到成功获取的图片。 What could be the reason the picture fails to render? 图片无法渲染的原因可能是什么?
我忘了在PoliceCarIcon样式对象内添加高度和宽度。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.