Image size get from onLoad() event is incorrect on Android
See original GitHub issueThe width
and height
get from onLoad()
event is incorrect on Android. It shows 720x1192 (depends on the screen size) for below example code on Android, and it works fine on iOS (400x400).
"react-native": "^0.59.3",
"react-native-fast-image": "^5.3.0"
onLoad = (evt) => {
console.warn(evt.nativeEvent);
}
...
<FastImage
onLoad={this.onLoad}
source={{
uri: 'https://unsplash.it/400/400?image=1'
}}
style={styles.image}
/>
...
full example project can be found at: https://github.com/rocwind/fast-image-test
Issue Analytics
- State:
- Created 4 years ago
- Reactions:13
- Comments:22
Top Results From Across the Web
Getting image width on image load fails on IE - Stack Overflow
On every image load a call this function with image and resize if its width or height is bigger than my max width...
Read more >Slow rendering - Android Developers
Ensure that the bitmap being displayed isn't significantly bigger than the area on screen it's showing in. If it is, that wastes upload...
Read more >Window: load event - Web APIs - MDN Web Docs - Mozilla
The load event is fired when the whole page has loaded, including all dependent resources such as stylesheets, scripts, iframes, and images.
Read more >Issue 67413 in chromium: get image size in img onload function
My case is related to this issue I think: Essentially javascript detect a wrong width of an image loaded from cache. ... 2)...
Read more >'onload' event is not fired if HTTP Content-Length is invalid.
At first, I completely agree that it is a sever's wrong behavior. Instead of that, Chromium is trying hard to render the contents,...
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
same issue on android. ios working fine. RN 0.62.2
the
onLoad
function is just passed down to thereact-native
Image component so the issue is more likely with react native it’s self. That being said there’s a workaround for it.For server images you can use Image.getSize, and for local images you can use Image.resolveAssetSource. I’m not sure why
getSize
doesn’t just support both but it doesn’t so I would just write a util function like this.then in your code you can just run it and use the result to set the state on your component