My project uses React Konva (https://github.com/konvajs/react-konva)
I am trying to draw multiple shapes into a Group
and use this to mask the image "below".
When my component draws a single shape with globalCompositeOperation
applied, it produces the expected result. Here's the code:
render() {
return (
<Group >
<Group>
<Image
image={this.state.image}
ref={node => { this.image = node; }}
/>
<Group>
<Rect fill={"#555555"}
width={200} height={200}
x={100} y={100}
globalCompositeOperation={"destination-in"}
/>
</Group>
</Group>
</Group>
)
}
Notice how the image is cropped to the rectangle, revealing the text layer below.
However, as soon as the shape moves inside a Group, and I apply the globalCompositeOperation
there, no masking happens. The relevant part of the code:
<Group>
<Image
image={this.state.image}
ref={node => { this.image = node; }}
/>
<Group globalCompositeOperation={"destination-in"}>
<Rect fill={"#555555"}
width={200} height={200}
x={100} y={100}
/>
</Group>
</Group>
And the result:
This is odd because the Konva documentation indicates that Group
does in fact have a property globalCompositeOperation
(see https://konvajs.github.io/api/Konva.Group.html#globalCompositeOperation__anchor).
Any idea how to get (React) Konva to apply the globalCompositeOperation
at the Group
level rather than just at the Shape
level?