onIndirectPointerGesture

Functions summary

Modifier
Modifier.onIndirectPointerGesture(
    enabled: Boolean,
    onSwipeForward: (() -> Unit)?,
    onSwipeBackward: (() -> Unit)?,
    onClick: (() -> Unit)?
)

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

Functions

Modifier.onIndirectPointerGesture

fun Modifier.onIndirectPointerGesture(
    enabled: Boolean = true,
    onSwipeForward: (() -> Unit)? = null,
    onSwipeBackward: (() -> Unit)? = null,
    onClick: (() -> Unit)? = null
): Modifier

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 swipe gesture callbacks. If a specific swipe gesture callback is null, the corresponding swipe events will not be consumed by this modifier. For example:

  • When nesting onIndirectPointerGesture modifiers, if the inner modifier provides an onSwipeBackward callback but leaves onSwipeForward as null, the outer modifier can still detect and handle the forward swipe, and vice versa.

Note that the initial down event is always consumed by this modifier (if not already consumed) as long as at least one callback (onClick, onSwipeForward, or onSwipeBackward) is provided.

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
enabled: Boolean = true

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

onSwipeForward: (() -> Unit)? = null

Invoked when a successful forward swipe is detected.

onSwipeBackward: (() -> Unit)? = null

Invoked when a successful backward swipe is detected.

onClick: (() -> Unit)? = null

Invoked when a successful click is detected.