Get Screen Display Size (Diagonal) in Inches

27 views Asked by At

I need a way to calculate a phone's display size (the diagonal measurement). I have an algorithm in my app that relies on the display size of a screen to do some calculations for a user and need a way to get this value.

Are there libraries to help get the PPI of a device? Perhaps libraries that help with getting the displaySize?

I've tried using the useWindowDimensions hook to get the width and heigh of the phone and have been successful. With these values, I convert them from , I calculate the diagonal in pixels.

const { height, width, scale } = useWindowDimensions();

const heightPixels = height * scale;
const widthPixels = width * scale;

const displaySizePixels = Math.sqrt(heightPixels * heightPixels + widthPixels * widthPixels)

From displaySizePixels I do not know how to get the PPI to get me to the last value needed to get the displaySize in inches.

Also, I've tried calculating DPI using the scale value by multiplying it by 160, per this solution, but for phones such as the iPhone Pro Max 15 the scale returns 3, the calculated DPI would be 160 * 3 = 480, but Apple states this phone to have a DPI of 460.

0

There are 0 answers