Skip to content

Commit e76417d

Browse files
committed
PANA-5681: Use window-relative coordinates for touch position
1 parent 087cbc5 commit e76417d

2 files changed

Lines changed: 10 additions & 7 deletions

File tree

features/dd-sdk-android-rum/src/main/kotlin/com/datadog/android/rum/internal/instrumentation/gestures/GesturesListener.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -270,12 +270,12 @@ internal class GesturesListener(
270270
addViewAttributes(view, attributes)
271271

272272
if (view.isAttachedToWindow) {
273-
val locationOnScreen = IntArray(2)
274-
@Suppress("UnsafeThirdPartyFunctionCall") // locationOnScreen is non-null with exactly 2 elements
275-
view.getLocationOnScreen(locationOnScreen)
273+
val locationInWindow = IntArray(2)
274+
@Suppress("UnsafeThirdPartyFunctionCall") // locationInWindow is non-null with exactly 2 elements
275+
view.getLocationInWindow(locationInWindow)
276276

277-
val relativeX = (touchX - locationOnScreen[0]).toLong()
278-
val relativeY = (touchY - locationOnScreen[1]).toLong()
277+
val relativeX = (touchX - locationInWindow[0]).toLong()
278+
val relativeY = (touchY - locationInWindow[1]).toLong()
279279

280280
attributes[RumAttributes.INTERNAL_ACTION_POSITION_X] = relativeX
281281
attributes[RumAttributes.INTERNAL_ACTION_POSITION_Y] = relativeY

features/dd-sdk-android-rum/src/test/kotlin/com/datadog/android/rum/internal/instrumentation/gestures/GesturesListenerTapTest.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -837,13 +837,16 @@ internal class GesturesListenerTapTest : AbstractGesturesListenerTest() {
837837
forge = forge,
838838
clickable = true
839839
)
840-
// Mock getLocationOnScreen to return a specific position
841-
whenever(validTarget.getLocationOnScreen(any())).doAnswer { invocation ->
840+
// Mock getLocationInWindow to return a specific position
841+
whenever(validTarget.getLocationInWindow(any())).doAnswer { invocation ->
842842
val array = invocation.arguments[0] as IntArray
843843
array[0] = targetX
844844
array[1] = targetY
845845
null
846846
}
847+
// Ensure the view dimensions are large enough for the hit test to pass
848+
whenever(validTarget.width).thenReturn((touchX - targetX).toInt() + 1)
849+
whenever(validTarget.height).thenReturn((touchY - targetY).toInt() + 1)
847850
mockDecorView = mockDecorView<ViewGroup>(
848851
id = forge.anInt(),
849852
forEvent = mockEvent,

0 commit comments

Comments
 (0)