Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't height automatically adjust to the width?

Tags:

react-native

In CSS, if you set a width of 60%, the height will proportionally adjust. In React Native, that is not the case. If you set the width of an image to be '60%', and don't set the height, the height will be 0 and not show. How do I get the height to do the same as CSS?

thumbnail: {
    width: '60%',
    minHeight: 10,
}

I tried setting a minHeight, and that makes it go to 10px. I want the height to change based on the image proportions. I looked at flex, but I don't think that's what I want.

enter image description here

like image 821
User Avatar asked Feb 21 '26 01:02

User


1 Answers

I think you want to set the resizeMode to contain. It could be cover, it looks like there's currently a mistake in the docs... https://facebook.github.io/react-native/docs/image.html

like image 188
klvs Avatar answered Feb 25 '26 23:02

klvs



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!