React Native components are unitless, and represent density-independent pixels according this page.
However, when I create an image, what should be its ideal resolution, in pixels? Let's say I have a tag like this:
<Image style={{width: 100, height: 100}} source={require('./img/myimage.png')} />
How big should I make my image to make sure it renders well in all devices?
If you are using react-native-image-picker for uploading images, you can set maxWidth, maxHeight or quality of image for reducing the size. Show activity on this post. https://github.com/bamlab/react-native-image-resizer provides an API to resize local images.
React Native uses Dots Per Inch (DPI) to measure the sizing of the User Interface (UI) and anything displayed on the UI. This type of measurement allows an application to look uniform across various screen sizes and pixel densities.
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. Last updated on Sep 5, 2022. PanResponder.
All dimensions in React Native are unitless, and represent density-independent pixels.
In react-native documentation it says that you can name your images with the suffixes @2.x and @3.x to make the images look right on every device. In your images folder, you should do something like this:
.
├── button.js
└── img
├── check.png
├── [email protected]
└── [email protected]
Also, remind to don't use other values than @2.x amd @3.x, because when you run ./gradlew bundleRelease
to build your production app, it will get an error, and it quite doesn't tell your that the problem is the suffixes that aren't recognized.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With