Preloading local images used via require() fails
See original GitHub issueSometimes with even local images take a short while to load, particularly if there are many images composing full ui i.e. games.
I thought using .preload
method on my local images could elevate some bottlenecks, but following errors
export default function preloadImages() {
FastImage.preload([
require('../assets/images/dwarf.webp')
])
Whenever I call preloadImages
I receive following error
Exception ‘-[__NSCFNumber objectForKeyedSubscript:]: unrecognized selector sent to instance 0xf4263c55c59de1d2’ was thrown while invoking preload on target FastImageView with params ( ( 1 ) )
I assume this number 1
relates to me using require. Should this be supported as part of preload or is this issue irrelevant?
Issue Analytics
- State:
- Created 5 years ago
- Comments:11
Top Results From Across the Web
How to preload images in React.js? - Stack Overflow
First one has nice API easy to understand and use ,but is spaming console with warning that images were not loaded even when...
Read more >How to Preload Images into Cache in React JS | by Jack P
This function will take in an image array as an argument and will loop through the array with Map. In each iteration, the...
Read more >3 Ways to Preload Images with CSS, JavaScript, or Ajax
Three easy ways to preload images using either CSS, JavaScript, or Ajax - an excellent way to speed things up and boost site...
Read more >Preloading responsive images - web.dev
The problem with CSS background images is that they are discovered by the browser only after it has downloaded and processed all the...
Read more >Preloading and the JavaScript Image() object - TechRepublic
Some browsers try to mitigate this problem by storing the images in the local cache so that subsequent calls to the image are...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I found a small hack-around for this by doing following, not sure how I feel about it yet nor what performance implications of this method could be, but we can get
uri
fromrequire
by using react-native’sImage.resolveAssetSource
You can then use
<FastImage source={require('../assets/images/graphic1.webp')} />
and image is actually already preloaded. I can see good improvement in my app, memory is not spiking, so I assume it caches to disk not ram?Solution above works very well for me, only wishing for a callback on
preload
to know when images have loaded