-
-
Notifications
You must be signed in to change notification settings - Fork 994
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
[Android] Change onTouchEvent
to dispatchTouchEvent
in NativeViewGestureHandler
#3244
Conversation
@@ -99,7 +99,7 @@ class NativeViewGestureHandler : GestureHandler<NativeViewGestureHandler>() { | |||
if (state == STATE_UNDETERMINED && !hook.canBegin(event)) { | |||
cancel() | |||
} else { | |||
view.onTouchEvent(event) | |||
view.dispatchTouchEvent(event) |
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.
Does this impact any other views? dispatchTouchEvent
sounds like it does something significantly different than onTouchEvent
.
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.
From my long journey through Android source code I can say that it is not entirely different. In short ViewGroup.dispatchTouchEvent
calls View.dispatchTouchEvent
, which calls View. performOnTouchCallback
, which calls View.onTouchEvent
. So in the end we still call this function. The thing is, beside calling onTouchEvent
indirectly, android also checks for interceptions and extracts touch target.
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.
I'll go through example app one more time and focus more on the examples that use NativeViewGestureHandler
.
Also, what exactly do you mean by
Does this impact any other views?
What do you think could be affected?
Also, I won't pretend I have the expertise to know much here, but I noticed there's one place that |
Yes, it is 😅 |
fun triggerEvent(event: MotionEvent) { | ||
val view = view!! | ||
|
||
if (view is ReactViewGroup) { | ||
view.dispatchTouchEvent(event) | ||
} else { | ||
view.onTouchEvent(event) | ||
} | ||
} |
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.
We may want this to be part of the native gesture hook, no?
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.
Good idea! Done in ac88178
/** | ||
* Decides whether or not target view should pass event to children. | ||
*/ | ||
fun triggerEvent(view: View?, event: MotionEvent) = view?.onTouchEvent(event) |
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.
/** | |
* Decides whether or not target view should pass event to children. | |
*/ | |
fun triggerEvent(view: View?, event: MotionEvent) = view?.onTouchEvent(event) | |
/** | |
* Passes the event down to the underlying view using the correct method. | |
*/ | |
fun sendTouchEvent(view: View?, event: MotionEvent) = view?.onTouchEvent(event) |
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.
Done in 4ca8726
android/src/main/java/com/swmansion/gesturehandler/core/NativeViewGestureHandler.kt
Outdated
Show resolved
Hide resolved
Co-authored-by: Jakub Piasecki <[email protected]>
just want to leave a comment that I started seeing |
Hi @lovegaoshi! Do you have any reproducible example? As far as I can see this package is not actively supported and depends on outdated versions of libraries, especially Gesture Handler. |
i think I'll just open an issue avoid polluting the PR tracker.thx for the attention! Let me clarify that the problem doesnt necessarily has to do with flashdraglist being unmaintained - at its core, its just an Animated wrapped flashlist with RNGH's ScrollView used as its renderScrollComponent. You can reproduce with simply that. while this is not exactly a minimum reproducer, I removed everything except the exact bug in index.js's entry point. You can build via git clone, yarn, yarn build, then build via Android Studio. Scrolling this list specifically on android 15 (emulator or real device) will yield this. |
Description
Currently wrapping
WebView
intoNativeViewGestureHandler
doesn't work as expected - events fromnative
gesture do not reachWebView
. This happens because insideNativeViewGestureHandler
we callonTouchEvent
method. In native hierarchyWebView
is nested insideViewGroup
, which means that callingonTouchEvent
instead ofdispatchTouchEvent
won't do anything to theWebView
.Should fix #2454
Fixes #3196
Test plan
Tested on example app and the code below:
Test code