Skip to content

Commit

Permalink
fix(android): scrolling hotfix (#4225)
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrik Sletmo authored and noomorph committed Oct 24, 2023
1 parent 3efcddd commit 36e752c
Showing 1 changed file with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 36e752c

Please sign in to comment.