kfiroo / react-native-cached-image

CachedImage component for react-native
MIT License
940 stars 468 forks source link

Changes in v1.4 vs v1.3 #99

Open jose920405 opened 6 years ago

jose920405 commented 6 years ago

Hi, Thanks for this module it has been very helpful.

In v1.3 version i was using a lot getCachedImagePath and cacheMultipleImages.

When updating to the new version v1.4 I found that in the readme these options do not exist anymore. What would be the equivalences for these functions? I wish I did not have to make many changes in my logic on this.

chrusart commented 6 years ago

ImageCachePreloader.preloadImages, don't konw about getCachedImagePath replacement

kfiroo commented 6 years ago

@jose920405 What were you using getCachedImagePath for?

jose920405 commented 6 years ago

i'm using getCachedImagePath for offline logic, converting the images in that patch to base64 and load to a canvas

kfiroo commented 6 years ago

When you are offline and the image is already cached, CachedImage will load and display it, why are you doing this manually?

jose920405 commented 6 years ago

But i'm not loading a image inside render in a react component. I'm try to render the image inside a CANVAS. And in my canvas i'm receiving base64 image data. That is the reason for use getCachedImagePath and convert the image to base64

kfiroo commented 6 years ago

@jose920405 I got it! Thanks! So you should use ImageCacheManager.downloadAndCacheUrl This method will return the path to the local file.

mik-rom commented 6 years ago

@kfiroo I'm getting undefined is not a function when trying to use this function

import { CachedImage, ImageCacheManager } from 'react-native-cached-image'

ImageCacheManager.downloadAndCacheUrl(this.props.source.uri)
      .then((imagePath) => {
        if(Platform.OS === 'android') {
          imagePath = 'file://' + imagePath
        }
        this.setState({renderAnimated: false, imagePath: imagePath})
      })
      .catch(() => {
        this.setState({renderAnimated: true})
      })

TypeError: _reactNativeCachedImage.ImageCacheManager.downloadAndCacheUrl is not a function

Before this update I used ImageCacheProvider.getCachedImagePath and it worked without an error.

Any ideas?

esamelson commented 6 years ago

@rom1k I just ran into the same issue. It looks like there was another change in 1.4 that was not documented - ImageCacheManager seems to be a factory. This worked for me:

import { ImageCacheManager } from 'react-native-cached-image'
const manager = ImageCacheManager({})
manager.downloadAndCacheUrl(...)
jose920405 commented 6 years ago

cacheMultipleImages now is?