IndirectPointerGestureKt

Added in 1.0.0-alpha09

public final class IndirectPointerGestureKt


Summary

Public methods

static final @NonNull Modifier
onIndirectPointerGesture(
    @NonNull Modifier receiver,
    boolean enabled,
    Function0<Unit> onSwipeForward,
    Function0<Unit> onSwipeBackward,
    Function0<Unit> onClick
)

A Modifier that detects high-level click and horizontal swipe gestures from an IndirectPointerEvent source.

Public methods

onIndirectPointerGesture

public static final @NonNull Modifier onIndirectPointerGesture(
    @NonNull Modifier receiver,
    boolean enabled,
    Function0<Unit> onSwipeForward,
    Function0<Unit> onSwipeBackward,
    Function0<Unit> onClick
)

A Modifier that detects high-level click and horizontal swipe gestures from an IndirectPointerEvent source. The component (or one of its descendants) using this modifier must be focused to intercept events.

This modifier allows optionality for gesture callbacks. If a specific gesture callback is null, the corresponding events will not be consumed by this modifier. For example, if onClick is null but swipe callbacks are provided, corresponding IndirectPointerEvents for click can still be handled by a parent clickable modifier, while swipe gestures are consumed by this modifier.

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.focusTarget
import androidx.xr.glimmer.onIndirectPointerGesture

Box(
    modifier =
        Modifier.fillMaxSize()
            .onIndirectPointerGesture(
                enabled = true,
                onSwipeForward = { /* onSwipeForward */ },
                onSwipeBackward = { /* onSwipeBackward */ },
                onClick = { /* onClick */ },
            )
            .focusTarget()
) {
    // App()
}
Parameters
boolean enabled

Controls whether gesture detection is active. When false, this modifier has no effect and no callbacks will be invoked.

Function0<Unit> onSwipeForward

Invoked when a successful forward swipe is detected. If null, the corresponding IndirectPointerEvents will not be consumed.

Function0<Unit> onSwipeBackward

Invoked when a successful backward swipe is detected. If null, the corresponding IndirectPointerEvents will not be consumed.

Function0<Unit> onClick

Invoked when a successful click is detected. If null, the corresponding IndirectPointerEvents will not be consumed.