Image preloading in React Native -


i building first app react native, app long list of images. want show spinner instead of image while image loading. sounds trivial didn't found solution. think spinner suppose use activityindicatorios , how combining image component?

<image source={...}>   <activityindicatorios /> </image> 

is right direction? missing something?

just ran same issue. have correct approach, indicator should of course rendered when image loading. keep track of need state. keep simple assume have on image in component keep state in same component. (the cool kids argue should use higher order component , pass state in via prop ;)

the idea is, image starts out loading , onloadend (or onload, spinner gets stuck on error, fine or course) re-set state.

getinitialstate: function(){ return { loading: true }}  render: function(){     <image source={...} onloadend={ ()=>{ this.setstate({ loading: false }) }>         <activityindicatorios animating={ this.state.loading }/>     </image> } 

you start out { loading: false } , set true onloadstart, i'm not sure benefit of that.

also styling reasons, depending on layout, might need put indicator in container view absolutely positioned. idea.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -