I am trying to get the original size image from a url and display the image based on its ratio. I used Image.getSize()
to do the job.
This is what I've done so far :
function displayimgThumb(file_url){
var win = Dimensions.get('window');
var ratio = 0
var imgWidth = 0;
var imgHeight = 0;
Image.getSize(file_url, (width, height) => {
ratio = win.width / width;
imgWidth = win.width;
imgHeight = height * ratio;
});
return (
<TouchableOpacity>
<FastImage
style={{
width: imgWidth,
height: imgHeight
}}
source={{
uri: file_url,
priority: FastImage.priority.normal,
}}
resizeMode={FastImage.resizeMode.contain} />
</TouchableOpacity>
)
}
See the Image.getSize()
, I can get the width and height of the image but I am unable to access the data from outside. Means I cannot get the width and height set in <FastImage />
style as the data cannot be accessed.
How should I pass it through there? For some reason, I am unable to use setState()
cause I'm using a function from a different separated file.