Use SVGs (2024)

Learn how to create and use SVGs in an Expo project.

SVGs (Scalable Vector Graphics) are a great way to present icons and other visual elements in a flexible, crisp, and performant way. Using SVGs on the web is straightforward since we can copy an SVG and place it inline in an HTML file. This works because browsers understand how to parse and present SVGs. Expo does not understand how to parse and present SVG out of the box on Android and iOS, so we'll need to use a React Native package and an SVG converter to do so.

Let's go over the whole process of creating an SVG to presenting it in an Expo project.

Exporting an SVG

Once we have a vector created inside a design program, like Figma, Illustrator, or Sketch, find the "export" menu and specify "SVG" as the export type. This will create an SVG file we can view in a code editor. Alternatively, these programs often allow right-clicking on an element, then copying it as an SVG.

Converting SVG files using a Babel transformer

React Native SVG transformer allows compile-time transformation to make SVG files compatible with React.

Follow the installation steps to configure your Expo project to use this workflow. After your project is properly configured, you'll be able to use your local SVG files like this:

import Logo from './assets/logo.svg';<Logo width={120} height={40} />;

Converting individual SVG files for React Native

Alternatively, React-SVGR is a great tool to convert individual SVG files. It takes an SVG as input then can transform it into another format, including a format that works with React.

Paste the SVG contents from the exported SVG file into React-SVGR and make sure the "native" checkbox is ticked. It will provide output that we can copy and paste into our project.

To automate this process, React-SVGR also provides a CLI that could allow us to put regular SVGs in our project, then run a script that would convert them into React components automatically. If you have many icons, or a team of developers working on your project, it's definitely worth the time to set up process like this.

Including the SVG in our project

Once we have a compatible SVG, we'll need to add react-native-svg to our project. We can do so with:

Terminal

-

npx expo install react-native-svg

Then we can add code like the following to our project:

You can learn more about SVG with our API Reference document on SVG.

Use SVGs (2024)
Top Articles
WEP vs. WPA
1 PI to INR - Exchange - How much Indian Rupee (INR) is 1 PiCoin (PI) ? Exchange Rates by Walletinvestor.com
Housing near Juneau, WI - craigslist
Uihc Family Medicine
Atvs For Sale By Owner Craigslist
Valley Fair Tickets Costco
How To Be A Reseller: Heather Hooks Is Hooked On Pickin’ - Seeking Connection: Life Is Like A Crossword Puzzle
10 Popular Hair Growth Products Made With Dermatologist-Approved Ingredients to Shop at Amazon
The Potter Enterprise from Coudersport, Pennsylvania
Alpha Kenny Buddy - Songs, Events and Music Stats | Viberate.com
Umn Pay Calendar
Back to basics: Understanding the carburetor and fixing it yourself - Hagerty Media
Western Razor David Angelo Net Worth
Blue Ridge Now Mugshots Hendersonville Nc
Regular Clear vs Low Iron Glass for Shower Doors
Dusk
What to do if your rotary tiller won't start – Oleomac
Restaurants Near Paramount Theater Cedar Rapids
Eka Vore Portal
Snow Rider 3D Unblocked Wtf
Puretalkusa.com/Amac
Sound Of Freedom Showtimes Near Cinelux Almaden Cafe & Lounge
Urban Airship Expands its Mobile Platform to Transform Customer Communications
How to Create Your Very Own Crossword Puzzle
Loves Employee Pay Stub
Costco Great Oaks Gas Price
Nhl Tankathon Mock Draft
Pioneer Library Overdrive
Gen 50 Kjv
1964 Impala For Sale Craigslist
Ipcam Telegram Group
Nikki Catsouras: The Tragic Story Behind The Face And Body Images
DIY Building Plans for a Picnic Table
Craigslist Texas Killeen
Wisconsin Volleyball Team Leaked Uncovered
Jeep Cherokee For Sale By Owner Craigslist
Half Inning In Which The Home Team Bats Crossword
Appraisalport Com Dashboard /# Orders
Free Robux Without Downloading Apps
The disadvantages of patient portals
Stanford Medicine scientists pinpoint COVID-19 virus’s entry and exit ports inside our noses
Michael Jordan: A timeline of the NBA legend
Pay Entergy Bill
How To Upgrade Stamina In Blox Fruits
Wasmo Link Telegram
Tfn Powerschool
Holzer Athena Portal
Petfinder Quiz
Itsleaa
Latest Posts
Article information

Author: Kieth Sipes

Last Updated:

Views: 5780

Rating: 4.7 / 5 (67 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Kieth Sipes

Birthday: 2001-04-14

Address: Suite 492 62479 Champlin Loop, South Catrice, MS 57271

Phone: +9663362133320

Job: District Sales Analyst

Hobby: Digital arts, Dance, Ghost hunting, Worldbuilding, Kayaking, Table tennis, 3D printing

Introduction: My name is Kieth Sipes, I am a zany, rich, courageous, powerful, faithful, jolly, excited person who loves writing and wants to share my knowledge and understanding with you.