useWindowDimensions

React 实战教程 深入学习一线大厂必备前端技能,VIP 教程限时免费领取。 立即查看 >
import { useWindowDimensions } from "react-native";

useWindowDimensions automatically updates width and height values when screen size changes. You can get your application window's width and height like so:

const windowWidth = useWindowDimensions().width;
const windowHeight = useWindowDimensions().height;

示例#

Properties#

fontScale#

The scale of the font currently used. Some operating systems allow users to scale their font sizes larger or smaller for reading comfort. This property will let you know what is in effect.

useWindowDimensions().fontScale;

height#

The height in pixels of the window or screen your app occupies.

useWindowDimensions().height;

scale#

The pixel ratio of the device your app is running on.

useWindowDimensions().scale;

A value of 1 indicates PPI/DPI of 96 (76 on some platforms). 2 indicates a Retina or high DPI display.

width#

The width in pixels of the window or screen your app occupies.

useWindowDimensions().width;

本文档贡献者:sunnylqm(97.47%), sunnylqm(2.53%)#