question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ClipPath is not working properly on Android without clipRule prop

See original GitHub issue

Bug

Screenshot 2020-06-29 at 18 34 54

Looks like ClipPath has only id prop, but at the same time code below do not working properly on android without this prop

Environment info

 System:
    OS: macOS 10.15.5
    CPU: (8) x64 Intel(R) Core(TM) i7-4980HQ CPU @ 2.80GHz
    Memory: 19.82 MB / 16.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 12.2.0 - ~/.nvm/versions/node/v12.2.0/bin/node
    Yarn: 1.22.4 - /usr/local/bin/yarn
    npm: 6.14.5 - ~/.nvm/versions/node/v12.2.0/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.9.1 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: iOS 13.5, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2
    Android SDK: Not Found
  IDEs:
    Android Studio: 3.6 AI-192.7142.36.36.6392135
    Xcode: 11.5/11E608c - /usr/bin/xcodebuild
  Languages:
    Java: 9.0.4 - /usr/bin/javac
    Python: 2.7.16 - /usr/bin/python
  npmPackages:
    @react-native-community/cli: Not Found
    react: 16.11.0 => 16.11.0 
    react-native: 0.62.2 => 0.62.2 
  npmGlobalPackages:
    *react-native*: Not Found

Library version: 12.1.0

Steps To Reproduce

Issues without reproduction steps or code are likely to stall.

  1. Use code below
  2. Try it with // @ts-ignore clipRule={'evenodd'} and without

Describe what you expected to happen:

  1. It should work without it OR need to fix the TS (types)

Short, Self Contained, Correct (Compilable), Example

<Svg width={'100%'} height={'100%'} viewBox={'0 0 256 340'}>
              <Defs>
                <Rect
                  id={'backgroundRect'}
                  x={-1}
                  y={-1}
                  width={258}
                  height={342}
                  fill={BACKGROUND_COLOR}
                />
                <Rect
                  id={'faceOvalRect'}
                  x={1}
                  y={1}
                  width={254}
                  height={338}
                  ry={127}
                  stroke={'#fff'}
                  strokeWidth={2}
                />

                <ClipPath
                  id={'clip'}
                  // @ts-ignore
                  clipRule={'evenodd'}
                >
                  <G>
                    <Use href={'#backgroundRect'} />

                    <Use href={'#faceOvalRect'} />
                  </G>
                </ClipPath>
              </Defs>

              <Use
                href={'#backgroundRect'}
                clipPath={'url(#clip)'}
                clipRule={'evenodd'}
              />

              <Use href={'#faceOvalRect'} />
            </Svg>

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
mshavandicommented, Sep 27, 2021

I finally got around this issue with an odd solution! (I also update react-native-svg to12.1.1 but no luck)

It was working fine in iOS even without clipRule parameter, so I ended up changing clipRule to its other variant whenever the props.data was changing (only when the device is android). so this is my workaround that works on both iOS and android:

    const [clipRule, setClipRule] = React.useState('evenodd')
    React.useEffect(()=>{
     if(Platform.OS === 'android') {
       setClipRule(clipRule==='evenodd' ? 'nonzero' : 'evenodd')
     }

and finally give this clipRule state as a prop to your <ClipPath/> component, like:

    <ClipPath id={"clip"} clipRule={clipRule} >
     ...
    </ClipPath>

I wish I was kidding but this works!

1reaction
SaeedZhianycommented, Apr 12, 2021

@magicismight

why the new version does not follow semantic version rules? is it a stable version or an RC version? (I just think 12.1.1 was better)

also, please consider updating the changelog if you have time for it. Thanks

Read more comments on GitHub >

github_iconTop Results From Across the Web

ClipPath is not working properly on Android without clipRule ...
Bug Looks like ClipPath has only id prop, but at the same time code below do not working properly on android without this...
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 >
CSS clip-path not working in Chrome 63 - Stack Overflow
Seems that Chrome has partial support to clip-path, to shapes and inline svgs. But even with the shape property, it isn't working properly....
Read more >
Clipping, Masking and Compositing – SVG 1.1 (Second Edition)
For all other elements, the property has no effect (i.e., a clipping rectangle is not ... A clipping path is used/referenced using the...
Read more >
CSS clip-path property (for HTML) | Can I use... Support tables ...
Support refers to the clip-path CSS property on HTML elements specifically. Support for clip-path in SVG is supported in all browsers with basic...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found