Skip to content

Commit 23c6413

Browse files
authored
[Android] Check all pointers in move events (#4010)
## Description When one pointer is placed on the background, handlers don't to other pointers. Instead, they fail on [this line](https://github.com/software-mansion/react-native-gesture-handler/blob/41fbd374a85def52eb7051f96e3d4c63e6eb0724/packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandlerOrchestrator.kt#L295). This is because on Android events with `ACTION_MOVE` are batched and all pointers are contained within one event. As [Android docs say](https://developer.android.com/reference/android/view/MotionEvent#getActionIndex()), `actionIndex` is fine to check for up and down actions. However, we use it for move action and it always returns `0`. To solve this problem, I've added loop that checks whether any pointer from event is tracked by the handler. Fixes #3995 ## Test plan Tested on example code from #3995
1 parent 5429e5e commit 23c6413

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

  • packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/core

packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandler.kt

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -644,11 +644,22 @@ open class GestureHandler {
644644
onStateChange(newState, oldState)
645645
}
646646

647-
fun wantsEvent(event: MotionEvent): Boolean = isEnabled &&
648-
state != STATE_FAILED &&
649-
state != STATE_CANCELLED &&
650-
state != STATE_END &&
651-
isTrackingPointer(event.getPointerId(event.actionIndex))
647+
fun wantsEvent(event: MotionEvent): Boolean {
648+
if (!isEnabled || state == STATE_FAILED || state == STATE_CANCELLED || state == STATE_END) {
649+
return false
650+
}
651+
652+
if (event.actionMasked == MotionEvent.ACTION_MOVE) {
653+
for (i in 0 until event.pointerCount) {
654+
if (isTrackingPointer(event.getPointerId(i))) {
655+
return true
656+
}
657+
}
658+
return false
659+
} else {
660+
return isTrackingPointer(event.getPointerId(event.actionIndex))
661+
}
662+
}
652663

653664
open fun shouldRequireToWaitForFailure(handler: GestureHandler): Boolean {
654665
if (handler === this) {

0 commit comments

Comments
 (0)