https://kotlinlang.org logo
Title
m

Moritz Post

01/20/2022, 12:12 PM
Hello. I am using the
Canvas
composable in my compose desktop app. I have found that the
Canvas.onDraw
method is called multiple times although the size of the canvas has not canged. This leads to jank since the drawing is quite intensive. Next to the canvas i have a couple of items that are clickable() so they show hoover feedback for the mouse cursor. Even just hoovering over these unrelated items triggers a redraw of the canvas. Is there a way to circumvent this redrawing?
z

Zach Klippenstein (he/him) [MOD]

01/20/2022, 2:33 PM
Can you share your code?
m

Moritz Post

01/20/2022, 2:33 PM
i will try to come up with a smaller example
z

Zach Klippenstein (he/him) [MOD]

01/20/2022, 2:35 PM
If you're showing visual indication of hover state I'm guessing that is probably causing the whole layer to redraw. You could try putting a
graphicsLayer
modifier on your Canvas.
m

Moritz Post

01/20/2022, 2:36 PM
Interesting as well i will look into.
Late update but your were right about the .graphicsLayer() modifier. It does resolve to redraw issue.
k

Kebbin

01/27/2022, 2:49 AM
Thanks for sharing! So what did you put in the
.graphicsLayer()
modifier to make it work? The hover state animations?