Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Constrain View to square aspect ratio

I'm playing with an iPhone app in react-native and I'd like a view to fill the screen in width and maintain a square aspect ratio. So the height should equal the width. I can't seem to find a way to achieve that. The other option is to specify a specific width and height but I'm not seeing a way to query the device width from within react-native to allow me to do this. Any pointers?

like image 497
Daniel Avatar asked Sep 25 '22 23:09

Daniel


1 Answers

I hope you are looking for this...

var Dimensions = require('Dimensions');
var device = Dimensions.get('window');


var styles = StyleSheet.create({
  squareBox: {
    width: device.width,
    height: device.width,
  }
);
like image 98
Phyo Avatar answered Sep 28 '22 23:09

Phyo