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 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
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. If null, the corresponding IndirectPointerEvents will not be consumed.

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

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

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

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