All Dimensions in React Native are unitless, and represent Density-Independent pixels.
https://facebook.github.io/react-native/docs/height-and-width.html
Translating:
All dimensions in React Native are dimensionless (no unit of measurement) and represent density independent pixels (resolution).
The factor that multiplies the units of measure and gives rise to the values in real pixels is called pixel ratio for it is always the reason (ratio) between two pixel densities. You can get it through the method PixelRatio.get()
(source: https://facebook.github.io/react-native/docs/pixelratio.html).
Exemplifying how is the calculation of pixel ratio, on Android systems there are six densities:
ldpi
: 120 dpi
mdpi
: 160 dpi
hdpi
: 240 dpi
xhdpi
: 320 dpi
xxhdpi
: 480 dpi
xxxhdpi
: 640 dpi
A measurement unit in React Native equals exactly 1 px
in mdpi
and for the other resolutions you can multiply by the ratio between the pixel density of the current resolution and the resolution density in mdpi
. Thus, 1
would amount to 1 × 480 dpi/160 dpi px
= 3 px
in xxhdpi
for the pixel ratio is 480 dpi/160 dpi
= 3
.
For iOS, the default resolution is 163 dpi
and the rest are whole multiples of it. So, 1
may amount to 1 px
, 2 px
, 3 px
etc..
React-Native
does not useCSS
– Rafael Augusto
So what are the names of these measures?
– Mateus
https://facebook.github.io/react-native/docs/pixelratio.html
– Rafael Augusto
When we program in
Kotlin
(for example) we usedp
and notpx
, which, if I’m not mistaken, is the case withReact Native
andNativeScript
.– Rafael Augusto
I did a search on the dp here, and this would be to convert the image to the ratio set depending on the pixel density of the screen, that’s it?
– Mateus
And in this case then there would be an exact value, because it depends on the device
– Mateus
http://labs.rampinteractive.co.uk/android_dp_px_calculator/
– Rafael Augusto