I am receiving a JSON array from an api where images have a live link. So, after the success I am rendering the data, problem is I want to show an gif until the images load completely.
The array is:-
[{
"category": "Loose Flower",
"id": "7",
"product_name": "Drb,Tls,Blpt,Nlknt",
"unit_price": "0",
"img_path": "http://prabhujionline.com/bo/upload/product_img/[email protected]",
"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
}
})
}
I have tried the onLoadStart and onLoadEnd but I am unable to make the logic, can I have some help?