【发布时间】:2019-08-16 10:15:40
【问题描述】:
我从图像具有实时链接的 api 接收 JSON 数组。所以,在我渲染数据成功后,问题是我想显示一个 gif,直到图像完全加载。
数组是:-
[{
"category": "Loose Flower",
"id": "7",
"product_name": "Drb,Tls,Blpt,Nlknt",
"unit_price": "0",
"img_path": "http://prabhujionline.com/bo/upload/product_img/1513948635octa_pooja_basket_w_handle6_580x@2x.jpg",
"count": 0,
"is_loaded": true
},
{
"category": "Loose Flower",
"id": "1",
"product_name": "Genda",
"unit_price": "0.5",
"img_path": "http://prabhujionline.com/bo/upload/product_img/1513947159genda.png",
"count": 0,
"is_loaded": true
}]
<Image
style={{ height: 212 / 3, width: 300 / 3, borderRadius: 5 }}
source={(this.state.singlepack.is_loaded) ? { uri:
this.state.singlepack.img_path } :
require('../../../../assets/flower-loader.gif')}
onLoadStart={(e) => {
this.changeImageLoadStatusOnStart(this.props.singleData.id) }}
onLoadEnd={(e) =>
this.changeImageLoadStatusOnEnd(this.props.singleData.id) }
/>
changeImageLoadStatusOnStart = (id)=>{
this.setState({
singlepack: {
...this.state.singlepack,
is_loaded : false
}
})
}
changeImageLoadStatusOnEnd = (id) => {
this.setState({
singlepack: {
...this.state.singlepack,
is_loaded: true
}
})
}
我已经尝试过 onLoadStart 和 onLoadEnd 但我无法做出逻辑,我可以帮忙吗?
【问题讨论】:
-
我仍然希望有一个解决方案。由于 defaultSorce 和 loadingIndicatorSource 无法正常工作。
标签: react-native reactive-programming