ClipPath appears to be broken
See original GitHub issueHello! I’m trying to use ClipPath
to cut a circle in a rect in order to highlight what is underneath that circle. Issue #936 covers this and there is a handy answer that says this code should do it:
import React from 'react';
import { View } from 'react-native';
import Svg, { Defs, ClipPath, Circle, Rect } from 'react-native-svg';
export default class App extends React.Component {
render() {
return (
<View
style={{
flex: 1,
alignContent: 'center',
justifyContent: 'center',
backgroundColor: '#ecf0f1',
}}
>
<Svg width="100%" height="100%" viewBox="0 0 100 100">
<Defs>
<ClipPath id="clip_out" clipRule="evenodd">
<Rect width={100} height={100}/>
<Circle cx={50} cy={50} r={25}/>
</ClipPath>
</Defs>
<Rect width={100} height={100} fill="green" clipPath="url(#clip_out)" />
</Svg>
</View>
);
}
}
Unfortunately the circle does not get cut out. It seems that ClipRule
may be failing, but I’m not sure. Here is a snack that shows the behavior.
Issue Analytics
- State:
- Created 4 years ago
- Comments:22
Top Results From Across the Web
ClipPath appears to be broken · Issue #983 - GitHub
Another workaround is to use a single Path in the ClipPath: Correction, this is the spec conformant way to get nonzero clip-rule. But,...
Read more >Clip path seems to be broken - Stack Overflow
I am working on a project where I need to use a Polygon shaped container. I managed to make it work on chrome...
Read more >Unfortunately, clip-path: path() is Still a No-Go - CSS-Tricks
I went on CodePen, dropped a <div> in the HTML panel, gave it dimensions in viewport units so that it scales nicely, added...
Read more >clip-path - CSS: Cascading Style Sheets - MDN Web Docs
The clip-path CSS property creates a clipping region that sets what part of an element should be shown. Parts that are inside the...
Read more >450256 - HTML clipped with SVG <clipPath> not repainted ...
Steps to reproduce the problem: 1. In the linked pen, an SVG `<clipPath>` is applied to a `<div>` using `-webkit-clip-path`. 2. Adjust the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
ClipPath (with Rect) appears to be broken again, on iOS.
Another workaround is to use a single Path in the ClipPath: Correction, this is the spec conformant way to get nonzero clip-rule. But, setting it to evenodd on the Path element inside the ClipPath doesn’t affect anything in react-native-svg right now, it needs to be set on the ClipPath element, which isn’t part of the svg spec, as it only allows it to affect anything on elements which are direct descendants of a clip-path element, if I understand it correctly.