-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Svg loses gradients displaying a black color #1153
Svg loses gradients displaying a black color #1153
Comments
The issue is that you're specifying the stop-color as a style rather than an attribute. It's possible to fix quite easily with a change in js. Fix coming up. Meanwhile, here's a workaround: App.js import React from 'react';
import {SvgXml} from 'react-native-svg';
import {SafeAreaView} from 'react-native';
const xml = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200">
<defs>
<radialGradient id="gradient1" cx="50%" cy="50%" r="50%" fx="50%" fy="50%">
<stop offset="0%" stop-color="#FF00FF" />
<stop offset="100%" stop-color="#FFBD2E" />
</radialGradient>
<radialGradient id="gradient2" cx="50%" cy="50%" r="70%" fx="50%" fy="50%">
<stop offset="0%" stop-color="#FF00FF" />
<stop offset="100%" stop-color="#FFBD2E" />
</radialGradient>
<radialGradient id="gradient3" cx="20%" cy="50%" r="50%" fx="50%" fy="50%">
<stop offset="0%" stop-color="#FF00FF" />
<stop offset="100%" stop-color="#FFBD2E" />
</radialGradient>
<radialGradient id="gradient4" cx="50%" cy="50%" r="50%" fx="20%" fy="90%">
<stop offset="0%" stop-color="#FF00FF" />
<stop offset="100%" stop-color="#FFBD2E" />
</radialGradient>
<radialGradient id="gradient5" cx="20%" cy="20%" r="50%" fx="20%" fy="20%">
<stop offset="0%" stop-color="#FF00FF" />
<stop offset="100%" stop-color="#FFBD2E" />
</radialGradient>
<radialGradient id="gradient6" cx="50%" cy="50%" r="50%" fx="80%" fy="80%">
<stop offset="0%" stop-color="#FF00FF" />
<stop offset="100%" stop-color="#FFBD2E" />
</radialGradient>
</defs>
<circle cx="40" cy="60" r="30" fill="url(#gradient1)" />
<circle cx="100" cy="60" r="30" fill="url(#gradient2)" />
<circle cx="160" cy="60" r="30" fill="url(#gradient3)" />
<circle cx="40" cy="140" r="30" fill="url(#gradient4)" />
<circle cx="100" cy="140" r="30" fill="url(#gradient5)" />
<circle cx="160" cy="140" r="30" fill="url(#gradient6)" />
</svg>`;
const App = () => {
return (
<SafeAreaView style={{flex: 1, backgroundColor: 'white'}}>
<SvgXml width="100%" height="100%" xml={xml} />
</SafeAreaView>
);
};
export default App; |
Can you try with the latest commit from the develop branch? |
# [9.12.0](v9.11.1...v9.12.0) (2019-10-19) ### Bug Fixes * handle setting transform attribute on clipPath, fixes [#1152](#1152) ([73b21d1](73b21d1)) * improve handling of transform attribute on clipPath, fixes [#1152](#1152) ([3aa126e](3aa126e)) * **ios:** backwards compatible RCTImageLoader.h handling fixes [#1141](#1141) ([3c22c97](3c22c97)) * **ios:** clipPath rendering, fixes [#1131](#1131) ([2534537](2534537)) * **ios:** deprecation of RCTImageLoader fixes [#1141](#1141) ([5452144](5452144)) * **ios:** fix changes in color/currentColor/tintColor, fixes [#1151](#1151) ([0c7e94d](0c7e94d)) * **ios:** image viewBox opposite handling of y alignment, fixes [#1138](#1138) ([c69e9e2](c69e9e2)) * **js:** allow setting stopColor/Opacity/Offset using styles, fix [#1153](#1153) ([5984e06](5984e06)) * getPointAtLength signature ([2c57af2](2c57af2)) * getScreenCTM calculation ([5c5072d](5c5072d)) * improve native method spec conformance ([c63f9e2](c63f9e2)) * improve types for getBBox ([cecde7d](cecde7d)) * prepare script ([9a3dc4e](9a3dc4e)) * **ios:** memory leak in tspan, fixes [#1073](#1073) ([974f3a8](974f3a8)) * fix native methods spec conformance ([ecedb21](ecedb21)) * Make native methods synchronous ([8ce7611](8ce7611)) * refine types for matrix helpers ([409af91](409af91)) * refine types for matrix helpers ([7a3f867](7a3f867)) * **android:** defineMarker/getDefinedMarker storage ([e6eda84](e6eda84)) * **android:** native method scaling and getScreenCTM offset ([f3e0b19](f3e0b19)) * native method signatures web compatibility / spec conformance ([8687a3d](8687a3d)) * **ios:** optimize extractPathData, clear PathMeasure when no textPath ([df69c26](df69c26)) ### Features * **flow:** add flowgen to generate flow types from typescript, [#1125](#1125) ([fcd66fb](fcd66fb)) * implement getBBox, getCTM, getScreenCTM ([f13d54a](f13d54a)) * implement isPointInStroke ([2ba64df](2ba64df)) * initial implementation of isPointInFill ([203e53b](203e53b)) * support using native methods using promises instead of callbacks ([c28499b](c28499b)) * **android:** implement getTotalLength and getPointAtLength ([cd667d0](cd667d0)) * **ios:** implement getTotalLength and getPointAtLength ([78c4f20](78c4f20))
🎉 This issue has been resolved in version 9.12.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Still not working. It's a completely black fill. Loading it from file |
I wonder if it's related to react-native-svg-transformer then, @kristerkari would you mind having a look? |
I just tested with v9.12.0, and both the svg file from this issue and @msand's workaround are working for me when I use react-native-svg-transformer. |
@kristerkari Great. Btw, there's support for the style element coming up, essentially removing the need for svgo, or at least giving support for css/style elements when fetching content from e.g. uris: #1150 (comment) my experiment is available from the css branch: /~https://github.com/react-native-community/react-native-svg/tree/css |
@msand with the svg I had on the repo works perfectly but I just tested with another and the problem persists if I use a javascript svg or a .svg file, want me to update the repository with the reproducible code? Or are you already aware of the situation? |
Just updated it, give it a new look @msand and thanks for your time |
@tiagocorreiaitcenter The other svg file contains a style element with css inside it, and if you use svgr, you need to specify settings (onlyMatchedOnce to false) for the inlineStyles plugin, because the selectors in your css match more than a single element, and by default it doesn't inline those css rules: {
"plugins": [
{
"inlineStyles": {
"onlyMatchedOnce": false
}
}
]
} @neoziro Perhaps this should be made the default when setting the react-native option in svgr? Alternatively, you can use the SvgCss element from react-native-svg like this: import React from 'react';
import {SvgCss} from 'react-native-svg';
const xml = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200">
<style>.bones{fill:#ccc ;} .eye{fill:#666;}</style>
<path class="bones"
d="M38.8 97.7c-2.1 1.1-4.2 2.4-6.1 4-.9.8-3.4 3.1-3.1 4.5.6 3.1 6.4.1 7.9-.7 2.7-1.4 8.6-3.7 9.9-6.6 2.4-5.3-6.7-2.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/>
<path class="eye"
d="M130.4 78.1c-1.5 1.4-2.9 2.9-4.3 4.3-.5.5-3.1 2.4-1.7 3.1 1.2.6 3.7-2.1 4.6-2.8 1.1-.9 2.2-2 3.4-2.9 1.3-1.1 5.4-3.8 4-6.1-.5-.8-.8-.4-1.5.2-1.6 1.4-3.1 2.8-4.5 4.2z"/>
</g>
</svg>`;
export default () => {
return <SvgCss xml={xml} width="100%" height="100%" />;
}; |
@tiagocorreiaitcenter Can you try this?
|
@msand Hey, thanks for your time once again, I tested and with svg above the problem was indeed solved, but I just updated it to a simple circle with a linear-gradient and it still fails on this scenario, do you mind giving a new look to it? thanks |
@tiagocorreiaitcenter We currently don't have support for xlinkHref on the Gradient elements, there is a pr with partial support but not properly implemented yet: /~https://github.com/react-native-community/react-native-svg/pull/920/files |
@msand Ok, I will keep an eye on it, hoping it comes out soon, thanks for your time |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. You may also mark this issue as a "discussion" and I will leave this open. |
Closing this issue after a prolonged period of inactivity. Fell free to reopen this issue, if this still affecting you. |
# [9.12.0](software-mansion/react-native-svg@v9.11.1...v9.12.0) (2019-10-19) ### Bug Fixes * handle setting transform attribute on clipPath, fixes [#1152](software-mansion/react-native-svg#1152) ([73b21d1](software-mansion/react-native-svg@73b21d1)) * improve handling of transform attribute on clipPath, fixes [#1152](software-mansion/react-native-svg#1152) ([3aa126e](software-mansion/react-native-svg@3aa126e)) * **ios:** backwards compatible RCTImageLoader.h handling fixes [#1141](software-mansion/react-native-svg#1141) ([3c22c97](software-mansion/react-native-svg@3c22c97)) * **ios:** clipPath rendering, fixes [#1131](software-mansion/react-native-svg#1131) ([2534537](software-mansion/react-native-svg@2534537)) * **ios:** deprecation of RCTImageLoader fixes [#1141](software-mansion/react-native-svg#1141) ([5452144](software-mansion/react-native-svg@5452144)) * **ios:** fix changes in color/currentColor/tintColor, fixes [#1151](software-mansion/react-native-svg#1151) ([0c7e94d](software-mansion/react-native-svg@0c7e94d)) * **ios:** image viewBox opposite handling of y alignment, fixes [#1138](software-mansion/react-native-svg#1138) ([c69e9e2](software-mansion/react-native-svg@c69e9e2)) * **js:** allow setting stopColor/Opacity/Offset using styles, fix [#1153](software-mansion/react-native-svg#1153) ([5984e06](software-mansion/react-native-svg@5984e06)) * getPointAtLength signature ([2c57af2](software-mansion/react-native-svg@2c57af2)) * getScreenCTM calculation ([5c5072d](software-mansion/react-native-svg@5c5072d)) * improve native method spec conformance ([c63f9e2](software-mansion/react-native-svg@c63f9e2)) * improve types for getBBox ([cecde7d](software-mansion/react-native-svg@cecde7d)) * prepare script ([9a3dc4e](software-mansion/react-native-svg@9a3dc4e)) * **ios:** memory leak in tspan, fixes [#1073](software-mansion/react-native-svg#1073) ([974f3a8](software-mansion/react-native-svg@974f3a8)) * fix native methods spec conformance ([ecedb21](software-mansion/react-native-svg@ecedb21)) * Make native methods synchronous ([8ce7611](software-mansion/react-native-svg@8ce7611)) * refine types for matrix helpers ([409af91](software-mansion/react-native-svg@409af91)) * refine types for matrix helpers ([7a3f867](software-mansion/react-native-svg@7a3f867)) * **android:** defineMarker/getDefinedMarker storage ([e6eda84](software-mansion/react-native-svg@e6eda84)) * **android:** native method scaling and getScreenCTM offset ([f3e0b19](software-mansion/react-native-svg@f3e0b19)) * native method signatures web compatibility / spec conformance ([8687a3d](software-mansion/react-native-svg@8687a3d)) * **ios:** optimize extractPathData, clear PathMeasure when no textPath ([df69c26](software-mansion/react-native-svg@df69c26)) ### Features * **flow:** add flowgen to generate flow types from typescript, [#1125](software-mansion/react-native-svg#1125) ([fcd66fb](software-mansion/react-native-svg@fcd66fb)) * implement getBBox, getCTM, getScreenCTM ([f13d54a](software-mansion/react-native-svg@f13d54a)) * implement isPointInStroke ([2ba64df](software-mansion/react-native-svg@2ba64df)) * initial implementation of isPointInFill ([203e53b](software-mansion/react-native-svg@203e53b)) * support using native methods using promises instead of callbacks ([c28499b](software-mansion/react-native-svg@c28499b)) * **android:** implement getTotalLength and getPointAtLength ([cd667d0](software-mansion/react-native-svg@cd667d0)) * **ios:** implement getTotalLength and getPointAtLength ([78c4f20](software-mansion/react-native-svg@78c4f20))
Bug
I'm trying to use svg's which have some gradients, when I import them using as a file with react-native-svg-transformer I get the svg displayed but with a black color instead of keeping the defined colors/gradients.
Same happens if I convert the web svg into a react-native-svg component using svgr.now.sh
Svg file:
Svg displayed on react-native:
Environment info
Versions
Describe what you expected to happen:
Reproducible sample code with svg file and react component
/~https://github.com/tiagocorreiaitcenter/react-native-svg-file-test
The text was updated successfully, but these errors were encountered: