My original image measures 1080
(w) * 607
(h). It comes from a server (not from local). The dimensions are not supposed to be known (I have a lot of image with different dimensions).
I simply want my image to be fully visible on my device, respecting the ratio.
I tried to display this image in resizeMode : contain
with a width: 100%
. It displays very well, but with a big huge margin (I added a red background to realize this). I don't understand this margin.
return (
...
<Image
source={{ uri: http://... }}
containerStyle={[
styles.image_container
]}
resizeMode="contain"
/>
....
)
const styles = StyleSheet.create({
image_container: {
backgroundColor: 'red',
width: '100%',
aspectRatio: 1
},
)}
I think it's because of aspectRatio: 1
. But if I remove aspectRatio: 1
the image is hidden. I tried a lot of combination with width
/ height
/ aspectRatio
.
I searched a lot (a lot a lot) on google but this question often returns a ton of possibility (with lot of calculs (example)) and no universal answer.
I think my situation is the simplest but it seems so complicated it gets weird.