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

PointerInteropFilterKt

public final class PointerInteropFilterKt


Summary

Public methods

static final @NonNull Modifier
motionEventSpy(
    @NonNull Modifier receiver,
    @NonNull Function1<@NonNull MotionEventUnit> watcher
)

Calls watcher with each MotionEvent that the layout area or any child pointerInput receives.

static final @NonNull Modifier
@ExperimentalComposeUiApi
pointerInteropFilter(
    @NonNull Modifier receiver,
    RequestDisallowInterceptTouchEvent requestDisallowInterceptTouchEvent,
    @NonNull Function1<@NonNull MotionEvent, @NonNull Boolean> onTouchEvent
)

A special PointerInputModifier that provides access to the underlying MotionEvents originally dispatched to Compose.

Public methods

motionEventSpy

public static final @NonNull Modifier motionEventSpy(
    @NonNull Modifier receiver,
    @NonNull Function1<@NonNull MotionEventUnit> watcher
)

Calls watcher with each MotionEvent that the layout area or any child pointerInput receives. The MotionEvent may or may not have been transformed to the local coordinate system. The Compose View will be considered as handling the MotionEvent in the area that the motionEventSpy is active.

This method can only be used to observe MotionEvents and can not be used to capture an event stream.

watcher is called during the PointerEventPass.Initial pass.

Developers should use pointerInput to handle pointer input processing within Compose. motionEventSpy is only useful as part of Android View interoperability.

pointerInteropFilter

@ExperimentalComposeUiApi
public static final @NonNull Modifier pointerInteropFilter(
    @NonNull Modifier receiver,
    RequestDisallowInterceptTouchEvent requestDisallowInterceptTouchEvent,
    @NonNull Function1<@NonNull MotionEvent, @NonNull Boolean> onTouchEvent
)

A special PointerInputModifier that provides access to the underlying MotionEvents originally dispatched to Compose. Prefer pointerInput and use this only for interoperation with existing code that consumes MotionEvents.

While the main intent of this Modifier is to allow arbitrary code to access the original MotionEvent dispatched to Compose, for completeness, analogs are provided to allow arbitrary code to interact with the system as if it were an Android View.

This includes 2 APIs,

  1. onTouchEvent has a Boolean return type which is akin to the return type of View.onTouchEvent. If the provided onTouchEvent returns true, it will continue to receive the event stream (unless the event stream has been intercepted) and if it returns false, it will not.

  2. requestDisallowInterceptTouchEvent is a lambda that you can optionally provide so that you can later call it (yes, in this case, you call the lambda that you provided) which is akin to calling ViewParent.requestDisallowInterceptTouchEvent. When this is called, any associated ancestors in the tree that abide by the contract will act accordingly and will not intercept the even stream.