Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot override shape.rotation() in on transform event #1724

Closed
VanquishedWombat opened this issue Feb 20, 2024 · 0 comments
Closed

Cannot override shape.rotation() in on transform event #1724

VanquishedWombat opened this issue Feb 20, 2024 · 0 comments

Comments

@VanquishedWombat
Copy link
Contributor

Version: Konva 9+

Summary: We can use the shape.onTransform method like a dragBoundFunc to limit where the shape may be placed etc. However, we cannot override the shape.rotation().

Cause: In Transformer.ts in method _fitNodesInto(), the loop that invokes the shape.onTransform event on the nodes in the transformer.nodes list runs before the setting of the transformer rotation. Which means that we can never override the transformer rotation with code in the shape.onTransform event.

Workaround: Only one I found is to place the code altering the rotation into a setTimeout(fn, 0). My assumption is that this is added to the end of the execution queue with the result that it runs after the _fitNodesInto() code is completed. However this is a poor workaround and may not give a pleasing UX result if a processor has a heavy workload or is overloaded.

Solution: In _fitNodesInto() reposition the setting of the transformer rotation above the transformer.nodes[] onTransform loop.

Demo: See https://codepen.io/JEE42/pen/abMMevp

Example image:
2024-02-20_10-22-14

@lavrton lavrton closed this as completed in b09ceb3 Mar 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant