-
Notifications
You must be signed in to change notification settings - Fork 18
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
Implement useDrag
hook
#1478
Implement useDrag
hook
#1478
Conversation
137cdec
to
8d997f3
Compare
41492f3
to
469ffda
Compare
0a30281
to
4f117f6
Compare
@loichuder I've moved the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good !
I wonder if we should not expose a ref
handler that consumers will pass to the draggable element instead of having to set themselves startDrag
to onPointerDown
. It is just an idea: it is fine like this and more easily extendable.
Yeah I did consider this solution, but the problem is that we don't know enough to register the event handler ourselves: perhaps the consumer wants to check for a modifier key or a mouse button, perhaps they're implementing a canvas interaction and need to call |
This looked handy to me until I tried to integrate it into DvdDragHandle.tsx and came across a limitation that it's tied to the r3f layer. In Davidia, each selection shape has a number of drag handles and the handles are created as children within those shapes (see, e.g., DvdAxisBox.tsx). Each shape is created as an SVGElement (see createShape). I guess significant refactoring of the selection classes in Davidia's code may be needed to lift the drag handles creation to that |
Thanks for sharing the link to your repo. It looks like Davidia is really taking shape (pun intended 🥁)! It's good to see another project using Regarding |
My comment was mainly feedback but pushing down |
I think it's the fact that I create drag handles programmatically so they are not children of |
This should hopefully make implementing draggable interactions easier (e.g. moving/resizing ROIs), though I'm hoping it will also abstract out a lot of the code from
SelectionTool
andPan
.The approach taken by
@visx/drag
is not great for us because of our multiple coordinate spaces and because it requires capturing events on a transparent rectangle on top of the element that is being dragged.Instead, the approach I'm proposing makes use of the new event bubbling mechanism introduced in #1473:
useDrag
automatically registers thepointermove
andpointerup
event handlers oncanvasWrapper
withuseCanvasEvents
, thus making sure that no events are missed. The consumer only needs to register apointerdown
handler on the draggable element.I've created a story to demonstrate the use of
useDrag
and how pretty straightforward it is: