{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

TouchInjectionScope

public interface TouchInjectionScope extends InjectionScope


The receiver scope of the touch input injection lambda from performTouchInput.

The functions in TouchInjectionScope can roughly be divided into two groups: full gestures and individual touch events. The individual touch events are: down, move and friends, up, cancel and advanceEventTime. Full gestures are all the other functions, like click, doubleClick, swipe, etc. These are built on top of the individual events and serve as a good example on how you can build your own full gesture functions.

A touch gesture is started with a down event, followed by a sequence of move events and finally an up event, optionally combined with more sets of down and up events for multi-touch gestures. Most methods accept a pointerId to specify which pointer (finger) the event applies to. Movement can be expressed absolutely with moveTo and updatePointerTo, or relative to the current pointer position with moveBy and updatePointerBy. The moveTo/By methods enqueue an event immediately, while the updatePointerTo/By methods don't. This allows you to update the position of multiple pointers in a single move event for multi-touch gestures. Touch gestures can be cancelled with cancel. All events, regardless the method used, will always contain the current position of all pointers.

The entire event injection state is shared between all perform.*Input methods, meaning you can continue an unfinished touch gesture in a subsequent invocation of performTouchInput or performMultiModalInput. Note however that while the pointer positions are retained across invocation of perform.*Input methods, they are always manipulated in the current node's local coordinate system. That means that two subsequent invocations of performTouchInput on different nodes will report a different currentPosition, even though it is actually the same position on the screen.

All events sent by these methods are batched together and sent as a whole after performTouchInput has executed its code block. Because gestures don't have to be defined all in the same performTouchInput block, keep in mind that while the gesture is not complete, all code you execute in between these blocks will be executed while imaginary fingers are actively touching the screen. The events sent as part of the same batch will not be interrupted by recomposition, however, if a gesture spans multiple performTouchInput blocks it is important to remember that recomposition, layout and drawing could take place during the gesture, which may lead to events being injected into a moving target. As pointer positions are manipulated in the current node's local coordinate system, this could lead to issues caused by the fact that part of the gesture will take effect before the rest of the events have been enqueued.

Example of performing a click:

import androidx.compose.ui.test.click
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.performTouchInput

composeTestRule.onNodeWithTag("myComponent")
    .performTouchInput { click() }

Example of performing a swipe up:

import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.performTouchInput
import androidx.compose.ui.test.swipeUp

composeTestRule.onNodeWithTag("myComponent")
    .performTouchInput { swipeUp() }

Example of performing an L-shaped gesture:

import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.performTouchInput

composeTestRule.onNodeWithTag("myComponent")
    .performTouchInput {
        down(topLeft)
        moveTo(topLeft + percentOffset(0f, .1f))
        moveTo(topLeft + percentOffset(0f, .2f))
        moveTo(topLeft + percentOffset(0f, .3f))
        moveTo(topLeft + percentOffset(0f, .4f))
        moveTo(centerLeft)
        moveTo(centerLeft + percentOffset(.1f, 0f))
        moveTo(centerLeft + percentOffset(.2f, 0f))
        moveTo(centerLeft + percentOffset(.3f, 0f))
        moveTo(centerLeft + percentOffset(.4f, 0f))
        moveTo(center)
        up()
    }
See also
InjectionScope

Summary

Public methods

abstract void
cancel(long delayMillis)

Sends a cancel event delayMillis after the last sent event to cancel the current gesture.

abstract Offset
currentPosition(int pointerId)

Returns the current position of the given pointerId.

default void
down(@NonNull Offset position)

Sends a down event for the default pointer at position on the associated node.

abstract void
down(int pointerId, @NonNull Offset position)

Sends a down event for the pointer with the given pointerId at position on the associated node.

abstract void
move(long delayMillis)

Sends a move event delayMillis after the last sent event without updating any of the pointer positions.

default void
moveBy(@NonNull Offset delta, long delayMillis)

Sends a move event delayMillis after the last sent event on the associated node, with the position of the default pointer moved by the given delta.

default void
moveBy(int pointerId, @NonNull Offset delta, long delayMillis)

Sends a move event delayMillis after the last sent event on the associated node, with the position of the pointer with the given pointerId moved by the given delta.

default void
moveTo(@NonNull Offset position, long delayMillis)

Sends a move event delayMillis after the last sent event on the associated node, with the position of the default pointer updated to position.

default void
moveTo(int pointerId, @NonNull Offset position, long delayMillis)

Sends a move event delayMillis after the last sent event on the associated node, with the position of the pointer with the given pointerId updated to position.

default void
@ExperimentalTestApi
moveWithHistory(
    @NonNull List<@NonNull Long> relativeHistoricalTimes,
    @NonNull List<@NonNull Offset> historicalCoordinates,
    long delayMillis
)

Sends a move event delayMillis after the last sent event without updating any of the pointer positions.

abstract void
@ExperimentalTestApi
moveWithHistoryMultiPointer(
    @NonNull List<@NonNull Long> relativeHistoricalTimes,
    @NonNull List<@NonNull List<@NonNull Offset>> historicalCoordinates,
    long delayMillis
)

Sends a move event delayMillis after the last sent event without updating any of the pointer positions.

abstract void
up(int pointerId)

Sends an up event for the pointer with the given pointerId, or the default pointer if pointerId is omitted, on the associated node.

default void
updatePointerBy(int pointerId, @NonNull Offset delta)

Updates the position of the pointer with the given pointerId by the given delta, but does not send a move event.

abstract void
updatePointerTo(int pointerId, @NonNull Offset position)

Updates the position of the pointer with the given pointerId to the given position, but does not send a move event.

Extension functions

default final void
TouchInjectionScopeKt.click(
    @NonNull TouchInjectionScope receiver,
    @NonNull Offset position
)

Performs a click gesture (aka a tap) on the associated node.

default final void
TouchInjectionScopeKt.doubleClick(
    @NonNull TouchInjectionScope receiver,
    @NonNull Offset position,
    long delayMillis
)

Performs a double click gesture (aka a double tap) on the associated node.

default final void
TouchInjectionScopeKt.longClick(
    @NonNull TouchInjectionScope receiver,
    @NonNull Offset position,
    long durationMillis
)

Performs a long click gesture (aka a long press) on the associated node.

default final void
@ExperimentalTestApi
TouchInjectionScopeKt.multiTouchSwipe(
    @NonNull TouchInjectionScope receiver,
    @NonNull List<@NonNull Function1<@NonNull Long, @NonNull Offset>> curves,
    long durationMillis,
    @NonNull List<@NonNull Long> keyTimes
)

Performs a multi touch swipe gesture on the associated node.

default final void
TouchInjectionScopeKt.pinch(
    @NonNull TouchInjectionScope receiver,
    @NonNull Offset start0,
    @NonNull Offset end0,
    @NonNull Offset start1,
    @NonNull Offset end1,
    long durationMillis
)

Performs a pinch gesture on the associated node.

default final void
TouchInjectionScopeKt.swipe(
    @NonNull TouchInjectionScope receiver,
    @NonNull Function1<@NonNull Long, @NonNull Offset> curve,
    long durationMillis,
    @NonNull List<@NonNull Long> keyTimes
)

Performs a swipe gesture on the associated node.

default final void
TouchInjectionScopeKt.swipe(
    @NonNull TouchInjectionScope receiver,
    @NonNull Offset start,
    @NonNull Offset end,
    long durationMillis
)

Performs a swipe gesture on the associated node.

default final void
TouchInjectionScopeKt.swipeDown(
    @NonNull TouchInjectionScope receiver,
    float startY,
    float endY,
    long durationMillis
)

Performs a swipe down gesture along x = [centerX] of the associated node, from startY till endY, taking durationMillis milliseconds.

default final void
TouchInjectionScopeKt.swipeLeft(
    @NonNull TouchInjectionScope receiver,
    float startX,
    float endX,
    long durationMillis
)

Performs a swipe left gesture along y = [centerY] of the associated node, from startX till endX, taking durationMillis milliseconds.

default final void
TouchInjectionScopeKt.swipeRight(
    @NonNull TouchInjectionScope receiver,
    float startX,
    float endX,
    long durationMillis
)

Performs a swipe right gesture along y = [centerY] of the associated node, from startX till endX, taking durationMillis milliseconds.

default final void
TouchInjectionScopeKt.swipeUp(
    @NonNull TouchInjectionScope receiver,
    float startY,
    float endY,
    long durationMillis
)

Performs a swipe up gesture along x = [centerX] of the associated node, from startY till endY, taking durationMillis milliseconds.

default final void
TouchInjectionScopeKt.swipeWithVelocity(
    @NonNull TouchInjectionScope receiver,
    @NonNull Offset start,
    @NonNull Offset end,
    float endVelocity,
    long durationMillis
)

Performs a swipe gesture on the associated node such that it ends with the given endVelocity.

Inherited methods

From androidx.compose.ui.unit.Density
abstract float

The logical density of the display.

abstract float

Current user preference for the scaling factor for fonts.

default int

Convert Dp to Int by rounding

default int

Convert Sp to Int by rounding

default @NonNull Dp

Convert Sp to Dp.

default @NonNull Dp
orgKt.toDp(int receiver)

Convert an Int pixel value to Dp.

default @NonNull Dp
orgKt.toDp(float receiver)

Convert a Float pixel value to a Dp

default @NonNull DpSize

Convert a Size to a DpSize.

default float
orgKt.toPx(@NonNull Dp receiver)

Convert Dp to pixels.

default float

Convert Sp to pixels.

default @NonNull Rect

Convert a DpRect to a Rect.

default @NonNull Size

Convert a DpSize to a Size.

default @NonNull TextUnit
orgKt.toSp(@NonNull Dp receiver)

Convert Dp to Sp.

default @NonNull TextUnit
orgKt.toSp(int receiver)

Convert an Int pixel value to Sp.

default @NonNull TextUnit
orgKt.toSp(float receiver)

Convert a Float pixel value to a Sp

From androidx.compose.ui.test.InjectionScope
abstract void
advanceEventTime(long durationMillis)

Adds the given durationMillis to the current event time, delaying the next event by that time.

default float

The y-coordinate for the bottom of the node we're interacting with in px, in the node's local coordinate system, where (0, 0) is the top left corner of the node.

default @NonNull Offset

The center of the bottom edge of the node we're interacting with, in the node's local coordinate system, where (0, 0) is the top left corner of the node.

default @NonNull Offset

The bottom left corner of the node we're interacting with, in the node's local coordinate system, where (0, 0) is the top left corner of the node.

default @NonNull Offset

The bottom right corner of the node we're interacting with, in the node's local coordinate system, where (0, 0) is the top left corner of the node.

default @NonNull Offset

The center of the node we're interacting with, in the node's local coordinate system, where (0, 0) is the top left corner of the node.

default @NonNull Offset

The center of the left edge of the node we're interacting with, in the node's local coordinate system, where (0, 0) is the top left corner of the node.

default @NonNull Offset

The center of the right edge of the node we're interacting with, in the node's local coordinate system, where (0, 0) is the top left corner of the node.

default float

The x-coordinate for the center of the node we're interacting with in px, in the node's local coordinate system, where (0, 0) is the top left corner of the node.

default float

The y-coordinate for the center of the node we're interacting with in px, in the node's local coordinate system, where (0, 0) is the top left corner of the node.

default long

The default time between two successive events.

default int

The height of the node in px.

default float

The x-coordinate for the left edge of the node we're interacting with in px, in the node's local coordinate system, where (0, 0) is the top left corner of the node.

default float

The x-coordinate for the right edge of the node we're interacting with in px, in the node's local coordinate system, where (0, 0) is the top left corner of the node.

default float

The y-coordinate for the bottom of the node we're interacting with in px, in the node's local coordinate system, where (0, 0) is the top left corner of the node.

default @NonNull Offset

The center of the top edge of the node we're interacting with, in the node's local coordinate system, where (0, 0) is the top left corner of the node.

default @NonNull Offset

The top left corner of the node we're interacting with, in the node's local coordinate system, where (0, 0) is the top left corner of the node.

default @NonNull Offset

The top right corner of the node we're interacting with, in the node's local coordinate system, where (0, 0) is the top left corner of the node.

abstract @NonNull ViewConfiguration

The ViewConfiguration in use by the SemanticsNode from the SemanticsNodeInteraction on which the input injection method is called.

abstract @NonNull IntSize

The size of the visible part of the node we're interacting with in px, i.e. its clipped bounds.

default int

The width of the node in px.

default @NonNull Offset
percentOffset(float x, float y)

Creates an Offset relative to the size of the node we're interacting with.

Public methods

cancel

abstract void cancel(long delayMillis)

Sends a cancel event delayMillis after the last sent event to cancel the current gesture. The cancel event contains the current position of all active pointers.

Parameters
long delayMillis

The time between the last sent event and this event. eventPeriodMillis by default.

currentPosition

abstract Offset currentPosition(int pointerId)

Returns the current position of the given pointerId. The default pointerId is 0. The position is returned in the local coordinate system of the node with which we're interacting. (0, 0) is the top left corner of the node.

down

default void down(@NonNull Offset position)

Sends a down event for the default pointer at position on the associated node. The position is in the node's local coordinate system, where (0, 0) is the top left corner of the node. The default pointer has pointerId = 0.

If no pointers are down yet, this will start a new touch gesture. If a gesture is already in progress, this event is sent at the same timestamp as the last event. If the default pointer is already down, an IllegalArgumentException will be thrown.

Parameters
@NonNull Offset position

The position of the down event, in the node's local coordinate system

down

abstract void down(int pointerId, @NonNull Offset position)

Sends a down event for the pointer with the given pointerId at position on the associated node. The position is in the node's local coordinate system, where (0, 0) is the top left corner of the node.

If no pointers are down yet, this will start a new touch gesture. If a gesture is already in progress, this event is sent at the same timestamp as the last event. If the given pointer is already down, an IllegalArgumentException will be thrown.

Parameters
int pointerId

The id of the pointer, can be any number not yet in use by another pointer

@NonNull Offset position

The position of the down event, in the node's local coordinate system

move

abstract void move(long delayMillis)

Sends a move event delayMillis after the last sent event without updating any of the pointer positions. This can be useful when batching movement of multiple pointers together, which can be done with updatePointerTo and updatePointerBy.

Parameters
long delayMillis

The time between the last sent event and this event. eventPeriodMillis by default.

moveBy

default void moveBy(@NonNull Offset delta, long delayMillis)

Sends a move event delayMillis after the last sent event on the associated node, with the position of the default pointer moved by the given delta. The default pointer has pointerId = 0.

If the pointer is not yet down, an IllegalArgumentException will be thrown.

Parameters
@NonNull Offset delta

The position for this move event, relative to the current position of the pointer. For example, `delta = Offset(10.px, -10.px) will add 10.px to the pointer's x-position, and subtract 10.px from the pointer's y-position.

long delayMillis

The time between the last sent event and this event. eventPeriodMillis by default.

moveBy

default void moveBy(int pointerId, @NonNull Offset delta, long delayMillis)

Sends a move event delayMillis after the last sent event on the associated node, with the position of the pointer with the given pointerId moved by the given delta.

If the pointer is not yet down, an IllegalArgumentException will be thrown.

Parameters
int pointerId

The id of the pointer to move, as supplied in down

@NonNull Offset delta

The position for this move event, relative to the current position of the pointer. For example, `delta = Offset(10.px, -10.px) will add 10.px to the pointer's x-position, and subtract 10.px from the pointer's y-position.

long delayMillis

The time between the last sent event and this event. eventPeriodMillis by default.

moveTo

default void moveTo(@NonNull Offset position, long delayMillis)

Sends a move event delayMillis after the last sent event on the associated node, with the position of the default pointer updated to position. The position is in the node's local coordinate system, where (0, 0) is the top left corner of the node. The default pointer has pointerId = 0.

If the default pointer is not yet down, an IllegalArgumentException will be thrown.

Parameters
@NonNull Offset position

The new position of the pointer, in the node's local coordinate system

long delayMillis

The time between the last sent event and this event. eventPeriodMillis by default.

moveTo

default void moveTo(int pointerId, @NonNull Offset position, long delayMillis)

Sends a move event delayMillis after the last sent event on the associated node, with the position of the pointer with the given pointerId updated to position. The position is in the node's local coordinate system, where (0, 0) is the top left corner of the node.

If the pointer is not yet down, an IllegalArgumentException will be thrown.

Parameters
int pointerId

The id of the pointer to move, as supplied in down

@NonNull Offset position

The new position of the pointer, in the node's local coordinate system

long delayMillis

The time between the last sent event and this event. eventPeriodMillis by default.

moveWithHistory

@ExperimentalTestApi
default void moveWithHistory(
    @NonNull List<@NonNull Long> relativeHistoricalTimes,
    @NonNull List<@NonNull Offset> historicalCoordinates,
    long delayMillis
)

Sends a move event delayMillis after the last sent event without updating any of the pointer positions.

This overload is a convenience method for the common case where the gesture only has one pointer.

Parameters
@NonNull List<@NonNull Long> relativeHistoricalTimes

Time of each historical event, as a millisecond relative to the time the actual event is sent. For example, -10L means 10ms earlier.

@NonNull List<@NonNull Offset> historicalCoordinates

Coordinates of each historical event, in the same coordinate space as moveTo. The list must have the same size as relativeHistoricalTimes.

long delayMillis

The time between the last sent event and this event. eventPeriodMillis by default.

moveWithHistoryMultiPointer

@ExperimentalTestApi
abstract void moveWithHistoryMultiPointer(
    @NonNull List<@NonNull Long> relativeHistoricalTimes,
    @NonNull List<@NonNull List<@NonNull Offset>> historicalCoordinates,
    long delayMillis
)

Sends a move event delayMillis after the last sent event without updating any of the pointer positions.

This overload supports gestures with multiple pointers.

Parameters
@NonNull List<@NonNull Long> relativeHistoricalTimes

Time of each historical event, as a millisecond relative to the time the actual event is sent. For example, -10L means 10ms earlier.

@NonNull List<@NonNull List<@NonNull Offset>> historicalCoordinates

Coordinates of each historical event, in the same coordinate space as moveTo. The outer list must have the same size as the number of pointers in the event, and each inner list must have the same size as relativeHistoricalTimes.

long delayMillis

The time between the last sent event and this event. eventPeriodMillis by default.

up

abstract void up(int pointerId)

Sends an up event for the pointer with the given pointerId, or the default pointer if pointerId is omitted, on the associated node.

Parameters
int pointerId

The id of the pointer to lift up, as supplied in down

updatePointerBy

default void updatePointerBy(int pointerId, @NonNull Offset delta)

Updates the position of the pointer with the given pointerId by the given delta, but does not send a move event. The move event can be sent with move.

If the pointer is not yet down, an IllegalArgumentException will be thrown.

Parameters
int pointerId

The id of the pointer to move, as supplied in down

@NonNull Offset delta

The position for this move event, relative to the last sent position of the pointer. For example, `delta = Offset(10.px, -10.px) will add 10.px to the pointer's x-position, and subtract 10.px from the pointer's y-position.

updatePointerTo

abstract void updatePointerTo(int pointerId, @NonNull Offset position)

Updates the position of the pointer with the given pointerId to the given position, but does not send a move event. The move event can be sent with move. The position is in the node's local coordinate system, where (0.px, 0.px) is the top left corner of the node.

If the pointer is not yet down, an IllegalArgumentException will be thrown.

Parameters
int pointerId

The id of the pointer to move, as supplied in down

@NonNull Offset position

The new position of the pointer, in the node's local coordinate system

Extension functions

TouchInjectionScopeKt.click

default final void TouchInjectionScopeKt.click(
    @NonNull TouchInjectionScope receiver,
    @NonNull Offset position
)

Performs a click gesture (aka a tap) on the associated node.

The click is done at the given position, or in the center if the position is omitted. The position is in the node's local coordinate system, where (0, 0) is the top left corner of the node.

Parameters
@NonNull Offset position

The position where to click, in the node's local coordinate system. If omitted, the center of the node will be used.

TouchInjectionScopeKt.doubleClick

default final void TouchInjectionScopeKt.doubleClick(
    @NonNull TouchInjectionScope receiver,
    @NonNull Offset position,
    long delayMillis
)

Performs a double click gesture (aka a double tap) on the associated node.

The double click is done at the given position or in the center if the position is omitted. By default, the delayMillis between the first and the second click is half way in between the minimum and maximum required delay for a double click. The position is in the node's local coordinate system, where (0, 0) is the top left corner of the node.

Parameters
@NonNull Offset position

The position of the double click, in the node's local coordinate system. If omitted, the center position will be used.

long delayMillis

The time between the up event of the first click and the down event of the second click

TouchInjectionScopeKt.longClick

default final void TouchInjectionScopeKt.longClick(
    @NonNull TouchInjectionScope receiver,
    @NonNull Offset position,
    long durationMillis
)

Performs a long click gesture (aka a long press) on the associated node.

The long click is done at the given position, or in the center if the position is omitted. By default, the durationMillis of the press is 100ms longer than the minimum required duration for a long press. The position is in the node's local coordinate system, where (0, 0) is the top left corner of the node.

Parameters
@NonNull Offset position

The position of the long click, in the node's local coordinate system. If omitted, the center of the node will be used.

long durationMillis

The time between the down and the up event

TouchInjectionScopeKt.multiTouchSwipe

@ExperimentalTestApi
default final void TouchInjectionScopeKt.multiTouchSwipe(
    @NonNull TouchInjectionScope receiver,
    @NonNull List<@NonNull Function1<@NonNull Long, @NonNull Offset>> curves,
    long durationMillis,
    @NonNull List<@NonNull Long> keyTimes
)

Performs a multi touch swipe gesture on the associated node.

Each pointer follows curves[i] from 0 till durationMillis. Sampling of an event is forced at all times defined in keyTimes. The time between events is kept as close to eventPeriodMillis as possible, given the constraints. The coordinates are in the node's local coordinate system, where (0, 0) is the top left corner of the node. The default duration is 200 milliseconds.

Will stay experimental until support has been added to start and end each pointer at different times.

Parameters
@NonNull List<@NonNull Function1<@NonNull Long, @NonNull Offset>> curves

The functions that define the position of the gesture over time

long durationMillis

The duration of the gesture

@NonNull List<@NonNull Long> keyTimes

An optional list of timestamps in milliseconds at which a move event must be sampled

TouchInjectionScopeKt.pinch

default final void TouchInjectionScopeKt.pinch(
    @NonNull TouchInjectionScope receiver,
    @NonNull Offset start0,
    @NonNull Offset end0,
    @NonNull Offset start1,
    @NonNull Offset end1,
    long durationMillis
)

Performs a pinch gesture on the associated node.

For each pair of start and end Offsets, the motion events are linearly interpolated. The coordinates are in the node's local coordinate system where (0, 0) is the top left corner of the node. The default duration is 400 milliseconds.

Parameters
@NonNull Offset start0

The start position of the first gesture in the node's local coordinate system

@NonNull Offset end0

The end position of the first gesture in the node's local coordinate system

@NonNull Offset start1

The start position of the second gesture in the node's local coordinate system

@NonNull Offset end1

The end position of the second gesture in the node's local coordinate system

long durationMillis

the duration of the gesture

TouchInjectionScopeKt.swipe

default final void TouchInjectionScopeKt.swipe(
    @NonNull TouchInjectionScope receiver,
    @NonNull Function1<@NonNull Long, @NonNull Offset> curve,
    long durationMillis,
    @NonNull List<@NonNull Long> keyTimes
)

Performs a swipe gesture on the associated node.

The swipe follows the curve from 0 till durationMillis. Will force sampling of an event at all times defined in keyTimes. The time between events is kept as close to eventPeriodMillis as possible, given the constraints. The coordinates are in the node's local coordinate system, where (0, 0) is the top left corner of the node. The default duration is 200 milliseconds.

Parameters
@NonNull Function1<@NonNull Long, @NonNull Offset> curve

The function that defines the position of the gesture over time

long durationMillis

The duration of the gesture

@NonNull List<@NonNull Long> keyTimes

An optional list of timestamps in milliseconds at which a move event must be sampled

TouchInjectionScopeKt.swipe

default final void TouchInjectionScopeKt.swipe(
    @NonNull TouchInjectionScope receiver,
    @NonNull Offset start,
    @NonNull Offset end,
    long durationMillis
)

Performs a swipe gesture on the associated node.

The motion events are linearly interpolated between start and end. The coordinates are in the node's local coordinate system, where (0, 0) is the top left corner of the node. The default duration is 200 milliseconds.

Parameters
@NonNull Offset start

The start position of the gesture, in the node's local coordinate system

@NonNull Offset end

The end position of the gesture, in the node's local coordinate system

long durationMillis

The duration of the gesture

TouchInjectionScopeKt.swipeDown

default final void TouchInjectionScopeKt.swipeDown(
    @NonNull TouchInjectionScope receiver,
    float startY,
    float endY,
    long durationMillis
)

Performs a swipe down gesture along x = [centerX] of the associated node, from startY till endY, taking durationMillis milliseconds.

Parameters
float startY

The y-coordinate of the start of the swipe. Must be less than or equal to the endY. By default the top of the node.

float endY

The y-coordinate of the end of the swipe. Must be greater than or equal to the startY. By default the bottom of the node.

long durationMillis

The duration of the swipe. By default 200 milliseconds.

TouchInjectionScopeKt.swipeLeft

default final void TouchInjectionScopeKt.swipeLeft(
    @NonNull TouchInjectionScope receiver,
    float startX,
    float endX,
    long durationMillis
)

Performs a swipe left gesture along y = [centerY] of the associated node, from startX till endX, taking durationMillis milliseconds.

Parameters
float startX

The x-coordinate of the start of the swipe. Must be greater than or equal to the endX. By default the right of the node.

float endX

The x-coordinate of the end of the swipe. Must be less than or equal to the startX. By default the left of the node.

long durationMillis

The duration of the swipe. By default 200 milliseconds.

TouchInjectionScopeKt.swipeRight

default final void TouchInjectionScopeKt.swipeRight(
    @NonNull TouchInjectionScope receiver,
    float startX,
    float endX,
    long durationMillis
)

Performs a swipe right gesture along y = [centerY] of the associated node, from startX till endX, taking durationMillis milliseconds.

Parameters
float startX

The x-coordinate of the start of the swipe. Must be less than or equal to the endX. By default the left of the node.

float endX

The x-coordinate of the end of the swipe. Must be greater than or equal to the startX. By default the right of the node.

long durationMillis

The duration of the swipe. By default 200 milliseconds.

TouchInjectionScopeKt.swipeUp

default final void TouchInjectionScopeKt.swipeUp(
    @NonNull TouchInjectionScope receiver,
    float startY,
    float endY,
    long durationMillis
)

Performs a swipe up gesture along x = [centerX] of the associated node, from startY till endY, taking durationMillis milliseconds.

Parameters
float startY

The y-coordinate of the start of the swipe. Must be greater than or equal to the endY. By default the bottom of the node.

float endY

The y-coordinate of the end of the swipe. Must be less than or equal to the startY. By default the top of the node.

long durationMillis

The duration of the swipe. By default 200 milliseconds.

TouchInjectionScopeKt.swipeWithVelocity

default final void TouchInjectionScopeKt.swipeWithVelocity(
    @NonNull TouchInjectionScope receiver,
    @NonNull Offset start,
    @NonNull Offset end,
    float endVelocity,
    long durationMillis
)

Performs a swipe gesture on the associated node such that it ends with the given endVelocity.

The swipe will go through start at t=0 and through end at t=durationMillis. In between, the swipe will go monotonically from start and end, but not strictly. Due to imprecision, no guarantees can be made for the actual velocity at the end of the gesture, but generally it is within 0.1 of the desired velocity.

When a swipe cannot be created that results in the desired velocity (because the input is too restrictive), an exception will be thrown with suggestions to fix the input.

The coordinates are in the node's local coordinate system, where (0, 0) is the top left corner of the node. The default duration is calculated such that a feasible swipe can be created that ends in the given velocity.

Parameters
@NonNull Offset start

The start position of the gesture, in the node's local coordinate system

@NonNull Offset end

The end position of the gesture, in the node's local coordinate system

float endVelocity

The velocity of the gesture at the moment it ends in px/second. Must be positive.

long durationMillis

The duration of the gesture in milliseconds. Must be long enough that at least 3 input events are generated, which happens with a duration of 40ms or more. If omitted, a duration is calculated such that a valid swipe with velocity can be created.

Throws
kotlin.IllegalArgumentException

When no swipe can be generated that will result in the desired velocity. The error message will suggest changes to the input parameters such that a swipe will become feasible.