Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What should be the resolution of an image in React Native?

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?

like image 287
laurent Avatar asked Jul 22 '17 10:07

laurent


People also ask

How do I optimize an image in React Native?

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.

What is DPI in native React?

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.

What is pixel ratio React Native?

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.

Does React Native use pixels?

All dimensions in React Native are unitless, and represent density-independent pixels.


1 Answers

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.

like image 101
Pedro Henrique Bufulin Avatar answered Oct 15 '22 04:10

Pedro Henrique Bufulin