React native 如何在React Native中获取屏幕尺寸

React native 如何在React Native中获取屏幕尺寸,react-native,navigation-drawer,react-navigation-drawer,React Native,Navigation Drawer,React Navigation Drawer,我正在尝试使用React Native创建一个全宽导航抽屉。到目前为止,我编写了以下代码: 从“react native”导入{Dimensions}; const{customWidth}=Dimensions.get('window').width// 我自己发现了这个虫子。实际上,那些额外的{和}就是问题所在。我应该写: const customWidth=Dimensions.get('window').width; 就这么简单。试试const customWidth=Dimensi

我正在尝试使用React Native创建一个全宽导航抽屉。到目前为止,我编写了以下代码:



从“react native”导入{Dimensions};
const{customWidth}=Dimensions.get('window').width// 我自己发现了这个虫子。实际上,那些额外的
{
}
就是问题所在。我应该写:

const customWidth=Dimensions.get('window').width;

就这么简单。

试试const customWidth=Dimensions.get('window').width;而是和console.log(customwidt)——它应该向您显示它从“react native”导入{Dimensions};const width=Dimensions.get('window').width;const height=维度.get('window')。高度;