How React Native Image.prefetch works?

Can somebody explain me, how RN Image.prefetch works? I've read docs and example, but I can't get, what happens there.

  • When we prefetch image once, will it be loaded from the cache automatically, when I want to use it some where else or I need to do some checks manually?

  • When I need to call Image.prefetch method: before image rendering in componentWillMount for example or after image loading in loadEnd callback, like it's shown in docs example?

  • Thanks in advance for your answers.


    Example given in docs seem confusing but is quite straightforward actually. You prefetch images ahead, and when you want to display them just use Image component like usual. For example during some initial scene you can display ActivityIndicator while you prefetch all images, once is all done just show images like you would without prefetch in place.

    To answer your questions:

  • Image will be loaded from cache automatic, no manual check needed. Make sure not to unmount/mount again scene that does prefetch as it will start loading images again.
  • Before image rendering, best in some scene before as image is rendered when scene that shows it is rendered. You can use onLoadEnd to know when to show next scene. You may use componentWillMount to do prefetch, just render something else like ActivityIndicator while prefech is completed, once done render image.
  • Hope it helps.

    链接地址: http://www.djcxy.com/p/93988.html

    上一篇: 长COMMIT持续时间,Postgres 9.1中的高I / O等待

    下一篇: React Native Image.prefetch如何工作?