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

Detecting (long) clicks with position is not supported #434

Open
mhoff opened this issue Feb 27, 2018 · 2 comments
Open

Detecting (long) clicks with position is not supported #434

mhoff opened this issue Feb 27, 2018 · 2 comments

Comments

@mhoff
Copy link

mhoff commented Feb 27, 2018

This issue might be a duplicate of #172 -- has there been some progress meanwhile?

I want to use RxBindings to implement a custom component which is drawn on canvas. For this, I need clicks, long clicks, double clicks etc. together with the precise location of these events.

What is possible:

  • react on clicks and long clicks on Views using RxView.clicks() and RxView.longClicks()
  • react on touch events using RxView.touches() which supplies MotionEvents conveying the position information

However, the combination, detecting a click and having the position of the click at hand seems not to be supported. In particular, a combined approach using something like view.longClicks().withLatestFrom(view.touches()) does not produce any results at all. I guess this is one of the cases which are simply not supported by this project.

[@JakeWharton just started to use Rx* and love the concept, keep up the good work]

@JakeWharton
Copy link
Owner

The information provided is the same information that is available to the callback. So if you were using a long click listener callback directly you wouldn't have any touch information. I don't know how you do something like this. Perhaps listen to touches and figure out click/long click timings yourself? And then you have the MotionEvent as to the location. I don't think there's anything the library can do for you though since it's just relaying the events it gets.

@mhoff
Copy link
Author

mhoff commented Feb 27, 2018

I believe an operation like view.longClicks().withLatestFrom(view.touches()) would produce exactly that result in an intuitive way (assuming withLatestFrom(view.touches()) is not too expensive). This approach is probably not working because of an low-level issue regarding the listeners required for this task. I understand that this is something you will not support:

The library is not responsible for supporting multiple observables bound to the same view

Another approach would be to use a GestureDetector and use it as a sink for the touches() events. In turn, the detector could produce different event streams for single clicks, long clicks, double clicks etc (basically everything SimpleOnGestureListener provides). However, this would require an intermediate object (which has to be taken care of ..) plus logic to handle the different streams. So, I guess this is also not in scope of this library.

I conclude that both approaches are unfortunately not in scope of this library. Feel free to close this issue.

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

2 participants