# onIndirectPointerGesture

## Functions summary

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier.https://developer.android.com/reference/kotlin/androidx/xr/glimmer/onIndirectPointerGesture.modifier#(androidx.compose.ui.Modifier).onIndirectPointerGesture(kotlin.Boolean,kotlin.Function0,kotlin.Function0,kotlin.Function0)( enabled: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html, onSwipeForward: (() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)?, onSwipeBackward: (() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)?, onClick: (() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)? )` A `https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier` that detects high-level click and horizontal swipe gestures from an `https://developer.android.com/reference/kotlin/androidx/compose/ui/input/indirect/IndirectPointerEvent` source. |

## Functions

### Modifier.onIndirectPointerGesture

Artifact: [androidx.xr.glimmer:glimmer](https://developer.android.com/jetpack/androidx/releases/xr-glimmer) [View Source](https://cs.android.com/search?q=file:androidx/xr/glimmer/IndirectPointerGesture.kt+function:onIndirectPointerGesture) Added in [1.0.0-alpha22](https://developer.android.com/jetpack/androidx/releases/xr-glimmer#1.0.0-alpha22)

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

A `https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier` that detects high-level click and horizontal swipe gestures from an `https://developer.android.com/reference/kotlin/androidx/compose/ui/input/indirect/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 `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/package-summary#(androidx.compose.ui.Modifier).onIndirectPointerGesture(kotlin.Boolean,kotlin.Function0,kotlin.Function0,kotlin.Function0)` callback but leaves `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/package-summary#(androidx.compose.ui.Modifier).onIndirectPointerGesture(kotlin.Boolean,kotlin.Function0,kotlin.Function0,kotlin.Function0)` 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 (`https://developer.android.com/reference/kotlin/androidx/xr/glimmer/package-summary#(androidx.compose.ui.Modifier).onIndirectPointerGesture(kotlin.Boolean,kotlin.Function0,kotlin.Function0,kotlin.Function0)`, `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/package-summary#(androidx.compose.ui.Modifier).onIndirectPointerGesture(kotlin.Boolean,kotlin.Function0,kotlin.Function0,kotlin.Function0)`, or `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/package-summary#(androidx.compose.ui.Modifier).onIndirectPointerGesture(kotlin.Boolean,kotlin.Function0,kotlin.Function0,kotlin.Function0)`) is provided.

```kotlin
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: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html = true` | Controls whether gesture detection is active. When `false`, this modifier has no effect and no callbacks will be invoked. |
| `onSwipeForward: (() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)? = null` | Invoked when a successful forward swipe is detected. |
| `onSwipeBackward: (() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)? = null` | Invoked when a successful backward swipe is detected. |
| `onClick: (() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)? = null` | Invoked when a successful click is detected. |