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

Feature request: avoid displaying placeholder when the picture is already in cache #121

Closed
Elindorath opened this issue Feb 13, 2025 · 3 comments · Fixed by #123
Closed
Assignees
Labels
enhancement New feature or request

Comments

@Elindorath
Copy link

Hello there,

I tested to use expo-image to take advantage of the cache. By doing so, I was expecting to see the placeholder only the first time the pictures are loaded. But this is sadly not the current behaviour, the placeholder is always shown no matter the situation.

If I understand correctly the implementation, the following is occurring:

  • On mount:

    1. Fetch inspect query
    2. Display placeholder
  • When visible (or eager):

    1. Wait 100ms
    2. Fetch the picture (or get a cache hit)
    3. When loaded, hide the placeholder using the defined timing animation

This means that under the best circumstances, the minimum time before we can effectively see the picture is 100ms + transitionDelay + transitionDuration (neglecting the overhead induced by rendering cycles). I don't fully understand why this arbitrary 100ms is present. But I think we could leverage the getCachePathAsync(cacheKey: string) method from expo-image (even the queryCache(urls: string[]) one from react-native's Image) to optimize this time depending on the case.

What do you think?

I would enjoy to work on a PR but I lack context about implementation design decisions.

@mbgspcii mbgspcii self-assigned this Feb 13, 2025
@mbgspcii mbgspcii added the enhancement New feature or request label Feb 13, 2025
@mbgspcii
Copy link
Collaborator

Hi @Elindorath.

You’re right, there’s no need to display the placeholder if the image is already cached. We’re currently looking into the best way to handle this case.

For the debounce, it helps avoid generating excessive requests when the user resizes their viewport (as shown in the video).

That being said, this feature doesn’t make sense for iOS and Android. We’ve modified it in version 0.31.4 of the components.

If you test it, you should notice that the previously observed latency is no longer present.

Hoping this helps.

Regards.

mbgspcii added a commit that referenced this issue Feb 16, 2025
@Elindorath
Copy link
Author

Thanks a lot!

That being said, this feature doesn’t make sense for iOS and Android.

Just to make sure you had it in mind: there might be a case that make sense, when switching from portrait to landscape mode, and vice versa.

We'll update to v0.31.4 during the first half of this week, I'll let you know.

@mbgspcii mbgspcii linked a pull request Feb 17, 2025 that will close this issue
mbgspcii added a commit that referenced this issue Feb 17, 2025
* Avoids displaying the placeholder if the image is in cache on iOS and Android in React Native. #121

* fix: adds miising CachePolicy validation.

* Adapts React-Native lazy-loading to handle cached images.

* Adds a debounce function in React-Native to compute ViewportBox on window size change.

* Updates CHANGELOG.
@mbgspcii
Copy link
Collaborator

Hi @Elindorath.

We have just released version 0.32.0 that improves the cache handling: no more placeholder when an image has been cached.

We sincerely hope this enhancement will improve your experience and makes image loading more efficient. As always, feel free to provide any feedback or suggestions.

Regards.

PS: thanks for suggesting this excellent idea! It really helped us improve the TwicPics Components.

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

Successfully merging a pull request may close this issue.

2 participants