Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use Height auto in react native?

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.

like image 951
Jeff P Chacko Avatar asked Apr 26 '16 10:04

Jeff P Chacko


1 Answers

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'
}
like image 172
Radek Czemerys Avatar answered Sep 18 '22 01:09

Radek Czemerys