如何在 react-native iOS 中获得正确的屏幕宽度?

How to get the correct screen width in react-native iOS?

react-native Dimensions.get("window").width return 375 对于 iPhone 6s.... 这似乎远非正确。

`

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 是 点数 跨越 iPhone 6。对于大多数事情,点数就可以了。但是如果你需要像素,你可以使用React Native提供的PixelRatio API。

例如,要获得以渲染像素为单位的 iPhone 的距离,您可以使用 Dimensions.get('window').width * PixelRatio.get(),对于 iPhone 6 应该 return 750。