Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native Image prefetch doesn't take headers

Tags:

react-native

According to the doc, the current prefetch method doesn't consider headers as same as . Does anyone know wether this is going to be fixed when the API is completed?

like image 904
Bunnyc1986 Avatar asked Jan 30 '18 13:01

Bunnyc1986


People also ask

How do you store image in cache in react-native?

For the logic of our custom image caching component, we'll import expo-file-system : import * as FileSystem from "expo-file-system"; First, we need to create a new local path for our remote image using the cacheKey (unique ID) to check whether it already exists in the local cache and, if not, download it.


1 Answers

Hope it's not too late, I faced this issue before, and currently the prefetch method still not take any headers.

I found out there's a method in Image class named getSizeWithHeaders, base on the description:

In order to retrieve the image dimensions, the image may first need to be loaded or downloaded, after which it will be cached. This means that in principle you could use this method to preload images

So if you use this method, it did prefetch the Image with headers for you, which fulfill your requirement even it's not optimized.

Looks like this is the only method to solve this, please correct me if there's any optimized method or library.

like image 63
jiale ko Avatar answered Oct 21 '22 11:10

jiale ko