React native 维度。获取(';屏幕';)在本机中不工作

React native 维度。获取(';屏幕';)在本机中不工作,react-native,react-native-android,React Native,React Native Android,Im使用react native dimensions获取屏幕尺寸,并确定用户是处于纵向模式还是横向模式……但是dimensions.get('screen')。高度始终作为两个面中的较长面返回,即使在横向模式下也是如此……即尺寸。获取('screen')。高度始终大于尺寸。获取('screen')。宽度(/code>),即使在横向模式下也是如此 constructor(props) { super(props); this.state = { orientation

Im使用react native dimensions获取屏幕尺寸,并确定用户是处于纵向模式还是横向模式……但是
dimensions.get('screen')。高度始终作为两个面中的较长面返回,即使在横向模式下也是如此……即<代码>尺寸。获取('screen')。高度始终大于尺寸。获取('screen')。宽度(/code>),即使在横向模式下也是如此

constructor(props) {
    super(props);
    this.state = {
      orientation: (Dimensions.get('screen').height >= Dimensions.get('screen').width ? 'portrait' : 'landscape')
    };

    Dimensions.addEventListener('change', () => {
      let orientation = (Dimensions.get('screen').height >= Dimensions.get('screen').width ? 'portrait' : 'landscape');
      this.setState({
        orientation: orientation
      });
    });
  }
使用。 只需在根组件中放入如下内容:

const SCREEN_WIDTH = useWindowDimensions().width;
const SCREEN_HEIGHT = useWindowDimensions().height;
return (
    <View style={{ width: SCREEN_WIDTH, minHeight: SCREEN_HEIGHT}} >
        //the rest of your app
    </View>
);
const SCREEN\u WIDTH=useWindowDimensions().WIDTH;
const SCREEN_HEIGHT=useWindowDimensions().高度;
返回(
//应用程序的其余部分
);

无法从类组件调用挂钩…我需要重写我的整个应用程序。是否没有其他方法使尺寸标注起作用?