software-mansion / react-native-svg

SVG library for React Native, React Native Web, and plain React web projects.
MIT License
7.34k stars 1.11k forks source link

`prefetch` or `onLoad` for <Image /> #2073

Open scnroy opened 1 year ago

scnroy commented 1 year ago

Hi all!

I'm using react-native-qrcode-svg, which uses this package under the hood.

I'm rendering a logo in the middle of the QR Code via require('./logo.png'). The QR code appears on a receipt layout, which is captured as an image via react-native-view-shot se we can either email it and/or send to a printer. This works great, however there is a race condition between capturing the screen shot and loading the logo image. I've been hunting for something like <Image/>'s onLoad event handler, and have also tried using Image.prefetch() without much success—perhaps because it's a local image?

Is there any way to know when the image is done loading or prefetch the image so that it renders on first pass when using your image component? I'd be happy to submit a PR to react-native-qrcode-svg, assuming we'd need to make the underlying API available.

Thanks!

bohdanprog commented 1 week ago

Hello @scnroy, Currently, we are working on the implementation onLoad prop to the image component. Here is PR