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

PointerInputChange

public final class PointerInputChange


Describes a change that has occurred for a particular pointer, as well as how much of the change has been consumed (meaning, used by a node in the UI).

The position represents the position of the pointer relative to the element that this PointerInputChange is being dispatched to.

Note: The position values can be outside the actual bounds of the element itself meaning the numbers can be negative or larger than the element bounds.

The previousPosition represents the position of the pointer offset to the current position of the pointer relative to the screen.

This means that position and previousPosition can always be used to understand how much a pointer has moved relative to an element, even if that element is moving along with the changes to the pointer. For example, if a pointer touches a 1x1 pixel box in the middle, position will report a position of (0, 0) when dispatched to it. If the next event moves x position 5 pixels, position will report (5, 0) and previousPosition will report (0, 0). If the box moves all 5 pixels, and the next event represents the pointer moving along the x axis for 5 more pixels, position will again report (5, 0) and previousPosition will report (0, 0).

Summary

Public constructors

PointerInputChange(
    @NonNull PointerId id,
    long uptimeMillis,
    @NonNull Offset position,
    boolean pressed,
    long previousUptimeMillis,
    @NonNull Offset previousPosition,
    boolean previousPressed,
    boolean isInitiallyConsumed,
    @NonNull PointerType type,
    @NonNull Offset scrollDelta
)
PointerInputChange(
    @NonNull PointerId id,
    long uptimeMillis,
    @NonNull Offset position,
    boolean pressed,
    float pressure,
    long previousUptimeMillis,
    @NonNull Offset previousPosition,
    boolean previousPressed,
    boolean isInitiallyConsumed,
    @NonNull PointerType type,
    @NonNull Offset scrollDelta
)

Public methods

final void

Consume change event, claiming all the corresponding change info to the caller.

final @NonNull PointerInputChange
copy(
    @NonNull PointerId id,
    long currentTime,
    @NonNull Offset currentPosition,
    boolean currentPressed,
    long previousTime,
    @NonNull Offset previousPosition,
    boolean previousPressed,
    @NonNull PointerType type,
    @NonNull Offset scrollDelta
)

Make a shallow copy of the PointerInputChange

final @NonNull PointerInputChange
copy(
    @NonNull PointerId id,
    long currentTime,
    @NonNull Offset currentPosition,
    boolean currentPressed,
    float pressure,
    long previousTime,
    @NonNull Offset previousPosition,
    boolean previousPressed,
    @NonNull PointerType type,
    @NonNull Offset scrollDelta
)

Make a shallow copy of the PointerInputChange

final @NonNull PointerInputChange
copy(
    @NonNull PointerId id,
    long currentTime,
    @NonNull Offset currentPosition,
    boolean currentPressed,
    long previousTime,
    @NonNull Offset previousPosition,
    boolean previousPressed,
    @NonNull ConsumedData consumed,
    @NonNull PointerType type,
    @NonNull Offset scrollDelta
)

This method is deprecated. Partial consumption has been deprecated.

final @NonNull PointerInputChange
@ExperimentalComposeUiApi
copy(
    @NonNull PointerId id,
    long currentTime,
    @NonNull Offset currentPosition,
    boolean currentPressed,
    long previousTime,
    @NonNull Offset previousPosition,
    boolean previousPressed,
    @NonNull PointerType type,
    @NonNull List<@NonNull HistoricalChange> historical,
    @NonNull Offset scrollDelta
)

Make a shallow copy of the PointerInputChange

final @NonNull PointerInputChange
@ExperimentalComposeUiApi
copy(
    @NonNull PointerId id,
    long currentTime,
    @NonNull Offset currentPosition,
    boolean currentPressed,
    float pressure,
    long previousTime,
    @NonNull Offset previousPosition,
    boolean previousPressed,
    @NonNull PointerType type,
    @NonNull List<@NonNull HistoricalChange> historical,
    @NonNull Offset scrollDelta
)

Make a shallow copy of the PointerInputChange

final @NonNull ConsumedData
final @NonNull List<@NonNull HistoricalChange>

Optional high-frequency pointer moves in between the last two dispatched events.

final @NonNull PointerId

The unique id of the pointer associated with this PointerInputChange.

final @NonNull Offset

The Offset of the current pointer event, relative to the containing element (values can be negative or larger than the element bounds).

final boolean

true if the pointer event is considered "pressed." For example, finger touching the screen or a mouse button is pressed pressed would be true.

final float

The pressure of the of the pointer event

final @NonNull Offset

The Offset of the previous pointer event, offset to the position and relative to the containing element.

final boolean

true if the pointer event was considered "pressed." For example , if a finger was touching the screen or a mouse button was pressed, previousPressed would be true.

final long

The uptimeMillis of the previous pointer event

final @NonNull Offset

The amount of scroll wheel movement in the horizontal and vertical directions.

final @NonNull PointerType

The device type that produced the event, such as mouse, or touch.git

final long

The time of the current pointer event, in milliseconds.

final boolean

Indicates whether the change was consumed or not.

@NonNull String

Extension functions

final boolean

This method is deprecated. Partial consumption has been deprecated.

final boolean

True if this PointerInputChange represents a pointer coming in contact with the screen and that change has not been consumed.

final boolean

True if this PointerInputChange represents a pointer coming in contact with the screen, whether or not that change has been consumed.

final boolean

True if this PointerInputChange represents a pointer breaking contact with the screen and that change has not been consumed.

final boolean

True if this PointerInputChange represents a pointer breaking contact with the screen, whether or not that change has been consumed.

final void

This method is deprecated. Use consume() instead

final void

This method is deprecated. Partial consumption has been deprecated.

final void

This method is deprecated. Partial consumption has been deprecated.

final boolean

This method is deprecated. Use isOutOfBounds() that supports minimum touch target

final boolean
PointerEventKt.isOutOfBounds(
    @NonNull PointerInputChange receiver,
    @NonNull IntSize size,
    @NonNull Size extendedTouchPadding
)

Returns true if the pointer has moved outside of the pointer region.

final @NonNull Offset

The distance that the pointer has moved on the screen minus any distance that has been consumed.

final boolean

This method is deprecated. Partial consumption has been deprecated.

final @NonNull Offset

The distance that the pointer has moved on the screen, ignoring the fact that it might have been consumed.

final boolean

True if this PointerInputChange represents a pointer moving on the screen and some of that movement has not been consumed.

final boolean

True if this PointerInputChange represents a pointer moving on the screen ignoring how much of that movement may have been consumed.

Public constructors

PointerInputChange

public PointerInputChange(
    @NonNull PointerId id,
    long uptimeMillis,
    @NonNull Offset position,
    boolean pressed,
    long previousUptimeMillis,
    @NonNull Offset previousPosition,
    boolean previousPressed,
    boolean isInitiallyConsumed,
    @NonNull PointerType type,
    @NonNull Offset scrollDelta
)

PointerInputChange

public PointerInputChange(
    @NonNull PointerId id,
    long uptimeMillis,
    @NonNull Offset position,
    boolean pressed,
    float pressure,
    long previousUptimeMillis,
    @NonNull Offset previousPosition,
    boolean previousPressed,
    boolean isInitiallyConsumed,
    @NonNull PointerType type,
    @NonNull Offset scrollDelta
)
Parameters
@NonNull PointerId id

The unique id of the pointer associated with this PointerInputChange.

long uptimeMillis

The time of the current pointer event, in milliseconds. The start (0) time is platform-dependent

@NonNull Offset position

The Offset of the current pointer event, relative to the containing element (values can be negative or larger than the element bounds).

boolean pressed

true if the pointer event is considered "pressed." For example, finger touching the screen or a mouse button is pressed pressed would be true.

float pressure

The pressure of the of the pointer event

long previousUptimeMillis

The uptimeMillis of the previous pointer event

@NonNull Offset previousPosition

The Offset of the previous pointer event, offset to the position and relative to the containing element.

boolean previousPressed

true if the pointer event was considered "pressed." For example , if a finger was touching the screen or a mouse button was pressed, previousPressed would be true.

boolean isInitiallyConsumed

whether the change was consumed from the start or not. This value can change over time as change is propagated through the pointer handlers. To query the actual status of the change use isConsumed

@NonNull PointerType type

The device type that produced the event, such as mouse, or touch.git

@NonNull Offset scrollDelta

The amount of scroll wheel movement in the horizontal and vertical directions.

Public methods

consume

public final void consume()

Consume change event, claiming all the corresponding change info to the caller. This is usually needed when, button, when being clicked, consumed the "up" event so no other parents of this button could consume this "up" again.

"Consumption" is just an indication of the claim and each pointer input handler implementation must manually check this flag to respect it.

copy

public final @NonNull PointerInputChange copy(
    @NonNull PointerId id,
    long currentTime,
    @NonNull Offset currentPosition,
    boolean currentPressed,
    long previousTime,
    @NonNull Offset previousPosition,
    boolean previousPressed,
    @NonNull PointerType type,
    @NonNull Offset scrollDelta
)

Make a shallow copy of the PointerInputChange

NOTE: Due to the need of the inner contract of the PointerInputChange, this method performs a shallow copy of the PointerInputChange. Any consume call between any of the copies will consume any other copy automatically. Therefore, copy with the new isConsumed is not possible. Consider creating a new PointerInputChange

copy

public final @NonNull PointerInputChange copy(
    @NonNull PointerId id,
    long currentTime,
    @NonNull Offset currentPosition,
    boolean currentPressed,
    float pressure,
    long previousTime,
    @NonNull Offset previousPosition,
    boolean previousPressed,
    @NonNull PointerType type,
    @NonNull Offset scrollDelta
)

Make a shallow copy of the PointerInputChange

NOTE: Due to the need of the inner contract of the PointerInputChange, this method performs a shallow copy of the PointerInputChange. Any consume call between any of the copies will consume any other copy automatically. Therefore, copy with the new isConsumed is not possible. Consider creating a new PointerInputChange.

copy

public final @NonNull PointerInputChange copy(
    @NonNull PointerId id,
    long currentTime,
    @NonNull Offset currentPosition,
    boolean currentPressed,
    long previousTime,
    @NonNull Offset previousPosition,
    boolean previousPressed,
    @NonNull ConsumedData consumed,
    @NonNull PointerType type,
    @NonNull Offset scrollDelta
)

copy

@ExperimentalComposeUiApi
public final @NonNull PointerInputChange copy(
    @NonNull PointerId id,
    long currentTime,
    @NonNull Offset currentPosition,
    boolean currentPressed,
    long previousTime,
    @NonNull Offset previousPosition,
    boolean previousPressed,
    @NonNull PointerType type,
    @NonNull List<@NonNull HistoricalChange> historical,
    @NonNull Offset scrollDelta
)

Make a shallow copy of the PointerInputChange

NOTE: Due to the need of the inner contract of the PointerInputChange, this method performs a shallow copy of the PointerInputChange. Any consume call between any of the copies will consume any other copy automatically. Therefore, copy with the new isConsumed is not possible. Consider creating a new PointerInputChange.

copy

@ExperimentalComposeUiApi
public final @NonNull PointerInputChange copy(
    @NonNull PointerId id,
    long currentTime,
    @NonNull Offset currentPosition,
    boolean currentPressed,
    float pressure,
    long previousTime,
    @NonNull Offset previousPosition,
    boolean previousPressed,
    @NonNull PointerType type,
    @NonNull List<@NonNull HistoricalChange> historical,
    @NonNull Offset scrollDelta
)

Make a shallow copy of the PointerInputChange

NOTE: Due to the need of the inner contract of the PointerInputChange, this method performs a shallow copy of the PointerInputChange. Any consume call between any of the copies will consume any other copy automatically. Therefore, copy with the new isConsumed is not possible. Consider creating a new PointerInputChange.

getConsumed

public final @NonNull ConsumedData getConsumed()

getHistorical

@ExperimentalComposeUiApi
public final @NonNull List<@NonNull HistoricalChangegetHistorical()

Optional high-frequency pointer moves in between the last two dispatched events. Can be used for extra accuracy when touchscreen rate exceeds framerate.

getId

public final @NonNull PointerId getId()

The unique id of the pointer associated with this PointerInputChange.

getPosition

public final @NonNull Offset getPosition()

The Offset of the current pointer event, relative to the containing element (values can be negative or larger than the element bounds).

getPressed

public final boolean getPressed()

true if the pointer event is considered "pressed." For example, finger touching the screen or a mouse button is pressed pressed would be true.

getPressure

public final float getPressure()

The pressure of the of the pointer event

getPreviousPosition

public final @NonNull Offset getPreviousPosition()

The Offset of the previous pointer event, offset to the position and relative to the containing element.

getPreviousPressed

public final boolean getPreviousPressed()

true if the pointer event was considered "pressed." For example , if a finger was touching the screen or a mouse button was pressed, previousPressed would be true.

getPreviousUptimeMillis

public final long getPreviousUptimeMillis()

The uptimeMillis of the previous pointer event

getScrollDelta

public final @NonNull Offset getScrollDelta()

The amount of scroll wheel movement in the horizontal and vertical directions.

getType

public final @NonNull PointerType getType()

The device type that produced the event, such as mouse, or touch.git

getUptimeMillis

public final long getUptimeMillis()

The time of the current pointer event, in milliseconds. The start (0) time is platform-dependent

isConsumed

public final boolean isConsumed()

Indicates whether the change was consumed or not. Note that the change must be consumed in full as there's no partial consumption system provided.

toString

public @NonNull String toString()

Extension functions

PointerEventKt.anyChangeConsumed

public final boolean PointerEventKt.anyChangeConsumed(@NonNull PointerInputChange receiver)

True if any aspect of this PointerInputChange has been consumed.

PointerEventKt.changedToDown

public final boolean PointerEventKt.changedToDown(@NonNull PointerInputChange receiver)

True if this PointerInputChange represents a pointer coming in contact with the screen and that change has not been consumed.

PointerEventKt.changedToDownIgnoreConsumed

public final boolean PointerEventKt.changedToDownIgnoreConsumed(
    @NonNull PointerInputChange receiver
)

True if this PointerInputChange represents a pointer coming in contact with the screen, whether or not that change has been consumed.

PointerEventKt.changedToUp

public final boolean PointerEventKt.changedToUp(@NonNull PointerInputChange receiver)

True if this PointerInputChange represents a pointer breaking contact with the screen and that change has not been consumed.

PointerEventKt.changedToUpIgnoreConsumed

public final boolean PointerEventKt.changedToUpIgnoreConsumed(
    @NonNull PointerInputChange receiver
)

True if this PointerInputChange represents a pointer breaking contact with the screen, whether or not that change has been consumed.

PointerEventKt.consumeAllChanges

public final void PointerEventKt.consumeAllChanges(@NonNull PointerInputChange receiver)

Consumes all changes associated with the PointerInputChange

PointerEventKt.consumeDownChange

public final void PointerEventKt.consumeDownChange(@NonNull PointerInputChange receiver)

Consume the up or down change of this PointerInputChange if there is an up or down change to consume.

PointerEventKt.consumePositionChange

public final void PointerEventKt.consumePositionChange(
    @NonNull PointerInputChange receiver
)

Consume position change if there is any

PointerEventKt.isOutOfBounds

public final boolean PointerEventKt.isOutOfBounds(
    @NonNull PointerInputChange receiver,
    @NonNull IntSize size
)

Returns true if the pointer has moved outside of the region of (0, 0, size.width, size.height) or false if the current pointer is up or it is inside the given bounds.

PointerEventKt.isOutOfBounds

public final boolean PointerEventKt.isOutOfBounds(
    @NonNull PointerInputChange receiver,
    @NonNull IntSize size,
    @NonNull Size extendedTouchPadding
)

Returns true if the pointer has moved outside of the pointer region. For Touch events, this is (-extendedTouchPadding.width, -extendedTouchPadding.height, size.width + extendedTouchPadding.width, size.height + extendedTouchPadding.height) and for other events, this is (0, 0, size.width, size.height). Returnsfalse if the current pointer is up or it is inside the pointer region.

PointerEventKt.positionChange

public final @NonNull Offset PointerEventKt.positionChange(@NonNull PointerInputChange receiver)

The distance that the pointer has moved on the screen minus any distance that has been consumed.

PointerEventKt.positionChangeConsumed

public final boolean PointerEventKt.positionChangeConsumed(
    @NonNull PointerInputChange receiver
)

True if this PointerInputChange's movement has been consumed.

PointerEventKt.positionChangeIgnoreConsumed

public final @NonNull Offset PointerEventKt.positionChangeIgnoreConsumed(
    @NonNull PointerInputChange receiver
)

The distance that the pointer has moved on the screen, ignoring the fact that it might have been consumed.

PointerEventKt.positionChanged

public final boolean PointerEventKt.positionChanged(@NonNull PointerInputChange receiver)

True if this PointerInputChange represents a pointer moving on the screen and some of that movement has not been consumed.

PointerEventKt.positionChangedIgnoreConsumed

public final boolean PointerEventKt.positionChangedIgnoreConsumed(
    @NonNull PointerInputChange receiver
)

True if this PointerInputChange represents a pointer moving on the screen ignoring how much of that movement may have been consumed.