react-native-image-cache-hoc icon indicating copy to clipboard operation
react-native-image-cache-hoc copied to clipboard

[Improvements] Request headers, filename, rejection callback

Open stinodes opened this issue 6 years ago • 0 comments

Hi there,

I forked your library for a project and added some (in my case) improvements:

  • Component takes a headers-property (needed for authorization headers in my specific case)
  • Component takes a fileName-property (I did not have the filename in the URL, and fetching the extension can slower than is desirable)
  • Component takes a rejected-component, similar to the placeholder that has already been implemented
  • Component takes a onRejected-property that gets called when fetching the image fails.

These additions should be perfectly backwards compatible.

Additional changes I want to implement in my fork, but would not be backwards-compatible:

  • Changing the placeholder props and options into a more standard pattern (slots or render-function)
    <CacheableImage
       placeholder={
         <Spinner />
       }/>

or

    <CacheableImage
      placeholder={
        () => <Spinner/>
      }/>
  • I was thinking of maybe changing up the code somewhat so the library could be changed to export both a FAC- and a HOC-component, but this would require some larger rearrangements of code. I feel this would make the library more flexible for advanced users. FAC-example
    <CacheableImage
      source="my.resource.com">
      {({pending, source, isRejected}) => 
        pending ? 
          <Spinner/> : 
          <Image source={source}/>
      }
    </CacheableImage>

I can totally make a pull request (or two!) for these, so they can be merged and published under this package, if those changes are something you see fitting here!

Cheers!

stinodes avatar Aug 10 '18 07:08 stinodes