From 36e752c5c099a27be707e4f7cf252dfbd47b0ed7 Mon Sep 17 00:00:00 2001 From: Patrik Sletmo Date: Tue, 24 Oct 2023 14:31:40 +0300 Subject: [PATCH] fix(android): scrolling hotfix (#4225) --- .../espresso/action/common/MotionEvents.kt | 33 +++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/detox/android/detox/src/main/java/com/wix/detox/espresso/action/common/MotionEvents.kt b/detox/android/detox/src/main/java/com/wix/detox/espresso/action/common/MotionEvents.kt index d8fc451c18..502ad40838 100644 --- a/detox/android/detox/src/main/java/com/wix/detox/espresso/action/common/MotionEvents.kt +++ b/detox/android/detox/src/main/java/com/wix/detox/espresso/action/common/MotionEvents.kt @@ -9,8 +9,37 @@ import androidx.test.espresso.action.MotionEvents private val PRECISION = floatArrayOf(16f, 16f) class MotionEvents { - fun obtainMoveEvent(downEvent: MotionEvent, eventTime: Long, x: Float, y: Float): MotionEvent - = MotionEvents.obtainMovement(downEvent.downTime, eventTime, floatArrayOf(x, y))!! + fun obtainMoveEvent(downEvent: MotionEvent, eventTime: Long, x: Float, y: Float): MotionEvent { + val pointerProperties = MotionEvent.PointerProperties().apply { + clear() + id = 0 + toolType = MotionEvent.TOOL_TYPE_UNKNOWN + } + val pointerCoords = MotionEvent.PointerCoords().apply { + clear() + this.x = x + this.y = y + this.pressure = 0f + this.size = 1f + } + + return MotionEvent.obtain( + downEvent.downTime, + eventTime, + MotionEvent.ACTION_MOVE, + 1, // pointerCounts + arrayOf(pointerProperties), + arrayOf(pointerCoords), + 0, // metaState + downEvent.buttonState, + downEvent.xPrecision, + downEvent.yPrecision, + 0, // deviceId + 0, // edgeFlags + downEvent.source, + 0 + ) + } fun obtainDownEvent(x: Float, y: Float, precision: FloatArray = PRECISION) = obtainDownEvent(x, y, precision, null)