Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React native: is it recommended to use PNG or SVG images?

I'm working on a react-native project and I have over 30 icons of SVG format. I want to know if it is recommended to convert those images to PNG or it's better to use as SVG files. If it's better to use images as SVG what is the best way to show SVG file on react native?

like image 855
Mahdi N Avatar asked Aug 01 '19 09:08

Mahdi N


3 Answers

You can always prefer svgs over pngs as the latter are heavy to render.

To render svg assets you can use react-native-svg.It's the best i found for react-native.But it is not fully complete.You can't show filters and shadows using this package.For that use the pngs instead.

like image 70
Thakur Karthik Avatar answered Oct 13 '22 12:10

Thakur Karthik


SVG is not always the best solution. If your SVG is not optimized and has lots of Paths / Lines or if you need to use it many times over, it can generate a lot of views and slow down your app.

Best answer is it depends.

like image 42
Grégory Rota Avatar answered Oct 13 '22 12:10

Grégory Rota


Prefer PNG over SVG for react-native apps because its rendering is less CPU intensive, and comparing to web apps user don't need to load all images on each app launch but only on installation, so the size doesn't matter that much.

Just make sure you provide three (or at least the last two) sizes:

image.png
[email protected]
[email protected]
like image 1
Alexander Danilov Avatar answered Oct 13 '22 11:10

Alexander Danilov