0

Say that I want to create a UI element 2cm*3cm in dimensions, exactly. Also, needles to say, said dimensions would need to be the same on all devices.

I am already using react-native-responsive-screen , but that is not what I am looking for.

I have come upon some solutions, like the one in this thread: Get screen DPI in react native

Reading through it, I made the function below:

(cm)=>{
    const dpi = (PixelRatio.get()*160);
    const dpCentimeter = dpi/2.54;
    return dpCentimeter*cm;
}

However, using it on different devices (specifically using an iPhone 6s and an Huawei honor) the dimensions end up wildly different. Could this be due to the different OS? Is there any other way to get this working as intended?

DanielGPR
  • 21
  • 2
  • Have you compared sizes on two Android devices? Is the difference manifest only on different OS's? – giotskhada Jul 09 '20 at 00:42
  • @giotskhada Haven't compared with two android devices, but I think the problem is someplace else. If I use the above function to return, for example, a height of a component in cm, the actual height ends up being magnitudes greater than the one specified. – DanielGPR Jul 09 '20 at 23:46

0 Answers0