Konva object snapping with transformer jitters

Viewed 20

I'm trying to make an editor using Konva.js.

In the editor I show a smaller draw area which becomes the final image. For this I'm using a group with a clipFunc. This gives a better UX since the transform controls of the transformer can be used "outside" of the canvas (visible part for the user) and allow the user to zoom and drag the draw area around (imagine a frame in Figma).

I want to implement object snapping based on this: https://konvajs.org/docs/sandbox/Objects_Snapping.html. (just edges and center for now) However I want it to be able to work when having multiple elements selected in my Transformer.

The strategy I'm using is basically calculating the snapping based on the .back element created by the transformer. When I know how much to snap I apply it to every node within the transformer.

However when doing it, the items starts jittering when moving the cursor close to the snapping lines.

My previous implementation was having the draw area fill the entire Stage, which I did manage to get working with the same strategy. (no jitter)

I don't really know what the issue is and I hope some of you guys can point me in the right direction.

I created a codepen to illustrate my issue: https://codesandbox.io/s/konva-transformer-snapping-1vwjc2?file=/src/index.ts

0 Answers
Related