jayesbe / react-native-cacheable-image

An Image Component for React Native that will cache itself to disk.
MIT License
304 stars 78 forks source link

Any way for caching image manually #66

Open jose920405 opened 6 years ago

jose920405 commented 6 years ago

Any function for caching image by code.?

gtjamesa commented 6 years ago

If you look through the source you can see that the cache image name is as follows:

const url = new URL(source.uri, null, true);
const type = url.pathname.replace(/.*\.(.*)/, '$1');
const cacheKey = SHA1(cacheable) + (type.length < url.pathname.length ? '.' + type : '');

Where cacheKey is the cached filename. You can then use RNFS.downloadFile() to download from a source URL and save as cacheKey.

I'm making some changes to the local on my forked repository, if I get time I'll add a method to download and cache an image without having to display it.