Open danivegamx opened 6 years ago
This library seem to be a little dead. Unfortunately there is bug that cause that error in some SVG with comments or texts. You can try to use any fork of this library.. several have addressed the same issue.
Also, would be usefull to have the SVG that causes that issue.
+1
@fniwes can you link a couple of forks that have addressed the issue?
I got the same issue.
Same issue. Very annoying!
there is another library same svg-uri?
Can someone link a fork in which the issue is adressed?
My current solution is to render the SVG URL inside a WebView. It's a hacky way of doing it, but it must suffice until this issue is addressed in the package.
Any solution ?
I started using react-native-svg-icon This library can be alternative for you.
Same error here!
Hi there,
As part of our internal development we've managed to solve this issue in our fork: addisonglobal/react-native-svg-uri
I'll be raising a PR in order to solve this. It's been caused by new React versions tagging componentWillReceiveProps as an unsafe lifecycle hook. We've just replaced that by splitting its functionality between getDerivedStateFromProps + componentDidUpdate methods.
Pull request: #160
Same issue here.
open the svg in the editor and delete the tags
This isnt a solution if you are fetching an SVG from an API. This is a workaround for local SVG files.
In my case, even locally, that workaround doesn't solve the problem, I'm still having the same error...
I experienced the same problem, i made mine work by removing all new lines of the svg file. However, it'll only work for local svg files.
No solutions yet? :(
// comment
strings and other unnecessary text I'm using a local svg file that is clean. No html comments or any strange tags. But still the app crashes with this same error. Any idea?
My svg code:
<?xml version="1.0" encoding="utf-8" ?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="30" height="26">
<defs>
<clipPath id="clip_0">
<rect x="-22" y="-697" width="375" height="812" clip-rule="evenodd"/>
</clipPath>
</defs>
<g clip-path="url(#clip_0)">
<path fill="none" stroke="rgb(126,211,33)" stroke-width="1.5" stroke-miterlimit="4" transform="translate(0.625122 0.670044)" d="M11.2463 24.955L22.5 24.955C22.5 24.955 22.5 20.765 21.9075 18.9788C21.3913 17.425 17.6625 16.385 13.75 14.91L13.75 11.785C13.75 11.785 15 11.0113 15 8.035C16.25 8.035 16.25 5.535 15 5.535C15 5.2425 16.3475 3.4375 15.9375 1.785C15.345 -0.595 8.24875 -0.595 7.65625 1.785C4.695 1.19 6.25 5.135 6.25 5.535L6.25 8.035C6.25 11.0113 8.75 11.785 8.75 11.785L8.75 14.91C5.2775 16.2288 1.1075 17.425 0.5925 18.9788C0 20.765 0 24.955 0 24.955L11.2463 24.955L11.2463 24.955Z"/>
</g>
<defs>
<clipPath id="clip_1">
<rect x="-22" y="-697" width="375" height="812" clip-rule="evenodd"/>
</clipPath>
</defs>
<g clip-path="url(#clip_1)">
<path fill="none" stroke="rgb(126,211,33)" stroke-width="1.5" stroke-miterlimit="4" transform="translate(18.2813 0.796997)" d="M7.96875 24.828L11.0938 24.828C11.0938 24.828 11.0938 20.638 10.5013 18.8518C9.985 17.298 6.25625 15.633 2.34375 14.158L2.34375 12.283C2.34375 12.283 3.59375 11.5093 3.59375 8.53302C4.84375 8.53302 4.84375 6.03302 3.59375 6.03302C3.59375 5.74052 4.94125 3.70552 4.53125 2.05302C4.25375 0.940522 1.875 -0.819478 0 0.430522"/>
</g>
</svg>```
I'm using a local svg file that is clean. No html comments or any strange tags. But still the app crashes with this same error. Any idea?
My svg code:
<?xml version="1.0" encoding="utf-8" ?> <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="30" height="26"> <defs> <clipPath id="clip_0"> <rect x="-22" y="-697" width="375" height="812" clip-rule="evenodd"/> </clipPath> </defs> <g clip-path="url(#clip_0)"> <path fill="none" stroke="rgb(126,211,33)" stroke-width="1.5" stroke-miterlimit="4" transform="translate(0.625122 0.670044)" d="M11.2463 24.955L22.5 24.955C22.5 24.955 22.5 20.765 21.9075 18.9788C21.3913 17.425 17.6625 16.385 13.75 14.91L13.75 11.785C13.75 11.785 15 11.0113 15 8.035C16.25 8.035 16.25 5.535 15 5.535C15 5.2425 16.3475 3.4375 15.9375 1.785C15.345 -0.595 8.24875 -0.595 7.65625 1.785C4.695 1.19 6.25 5.135 6.25 5.535L6.25 8.035C6.25 11.0113 8.75 11.785 8.75 11.785L8.75 14.91C5.2775 16.2288 1.1075 17.425 0.5925 18.9788C0 20.765 0 24.955 0 24.955L11.2463 24.955L11.2463 24.955Z"/> </g> <defs> <clipPath id="clip_1"> <rect x="-22" y="-697" width="375" height="812" clip-rule="evenodd"/> </clipPath> </defs> <g clip-path="url(#clip_1)"> <path fill="none" stroke="rgb(126,211,33)" stroke-width="1.5" stroke-miterlimit="4" transform="translate(18.2813 0.796997)" d="M7.96875 24.828L11.0938 24.828C11.0938 24.828 11.0938 20.638 10.5013 18.8518C9.985 17.298 6.25625 15.633 2.34375 14.158L2.34375 12.283C2.34375 12.283 3.59375 11.5093 3.59375 8.53302C4.84375 8.53302 4.84375 6.03302 3.59375 6.03302C3.59375 5.74052 4.94125 3.70552 4.53125 2.05302C4.25375 0.940522 1.875 -0.819478 0 0.430522"/> </g> </svg>```
My workaround for this is removing all whitespaces making it into a single-line SVG. Not sure if it'll work with your case. But try this.
<?xml version="1.0" encoding="utf-8" ?><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="30" height="26"><defs><clipPath id="clip_0"><rect x="-22" y="-697" width="375" height="812" clip-rule="evenodd"/></clipPath></defs><g clip-path="url(#clip_0)"><path fill="none" stroke="rgb(126,211,33)" stroke-width="1.5" stroke-miterlimit="4" transform="translate(0.625122 0.670044)" d="M11.2463 24.955L22.5 24.955C22.5 24.955 22.5 20.765 21.9075 18.9788C21.3913 17.425 17.6625 16.385 13.75 14.91L13.75 11.785C13.75 11.785 15 11.0113 15 8.035C16.25 8.035 16.25 5.535 15 5.535C15 5.2425 16.3475 3.4375 15.9375 1.785C15.345 -0.595 8.24875 -0.595 7.65625 1.785C4.695 1.19 6.25 5.135 6.25 5.535L6.25 8.035C6.25 11.0113 8.75 11.785 8.75 11.785L8.75 14.91C5.2775 16.2288 1.1075 17.425 0.5925 18.9788C0 20.765 0 24.955 0 24.955L11.2463 24.955L11.2463 24.955Z"/></g><defs><clipPath id="clip_1"><rect x="-22" y="-697" width="375" height="812" clip-rule="evenodd"/></clipPath></defs><g clip-path="url(#clip_1)"><path fill="none" stroke="rgb(126,211,33)" stroke-width="1.5" stroke-miterlimit="4" transform="translate(18.2813 0.796997)" d="M7.96875 24.828L11.0938 24.828C11.0938 24.828 11.0938 20.638 10.5013 18.8518C9.985 17.298 6.25625 15.633 2.34375 14.158L2.34375 12.283C2.34375 12.283 3.59375 11.5093 3.59375 8.53302C4.84375 8.53302 4.84375 6.03302 3.59375 6.03302C3.59375 5.74052 4.94125 3.70552 4.53125 2.05302C4.25375 0.940522 1.875 -0.819478 0 0.430522"/></g></svg>
I'm using a local svg file that is clean. No html comments or any strange tags. But still the app crashes with this same error. Any idea? My svg code:
<?xml version="1.0" encoding="utf-8" ?> <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="30" height="26"> <defs> <clipPath id="clip_0"> <rect x="-22" y="-697" width="375" height="812" clip-rule="evenodd"/> </clipPath> </defs> <g clip-path="url(#clip_0)"> <path fill="none" stroke="rgb(126,211,33)" stroke-width="1.5" stroke-miterlimit="4" transform="translate(0.625122 0.670044)" d="M11.2463 24.955L22.5 24.955C22.5 24.955 22.5 20.765 21.9075 18.9788C21.3913 17.425 17.6625 16.385 13.75 14.91L13.75 11.785C13.75 11.785 15 11.0113 15 8.035C16.25 8.035 16.25 5.535 15 5.535C15 5.2425 16.3475 3.4375 15.9375 1.785C15.345 -0.595 8.24875 -0.595 7.65625 1.785C4.695 1.19 6.25 5.135 6.25 5.535L6.25 8.035C6.25 11.0113 8.75 11.785 8.75 11.785L8.75 14.91C5.2775 16.2288 1.1075 17.425 0.5925 18.9788C0 20.765 0 24.955 0 24.955L11.2463 24.955L11.2463 24.955Z"/> </g> <defs> <clipPath id="clip_1"> <rect x="-22" y="-697" width="375" height="812" clip-rule="evenodd"/> </clipPath> </defs> <g clip-path="url(#clip_1)"> <path fill="none" stroke="rgb(126,211,33)" stroke-width="1.5" stroke-miterlimit="4" transform="translate(18.2813 0.796997)" d="M7.96875 24.828L11.0938 24.828C11.0938 24.828 11.0938 20.638 10.5013 18.8518C9.985 17.298 6.25625 15.633 2.34375 14.158L2.34375 12.283C2.34375 12.283 3.59375 11.5093 3.59375 8.53302C4.84375 8.53302 4.84375 6.03302 3.59375 6.03302C3.59375 5.74052 4.94125 3.70552 4.53125 2.05302C4.25375 0.940522 1.875 -0.819478 0 0.430522"/> </g> </svg>```
My workaround for this is removing all whitespaces making it into a single-line SVG. Not sure if it'll work with your case. But try this.
<?xml version="1.0" encoding="utf-8" ?><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="30" height="26"><defs><clipPath id="clip_0"><rect x="-22" y="-697" width="375" height="812" clip-rule="evenodd"/></clipPath></defs><g clip-path="url(#clip_0)"><path fill="none" stroke="rgb(126,211,33)" stroke-width="1.5" stroke-miterlimit="4" transform="translate(0.625122 0.670044)" d="M11.2463 24.955L22.5 24.955C22.5 24.955 22.5 20.765 21.9075 18.9788C21.3913 17.425 17.6625 16.385 13.75 14.91L13.75 11.785C13.75 11.785 15 11.0113 15 8.035C16.25 8.035 16.25 5.535 15 5.535C15 5.2425 16.3475 3.4375 15.9375 1.785C15.345 -0.595 8.24875 -0.595 7.65625 1.785C4.695 1.19 6.25 5.135 6.25 5.535L6.25 8.035C6.25 11.0113 8.75 11.785 8.75 11.785L8.75 14.91C5.2775 16.2288 1.1075 17.425 0.5925 18.9788C0 20.765 0 24.955 0 24.955L11.2463 24.955L11.2463 24.955Z"/></g><defs><clipPath id="clip_1"><rect x="-22" y="-697" width="375" height="812" clip-rule="evenodd"/></clipPath></defs><g clip-path="url(#clip_1)"><path fill="none" stroke="rgb(126,211,33)" stroke-width="1.5" stroke-miterlimit="4" transform="translate(18.2813 0.796997)" d="M7.96875 24.828L11.0938 24.828C11.0938 24.828 11.0938 20.638 10.5013 18.8518C9.985 17.298 6.25625 15.633 2.34375 14.158L2.34375 12.283C2.34375 12.283 3.59375 11.5093 3.59375 8.53302C4.84375 8.53302 4.84375 6.03302 3.59375 6.03302C3.59375 5.74052 4.94125 3.70552 4.53125 2.05302C4.25375 0.940522 1.875 -0.819478 0 0.430522"/></g></svg>
Looks like your solution working for me too! Thanks! Also I tried removing the <defs>
tags (without removing whitespaces like you did) & it worked too.
@nkgardose It works for me! Thanks
+1 @fcpineiro I tried your fork. It did manage not to crash but nothing seems to render. It does display a warning like you mentioned some where about deprecated lifecycles. link to svg
same problem
check if there's a title
property in the svg. but I think this library is dead.
In my case, I removed
* After
* "react": "16.8.3",
* "react-native": "0.59.3",
* "react-native-svg": "^9.5.1",
* "react-native-svg-uri": "^1.2.3",
minify your svg file
In Svg uri local image is not in current postion, can anyone know this issue?
This solution worked for me 90% of the time:
Accepted tags:
const ACCEPTED_SVG_ELEMENTS = [ 'svg', 'g', 'circle', 'path', 'rect', 'defs', 'line', 'linearGradient', 'radialGradient', 'stop', 'ellipse', 'polygon', 'polyline', 'text', 'tspan' ];
Try it!!!
<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 80 49"><defs><clipPath id="clip-path"><rect width="80" height="49" style="fill:none"/></clipPath></defs><title>empty-box</title><g style="clip-path:url(#clip-path)"><path d="M56.44,33.47c-3.52,5-16.19,2.34-16.19,2.34l-9.81-9.07-1.32-1.23,2.22-4.65,1.91.53C39.59,23.21,59.41,29.28,56.44,33.47Z" style="fill:#efb7b9"/><path d="M33.24,21.4a20.27,20.27,0,0,1-2.8,5.34l-1.32-1.23,2.22-4.65S32.05,21.05,33.24,21.4Z" style="opacity:0.10000000149011612;isolation:isolate"/><path d="M9.82,12.1,36.94,7.74V33.1L11.17,31.77Z" style="fill:#6c63ff"/><path d="M9.82,12.1,36.94,7.74V33.1L11.17,31.77Z" style="opacity:0.05000000074505806;isolation:isolate"/><path d="M36.94,7.74l32.52,2.4-1.8,22.07-30.72.89Z" style="fill:#6c63ff"/><path d="M36.94,7.74l32.52,2.4-1.8,22.07-30.72.89Z" style="opacity:0.10000000149011612;isolation:isolate"/><path d="M46.94,0l-10,7.74,32.52,2.4,5.31-7.92ZM0,3.65,24.41.71l12.53,7L9.82,12.1ZM42.88,14.33V49l-12.7-1.29-5.53-.55L23,47l-5.52-.56-7.63-.77V12.1l27.11,1.82Zm26.58-4.19V44L59.28,45.89l-5,.94L42.88,49V14.33l26.58-4.19Z" style="fill:#6c63ff"/><path d="M69.46,10.14V44L59.28,45.89l-5,.94L42.88,49V14.33l26.58-4.19Z" style="opacity:0.05000000074505806;isolation:isolate"/><path d="M0,19.4l9.82-7.3,33.06,2.23L38,22.42Z" style="fill:#6c63ff"/><path d="M0,19.4l9.82-7.3,33.06,2.23L38,22.42Z" style="fill:#fff;opacity:0.10000000149011612;isolation:isolate"/><path d="M69.46,10.14,42.88,14.33,51.53,22,80,17.26Z" style="fill:#6c63ff"/><path d="M69.46,10.14,42.88,14.33,51.53,22,80,17.26ZM59.28,45.89l-5,.94V39.6L59,38.45l.32,7.44Z" style="fill:#fff;opacity:0.10000000149011612;isolation:isolate"/></g></svg>
I was also having the same problem, but I found the react-native-svg package, worked for me!
Example:
import { SvgUri } from 'react-native-svg';
<SvgUri width="200" height="200" uri="http://thenewcode.com/assets/images/thumbnails/homer-simpson.svg" />
This isnt a solution if you are fetching an SVG from an API. This is a workaround for local SVG files.
Did anyone find a working solution for if you are fetching an SVG from an API?
This isnt a solution if you are fetching an SVG from an API. This is a workaround for local SVG files.
Did anyone find a working solution for if you are fetching an SVG from an API?
I would not use a package that has not been updated for 5+ years to be honest..
I'm using component, the app crashes with the following output:
react-native-svg-uri
in my project and I recently upgraded Xcode and RN to the latest versions 'till this issue posting. (Xcode 10, RN 0.57.1). When I want to navigate to a screen that contains thisInvariant Violation: Text strings must be rendered within a component.
If I remove the component, it works fine.
The version that I'm using from the library is:
"react-native-svg-uri": "^1.2.3",
"react-native-svg": "7.0.3",
Do you think this is a library issue (since I'm using RN 0.57.1) or this might be other problem?
Thanks