react-native-auto-height-image icon indicating copy to clipboard operation
react-native-auto-height-image copied to clipboard

Image caching?

Open xgenem opened this issue 5 years ago • 7 comments

Is your feature request related to a problem? Please describe. We're using the plugin in a Modal which loads the images from a URI based on the image clicked on a slider. However, every time I click on the same image, it loads the image again from the source.

Describe the solution you'd like Cache the image so the next time the resource image is accessed, it will be from cache. OR at least set something like 'only-if-cached' from React Native Image.

xgenem avatar Jul 06 '20 09:07 xgenem

Approach:

  1. Support Cache Control. https://reactnative.dev/docs/images#cache-control-ios-only
  2. Support cache for image resources. https://github.com/wcandillon/react-native-img-cache, https://github.com/DylanVann/react-native-fast-image

vivaxy avatar Jul 06 '20 12:07 vivaxy

I didn't do anything proper because I want to stop working on this, but this might be useful: https://github.com/vivaxy/react-native-auto-height-image/compare/master...mrexodia:proper-cache

I tested and it currently hits the server twice (which can be improved), but it's already much better than whatever crappy caching Image implements.

mrexodia avatar Jul 23 '20 20:07 mrexodia

Hi, you can try react-native-auto-height-fast-image2, I repalce default <Image/> replace to react-native-fast-image, support cache control.

alantoa avatar Dec 15 '21 03:12 alantoa

@alantoa Thank you for this, I truly needed the caching to autoHeight. However I am confused, the link you provided for react-native-auto-height-fast-image2, although its url is directed at your library, it seems that the whole description, even the installing steps are calling the original react-native-auto-height-image?

So how can I install your library rather than the original one, and how do I call yours instead of the original? (I'm sorry if the question seems silly, Github and npm clearly aren't my strength)

pierroo avatar Feb 23 '22 12:02 pierroo

@pierroo You don't need this lib anymore, there are better solutions now.

import FastImage from "react-native-fast-image"

const AutoHeightImage = React.memo(function AutoHeightImage ({ width, ...props }: ImageProps) {
  const [state, setstate] = React.useState(0)
  return (
    <FastImage 
      {...props}
      style={{ width: width, height: state }}
      onLoad={(evt) => {
        setstate((evt.nativeEvent.height / evt.nativeEvent.width) * width)
      }}
    />
  )
})

Simple to use:

<AutoHeightImage width={300}  />

alantoa avatar Feb 23 '22 13:02 alantoa

@alantoa Quite amazing, it actually works perfectly, thank you so much! :)

pierroo avatar Feb 23 '22 13:02 pierroo

@alantoa Quite amazing, it actually works perfectly, thank you so much! :)

You're welcome!

alantoa avatar Feb 23 '22 13:02 alantoa