Touch event is not emitted when handled func returns false in ViewTouchOnSubscribe
See original GitHub issueHi. Before creating a PR I would like to ask you guys if I’m right. ViewTouchOnSubscribe
class which is internally used during for example RxView.touches
method contains:
@Override public void call(final Subscriber<? super MotionEvent> subscriber) {
checkUiThread();
View.OnTouchListener listener = new View.OnTouchListener() {
@Override public boolean onTouch(View v, @NonNull MotionEvent event) {
if (handled.call(event)) {
if (!subscriber.isUnsubscribed()) {
subscriber.onNext(event);
}
return true;
}
return false;
}
};
view.setOnTouchListener(listener);
subscriber.add(new MainThreadSubscription() {
@Override protected void onUnsubscribe() {
view.setOnTouchListener(null);
}
});
}
Current implementation probably blocks possibility to handle emitted MotionEvent
when handled
function returns false for example:
RxView.touches(someEditText, motionEvent -> false)
.subscribe(event -> {
// do something here
});
In above case, no value will be emitted. When it’s needed? When we want to detect touch on EditText
widget and don’t “consume” the MotionEvent
. We can’t consume it if we just want to make some extra action but keep EditText
to get focus (that’s why handled have to return false
).
My proposed solution:
View.OnTouchListener listener = new View.OnTouchListener() {
@Override public boolean onTouch(View v, @NonNull MotionEvent event) {
if (!subscriber.isUnsubscribed()) {
subscriber.onNext(event);
}
return handled.call(event);
}
};
Am I correct or I did something wrong?
Issue Analytics
- State:
- Created 8 years ago
- Reactions:7
- Comments:15 (3 by maintainers)
Top Results From Across the Web
Manage touch events in a ViewGroup - Android Developers
If onInterceptTouchEvent() returns true , the MotionEvent is intercepted, ... false // Do not intercept touch event, let the child handle it
Read more >Touch events - Web APIs - MDN Web Docs - Mozilla
When a touchstart event occurs, indicating that a new touch on the surface has occurred, the handleStart() function below is called. function ......
Read more >Touch Event Not Returning Touch Data - Stack Overflow
There are two issues at play here: 1) When using jQuery, you have to use originalEvent (as VSO notes here) 2) When inspecting...
Read more >KYOCERA Hydro XTRM
The home screen is the starting point for all applications, functions, and menus. From any application screen, touch Home to return to the...
Read more >Introduction - Buick
The RKE transmitter functions may work up ... on the driver door handle will unlock the ... When replacing the battery, do not...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
If the
e -> false
predicate returns false,.onNext()
doesn’t get called.My use case is that I want to observe touch events without consuming them.
From ViewTouchObservable
Any progress on an approach to take here?
I have a case with nested ViewPagers where the inner ViewPager needs to prevent the parent from changing pages if the inner’s current item is the first or last item. Following this, the inner ViewPager automatically changes it’s current item after a period of time, but this needs to be cancelled on
ACTION_MOVE
.