software-mansion / react-native-gesture-handler

Declarative API exposing platform native touch and gesture system to React Native.
https://docs.swmansion.com/react-native-gesture-handler/
MIT License
6.14k stars 982 forks source link

Change `offsetX` and `offsetY` calculations in `PointerEventManager` #2938

Closed m-bert closed 5 months ago

m-bert commented 5 months ago

Description

While working on PointerTracker refactor and adding relativeCoords to it, I've noticed that offsetX/offsetY in PointerEventManager use PointerEvent.offsetX (and offsetY respectively) while TouchEventManager calculates this property by calculating the difference between clientX and bounding box (event.clientX - rect.left). I've decided to unify this behavior so that offset is now calculated in PointerEventManager the same way as in TouchEventManager.

As. you can see in the videos below, those 2 values may have different results - that is the main reason behind unifying them. offset property is used only in relativeCoords which have been recently introduced, so it won't be a breaking change.

Test plan

Tested by adding console.table in onPointerMove inside PanGestureHandler

div with Pan

image

Before

https://github.com/software-mansion/react-native-gesture-handler/assets/63123542/61918493-b667-49c5-88c5-bf5205336dae

After

https://github.com/software-mansion/react-native-gesture-handler/assets/63123542/a499a69e-52aa-4ed5-a4a4-826b9dc28a7e