PixelRatio

PixelRatio class gives access to the device pixel density.

TV relevance: Baseline React Native Web API. Useful for typography and visual scaling across TV display densities.

import { PixelRatio } from 'react-native';

API

Static methods

get () => number

Returns the device pixel density as a number.

getFontScale () => number

On web this returns the device pixel ratio as a number.

getPixelSizeForLayoutSize (number) => number

Converts a layout size (dp) to pixel size (px). Guaranteed to return an integer number.

roundToNearestPixel (number) => number

Rounds a layout size (dp) to the nearest layout size that corresponds to an integer number of pixels. For example, on a device with a PixelRatio of 3, PixelRatio.roundToNearestPixel(8.4) = 8.33, which corresponds to exactly (8.33 * 3) = 25 pixels.

Updated
React Native Web for TVPortions Copyright © Nicolas Gallagher, Meta Platforms, Inc., Facebook, Inc. and affiliates, and other contributors as noted in file headers and THIRD_PARTY_NOTICES.md. Modifications and TV extensions Copyright © Harpreet Singh and contributors.