question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Load a local svg file using react-native-svg

See original GitHub issue

Is there a way to load an existing svg asset from local files? Something like this:-

<Svg fillAll="#c6ccd8" width="60" height="60" source={require('../../icons/account.svg')}/>

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

1reaction
jackphuongvucommented, Mar 12, 2019

Docs have been updated: https://github.com/react-native-community/react-native-svg#use-with-svg-files With react-native-svg-transformer you can now do this:

import Logo from "./logo.svg";
const myApp = () => <Logo width={120} height={40} />
export default myApp

How about the fill props in this way? I’m working on this thing for now as well.

0reactions
msandcommented, Mar 12, 2019

It uses SVGR under the hood, and it produces components looking like this:

import React from 'react'
import Svg, { Path } from 'react-native-svg'
/* SVGR has dropped some elements not supported by react-native-svg: title */

const SvgComponent = props => (
  <Svg width={48} height={1} {...props}>
    <Path d="M0 0h48v1H0z" fill="#063855" fillRule="evenodd" />
  </Svg>
)

export default SvgComponent

So, if you have elements where you haven’t defined fill or stroke, then they’ll inherit from their ancestors, and if you give a value to the SvgComponent, it’ll give it to the Svg root and thus inherit from there. There is also the color property you can use in addition to stroke and fill, and it can be referenced using the currentColor value: https://github.com/react-native-community/react-native-svg#svg

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to import SVG files in React Native using react-native-svg
Let's look at how you can use the react-native-svg library to render SVGs in your app. Open up the project in your favorite...
Read more >
Load a local svg file using react-native-svg #900 - GitHub
Is there a way to load an existing svg asset from local files? Something like this:-
Read more >
How to show SVG file on React Native? - Stack Overflow
svg files called react-native-vector-image. It doesn't need any custom babel transforms and you can use it like you would for other bitmap based ......
Read more >
React Native: How To Use SVGs - Medium
First, install the react-native-svg and react-native-svg-transformer packages to your project with the package manager of your choice: yarn add ...
Read more >
Working with SVGs in React Native - OpenReplay Blog
The next step is getting an SVG file. You can download any on the internet or use this. Move the downloaded file to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found