Skip to content

Latest commit

 

History

History
27 lines (18 loc) · 783 Bytes

get-width-or-height-of-device-window.md

File metadata and controls

27 lines (18 loc) · 783 Bytes

Get Width Or Height Of Device Window

Category: React Native

You can obtain the width or height of a device window with the useWindowDimensions() hook.

const window = useWindowDimensions();
const {width, height} = window;
console.log(`Width is ${width} and height is ${height}`);

The values for width and height automatically update the when screen size changes.

Some operating systems allow users to scale their font sizes larger or smaller for reading comfort. Font scale can also be obtained using:

useWindowDimensions().fontScale;

Pixel ratio can be obtained using:

useWindowDimensions().scale;

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