Skip to content

Commit 294caa7

Browse files
committed
fix(android): always include changedTouches and allTouches in touch events
1 parent 6fdee58 commit 294caa7

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,14 @@ class RNGestureHandlerTouchEvent private constructor() : Event<RNGestureHandlerT
6969
putInt("eventType", handler.touchEventType)
7070
putInt("pointerType", handler.pointerType)
7171

72-
handler.consumeChangedTouchesPayload()?.let {
73-
putArray("changedTouches", it)
74-
}
72+
// Both keys have to be present in every touch event, otherwise the JS side may
73+
// misclassify it as an update event and crash trying to read gesture-specific data.
74+
// The payloads may be null when the tracked pointers were cleared before the event
75+
// was serialized (e.g. the gesture was cancelled by a rapid succession of taps) or
76+
// when the payload was already consumed - fall back to empty arrays, matching iOS.
77+
putArray("changedTouches", handler.consumeChangedTouchesPayload() ?: Arguments.createArray())
7578

76-
handler.consumeAllTouchesPayload()?.let {
77-
putArray("allTouches", it)
78-
}
79+
putArray("allTouches", handler.consumeAllTouchesPayload() ?: Arguments.createArray())
7980

8081
if (handler.isAwaiting && handler.state == GestureHandler.STATE_ACTIVE) {
8182
putInt("state", GestureHandler.STATE_BEGAN)

0 commit comments

Comments
 (0)