vault-development / react-native-svg-uri

Render SVG images in React Native from an URL or static file
849 stars 334 forks source link

Base64 support? #73

Closed cooperka closed 7 years ago

cooperka commented 7 years ago

Issue

I don't see any issues or documentation about base64 encoding support for SVG data. I tried it and it didn't work, but I'm wondering if you have any advice or quick solutions. For now I'll try to decode it manually before passing the string as svgXmlData.

Adding SVG files to my project directly requires them to be duplicated in Android and iOS resources folders, and prevents them from being easily updated using tools like CodePush.

Workaround

MyComponent.js:

import base64 from 'base-64';
import SvgUri from 'react-native-svg-uri';

import iconBase64 from './icon.svg.js';

const iconData = base64.decode(iconBase64);

...

  render() {
    return (
      <SvgUri
        width="80"
        height="80"
        svgXmlData={iconData}
      />
    );
  }

icon.svg.js:

export default 'Zm9vIMKpIGJhciDwnYyGIGJheg==';

(Of course you could just put the decoded XML in that file directly, but that doesn't meet my requirements)

matc4 commented 7 years ago

Hi @cooperka, i think that as you mention the solution will be have a file with the xml of the SVG directly. If you need for some reason use base64 its ok. But i think its not in the scope od this libary base64 encoding/decoding

cooperka commented 7 years ago

That makes sense. Thanks @matc4.