react-native Dimensions.get("window").width return 375 for an iPhone 6s.... it seems far from correct.
`
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
Dimensions
} from 'react-native';
class AwesomeProject extends Component {
render() {
return <Text style={{margin:50}}>Width: {Dimensions.get("window").width}</Text>;
}
}
AppRegistry.registerComponent('AwesomeProject', () => AwesomeProject);`
375 is the number of points across for the iPhone 6. For most things, points will be fine. But if you need pixels, you can use the PixelRatio
API provided by React Native.
For example, to get the distance across the iPhone in rendered pixels you could use Dimensions.get('window').width * PixelRatio.get()
, which should return 750 for the iPhone 6.
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