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

Listening to mouse events without capturing them? #581

Closed
kyldvs opened this issue Oct 2, 2019 · 3 comments
Closed

Listening to mouse events without capturing them? #581

kyldvs opened this issue Oct 2, 2019 · 3 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@kyldvs
Copy link
Contributor

kyldvs commented Oct 2, 2019

I'm trying to make a drag & drop module and have made a lot of progress. Right now I'm using Mouse.setCapture to track mouse moves and rendering the element being dragged based on those events.

The problem is that I don't want to capture these events. When I call setCapture then none of my other views get mouse enter/leave/etc events.

Is there a way to have something like Mouse.listen(~onMouseMove, ()) that doesn't prevent other components from getting the events?

(I'd also like this to be global, any time I tried wrapping the root of my app in a <View /> with an onMouseMove the rendering broke. I'd be open to this approach if there was a way to make it work, but the global listener just seems really convenient.)

This is the code I have right now: https://github.com/kyldvs/chesster/blob/master/src/drag/Drag.re

@kyldvs
Copy link
Contributor Author

kyldvs commented Oct 2, 2019

I made this branch which seems to be working, I can submit as a PR if the API seems okay: https://github.com/revery-ui/revery/compare/master...kyldvs:mouse-listeners?expand=1

I'm also not familiar enough with all the mouse/event propagation to know if my approach is going to be slow/buggy.

@bryphe
Copy link
Member

bryphe commented Oct 2, 2019

@kyldvs - ah, ya, we really didn't have a convenient way to do this.

I like your idea of the Mouse.listen / Mouse.registerListeners API - I can see where it would be convenient vs setCapture or listening to individual <View /> elements.

(I'd also like this to be global, any time I tried wrapping the root of my app in a with an onMouseMove the rendering broke. I'd be open to this approach if there was a way to make it work, but the global listener just seems really convenient.)

Ya, unfortunately the nested <View /> impacts layouts - even if it has no style. I'd like to explore how to improve this as part of the next iteration of our component model (some thoughts in #489 ).

I made this branch which seems to be working, I can submit as a PR if the API seems okay: https://github.com/revery-ui/revery/compare/master...kyldvs:mouse-listeners?expand=1

Awesome! API looks good to me 👍

I think this would be a useful addition, and there is a clear use case for it in your app. A PR would definitely be welcome!

I'm also not familiar enough with all the mouse/event propagation to know if my approach is going to be slow/buggy.

This should be OK; the most expensive aspect of handling the mouse events is traversing the node hierarchy to figure out which node the mouse is 'on'. The proposed change doesn't hit that hot path though.

@bryphe bryphe added enhancement New feature or request help wanted Extra attention is needed labels Oct 2, 2019
@bryphe
Copy link
Member

bryphe commented Oct 3, 2019

Fixed by #583 - thanks @kyldvs !

@bryphe bryphe closed this as completed Oct 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants