ascoders / react-native-image-viewer

🚀 tiny & fast lib for react native image viewer pan and zoom
MIT License
2.44k stars 577 forks source link

Support custom download logic by client #440

Open mortend opened 3 years ago

mortend commented 3 years ago

This makes it possible for clients to implement their own download logic and provide a local URL to the image once the download is complete.

This is useful when authorization is required to access images, or any scenario where public URLs to your images aren't available.

Usage

  1. Client sets image.url to empty string as a placeholder.

  2. Client implements props.onLoad(index, callbacks) like so:

    async onLoad(index, callbacks) {
        try {
            const url = "file://" + (await downloadImage(index))
            callbacks.onLoaded(index, url)
        } catch (e) {
            callbacks.onFailed(index)
        }
    }
  3. Rock'n'roll!