Skip to content

Commit 4b9b0bc

Browse files
authored
Fix missing begin event on Android for Pinch and Rotation (#2264)
## Description This PR sets the focal point/anchor to the position of the pointer before sending `begin` event on Android. At the position it's being sent, it's always `NaN` at the moment, which causes the event not to be received by the detector. ## Test plan Add pinch & rotation gestures to the app and check whether the `begin` event is called.
1 parent 108b78b commit 4b9b0bc

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

android/src/main/java/com/swmansion/gesturehandler/core/PinchGestureHandler.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ class PinchGestureHandler : GestureHandler<PinchGestureHandler>() {
5757
scaleGestureDetector = ScaleGestureDetector(context, gestureListener)
5858
val configuration = ViewConfiguration.get(context)
5959
spanSlop = configuration.scaledTouchSlop.toFloat()
60+
61+
// set the focal point to the position of the first pointer as NaN causes the event not to arrive
62+
this.focalPointX = event.x
63+
this.focalPointY = event.y
64+
6065
begin()
6166
}
6267
scaleGestureDetector?.onTouchEvent(sourceEvent)

android/src/main/java/com/swmansion/gesturehandler/core/RotationGestureHandler.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ class RotationGestureHandler : GestureHandler<RotationGestureHandler>() {
4545
if (state == STATE_UNDETERMINED) {
4646
resetProgress()
4747
rotationGestureDetector = RotationGestureDetector(gestureListener)
48+
49+
// set the anchor to the position of the first pointer as NaN causes the event not to arrive
50+
this.anchorX = event.x
51+
this.anchorY = event.y
52+
4853
begin()
4954
}
5055
rotationGestureDetector?.onTouchEvent(sourceEvent)

0 commit comments

Comments
 (0)