In a browser, the width of an image can be specified and height can be set to auto. This will let the image retain aspect ratio while being bound to the specified width. Neither Height nor aspect ratio is known beforehand
How can I do the same in react native? Height property can only accept number values.
Workaround:
get Dimensions
module from react-native
. You can get screen size from this module using Dimensions.height/width
. Then you can set you image style with something like this:
image: {
height: Dimensions.height * 0.8,
resizeMode: 'contain'
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With