Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not catching the style/classes correctly (Black shape) #11

Closed
manelsanz opened this issue Mar 20, 2019 · 13 comments
Closed

Not catching the style/classes correctly (Black shape) #11

manelsanz opened this issue Mar 20, 2019 · 13 comments

Comments

@manelsanz
Copy link

manelsanz commented Mar 20, 2019

Hi, I have an SVG file with <style> tags, and the conversion is not going well. That renders as a black shape of the SVG. I think that it doesn't catch the <styles> tag well... what I can do? I have so much SVG Files...

SVG File:

<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 23.0.2, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->
<svg version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
	 viewBox="0 0 96 96" style="enable-background:new 0 0 96 96;" xml:space="preserve">
<style type="text/css">
	.st0{fill:#FFFFFF;}
	.st1{fill:#222FFF;}
</style>
<path class="st0" d="M48,96c26.5,0,48-21.5,48-48S74.5,0,48,0S0,21.5,0,48S21.5,96,48,96"/>
<path class="st0" d="M48,95c26,0,47-21,47-47S74,1,48,1S1,22,1,48S22,95,48,95"/>
<g>
	<g id="Navigation">
		<g>
			<path class="st1" d="M24,30.9h48.6c1.8,0,3.2-1.5,3.2-3.3c0-1.8-1.4-3.3-3.2-3.3H24c-1.8,0-3.2,1.5-3.2,3.3
				C20.8,29.4,22.2,30.9,24,30.9z M72.6,44.3H24c-1.8,0-3.2,1.5-3.2,3.3c0,1.8,1.4,3.3,3.2,3.3h48.6c1.8,0,3.2-1.5,3.2-3.3
				C75.8,45.7,74.3,44.3,72.6,44.3z M72.6,64.2H24c-1.8,0-3.2,1.5-3.2,3.3c0,1.8,1.4,3.3,3.2,3.3h48.6c1.8,0,3.2-1.5,3.2-3.3
				C75.8,65.6,74.3,64.2,72.6,64.2z"/>
		</g>
	</g>
</g>
</svg>

Thanks.

@manelsanz manelsanz changed the title Not catching the style/classes correctly Not catching the style/classes correctly (Black shape) Mar 20, 2019
@kristerkari
Copy link
Owner

Thanks @manelsanz!

There are still features that react-native-svg does not support when compared what the web browsers support related to SVG rendering.

I haven't tested, but my guess is the same as yours that the <style> tag is not supported. Could you instead change the svg file to have the fill attribute in the path elements instead of the <style> tag?

@manelsanz
Copy link
Author

Thanks @manelsanz!

There are still features that react-native-svg does not support when compared what the web browsers support related to SVG rendering.

I haven't tested, but my guess is the same as yours that the <style> tag is not supported. Could you instead change the svg file to have the fill attribute in the path elements instead of the <style> tag?

Yes @kristerkari , this way works fine.
I see that in your example project (https://github.com/kristerkari/react-native-svg-example) you have a webpack.config.js that I don't have. And you have installed the package @svgr/webpack. It's really necessary?

Thank you.

@kristerkari
Copy link
Owner

I see that in your example project (https://github.com/kristerkari/react-native-svg-example) you have a webpack.config.js that I don't have. And you have installed the package @svgr/webpack. It's really necessary?

It's not strictly necessary, but it makes it possible to use the exact same code to render the SVG on both Web and React Native as they both are processed with the same library.

@alamothe
Copy link

@kristerkari It should be possible to inline styles with a plugin, please check: gregberge/svgr#245

By the way, is there a way to customize .svgrrc for transformer? Thanks!

@alamothe
Copy link

...I tried to create a custom .svgrrc but it wasn't picked up.

I succeeded by patching react-native-svg-transformer like this:

    var jsCode = svgr.sync(
      src,
      {
        native: true,
        plugins: ['@svgr/plugin-svgo', '@svgr/plugin-jsx'],
        "svgoConfig": {
          "plugins": [
            {
              // Inline styles
              // 
              // https://github.com/smooth-code/svgr/issues/245
              "inlineStyles": {
                "onlyMatchedOnce": false
              },
            },

Hope this helps.

Do you maybe know why custom config is not being picked up? Thanks!

@kristerkari
Copy link
Owner

Thanks for the example @alamothe.

I'll look into adding the feature of reading the user provided SVGR configuration inside the transformer.

Here are the docs for SVGR configs:
https://github.com/smooth-code/svgr/blob/master/website/src/pages/docs/configuration-files.mdx

@kristerkari
Copy link
Owner

I opened a Pull Request that adds support for reading SVGR config:
#19

@kristerkari
Copy link
Owner

@alamothe New version is out that adds support for the SVGR config file:
https://github.com/kristerkari/react-native-svg-transformer/releases/tag/0.13.0

@alamothe
Copy link

Thank you!

@gablorquet
Copy link

i've added the .svgrrc file but i still only get black shapes, do I need to have other components installed ?

@gablorquet
Copy link

found it, you need to add install @svgr/plugin-svgo

@kristerkari
Copy link
Owner

kristerkari commented Apr 23, 2019

@gablorquet I think that your problem was not related to the .svgrrc file, but to the fact that some SVG images don't render correctly with React Native. The @svgr/plugin-svgo helps because it removes some stuff that is not compatible with React Native.

@Cazs03
Copy link

Cazs03 commented Sep 2, 2019

I'm using expo.io, can tellme how can add this configuration? im bit confuse @kristerkari

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants