Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update known-issues.md #712

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

karlazzampersonal
Copy link

@karlazzampersonal karlazzampersonal commented Dec 16, 2022

Description

I had an issue using FlashList with image components not rendering the correct image the first time that item renders as you scroll down or up. The fix is in the readme, its to display a white image until the correct Image URI renders.

I encountered this issue and received help from one of the shopify devs. I wanted to add it to the list of known issues as recommended by one of the shopify devs since this is an issue everyone who uses iOS will have with a similar use case of rendering images in a FlashList

Screenshots or videos (if needed)

Flickering before wrapping Image in RecyclableImage: (You can see the bar Gray Dog's img didn't render correctly at first)

trim.5F19E121-554C-463C-AE7C-873686D55D9E.mov

No flickering after wrapping Image in RecyclableImage:

RPReplay_Final1671156566.mov

Comment on lines +39 to +40
When you scroll down a FlashList of components containing images, on iOS it will show the incorrect image and flicker to the correct image once the correct URI is loaded. To avoid this, you need to check if the URI ref of the current item rendering is the URI of the image you want to render. If it is not, then you need to render a blank image and then render the correct image once the URI is loaded. An example
of this is shown on this [gist here](https://gist.githubusercontent.com/naqvitalha/f13772b7bc5d361fb95cdd008f47042b/raw/41992420e40512ce10ea6189fea4a71b43cf020e/RecyclableImage.tsx).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't include this as a known issue as we can't fix this as it's fundamentally tied to the recycling mechanism which is what makes FlashList fast. I'd instead add a note about this in the Recycling documentation section.

@LinusU
Copy link

LinusU commented Jan 18, 2023

@karlazzampersonal did you try using defaultSource to work around this? From reading the documentation it feels like that should switch to that image whilst loading the next one 🤔

edit: I cannot get neither defaultSource or loadingIndicatorSource to work at all, at least in Expo 🤷‍♂️

I worked around this by adding a key that is the image url to the <Image />, that way a new component is forced when the uri changes and the old image is thus not shown...

@hirbod
Copy link
Contributor

hirbod commented Feb 27, 2023

@karlazzampersonal, I looked into that issue with @tsapeta and the new expo-image library (which replaces react-native-fast-image and react-native's default Image) - and it also works on the web.

This library has special treatment for recycling, with a new prop called recyclingKey that can be passed to the Image component. This will take care of resetting the image on the native side (because usage of key in your component would break recycling). I highly recommend this library, as it's currently the best image solution for React Native.

https://docs.expo.dev/versions/unversioned/sdk/image/#recyclingkey

And before you ask: it also works without Expo, you just need to install the core (which adds only 150KB overhead to your final app bundle, in case you're worried).

BTW, it is the only library in the ecosystem so far that handles this correctly.

Might also be interesting for you @LinusU

@LinusU
Copy link

LinusU commented Feb 28, 2023

@hirbod that sounds great! I've been eyeing expo-image anyways so that would be a great solution for us 🚀

I think that it would be nice to get this into the known-issues document anyhow, mentioning expo-image and recyclingKey specifically...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants