fix: restart animations when image starts loading #84
+5
−6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
closes #83
The reason why a new source url that resolves to the same cache key hides the image is because the opacity is set to 0 when calling
resetAnimations
react-native-image-cache/src/CachedImage.tsx
Lines 130 to 134 in 644fbda
And
resetAnimations
is called when the source prop changesreact-native-image-cache/src/CachedImage.tsx
Lines 90 to 93 in 644fbda
However the image only shows up when the image has loaded
react-native-image-cache/src/CachedImage.tsx
Lines 156 to 168 in 644fbda
Now the problem is that since the source url resolves to the same cache key, the image will not load since it is already loaded and the opacity is never set back to 1, leaving the source image invisible even though it is loaded.
Since we animate the opacity back on image load, then it makes sense to reset the animation on image load start and not when the source url prop changes.
Here is the outcome after this change compared to the one showed in the issue. The difference here is that the image stays rendered after the url changes
Simulator.Screen.Recording.-.iPhone.15.-.2024-07-17.at.09.38.54.mp4