Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native: Setting the width of a view equal to its height when using percentages

Tags:

I have this stylesheet, and I'm trying to make the width of this equal to the height when I set height as a percentage. I the following with no success:

art: {     height: "70%",     width: styles.podcastArt.height,     marginRight:10,     marginTop:10,     marginBottom:10, }, 

Any ideas or direction would be helpful. Thanks!

like image 394
user8811409 Avatar asked Nov 18 '17 13:11

user8811409


People also ask

How do I change the width of a percentage in React Native?

To set width style to a percentage number with React Native, we can use flexbox. to set flexDirection to 'row' to add a horizontal flexbox layout. We set the 2nd Text component to fill 20% of the screen. Then we set flexGrow to 1 on the first Text component to expand to fill the remaining width of the screen.

How do you set dynamic height and width in React Native?

In react-native, to set the dynamic width and height to a component, we use built-in interface Dimensions. it takes the dimension of a given component and then sets the width and height to its equivalent.


1 Answers

set aspectRatio: 1

art: {     height: "70%",     aspectRatio: 1,     marginRight:10,     marginTop:10,     marginBottom:10, }, 
like image 182
SiSa Avatar answered Oct 23 '22 09:10

SiSa