Can I use Image.getSize with a static image file?

I want to use Image.getSize ( https://facebook.imtqy.com/react-native/docs/image.html ) to get the size of my image, but the first argument requires the image source to be in a URI, but I cannot use URI with a static file, I can only use Require.

Therefore, is it possible to use Image.getSize in a static file, or do I need to find another way?

+4
source share
1 answer

You can use resolAssetSource (from response-native / Libraries / Image / resolveAssetSource ) to get the size of the image.

import resolveAssetSource from 'resolveAssetSource';

and

let icon =  require('./assets/images/icon.png'); 
let source = resolveAssetSource(icon);
// source.width, source.height`
+13
source

Source: https://habr.com/ru/post/1668594/


All Articles