# TiltGesture

Artifact: [androidx.xr.arcore:arcore](https://developer.android.com/jetpack/androidx/releases/xr-arcore) [View Source](https://cs.android.com/search?q=file:androidx/xr/arcore/TiltGesture.kt+class:androidx.xr.arcore.TiltGesture) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-arcore#1.0.0)

*** ** * ** ***


```
@ExperimentalGesturesApi
public static class TiltGesture
```

<br />

*** ** * ** ***

Container for device tilt gesture detection logic and the `https://developer.android.com/reference/androidx/xr/arcore/Tilt` state representation.

The primary way to use this is via the `https://developer.android.com/reference/androidx/xr/arcore/TiltGesture#detect(androidx.xr.runtime.Session)` method, which provides a `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html` of `https://developer.android.com/reference/androidx/xr/arcore/Tilt` states.

## Summary

| ### Nested types |
|---|
| `@https://developer.android.com/reference/androidx/xr/arcore/ExperimentalGesturesApi public final class https://developer.android.com/reference/androidx/xr/arcore/TiltGesture.State` Tilt state and transition progress of the device. |

| ### Public fields |
|---|---|
| `static @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/arcore/TiltGesture` | `https://developer.android.com/reference/androidx/xr/arcore/TiltGesture#INSTANCE()` |

| ### Public methods |
|---|---|
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/arcore/TiltGesture.State>` | `https://developer.android.com/reference/androidx/xr/arcore/TiltGesture#detect(androidx.xr.runtime.Session)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/Session session)` Begins detecting the device's tilt state and returns a cold `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html` of `https://developer.android.com/reference/androidx/xr/arcore/Tilt` updates. |

## Public fields

### INSTANCE

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-arcore#1.0.0)

```
public static @NonNull TiltGesture INSTANCE
```

## Public methods

### detect

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-arcore#1.0.0)

```
public final @NonNull Flow<@NonNull TiltGesture.State> detect(@NonNull Session session)
```

Begins detecting the device's tilt state and returns a cold `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html` of `https://developer.android.com/reference/androidx/xr/arcore/Tilt` updates.

This function observes changes to the `https://developer.android.com/reference/androidx/xr/arcore/ArDevice#state()` obtained from the provided `https://developer.android.com/reference/androidx/xr/arcore/TiltGesture#detect(androidx.xr.runtime.Session)`. The device's tilt is calculated based on the `devicePose.rotation` from this state.

**Precondition** : The `https://developer.android.com/reference/androidx/xr/arcore/TiltGesture#detect(androidx.xr.runtime.Session)` must be configured with device tracking set to `https://developer.android.com/reference/androidx/xr/runtime/DeviceTrackingMode#SPATIAL()`. If `https://developer.android.com/reference/androidx/xr/runtime/DeviceTrackingMode#DISABLED()` is used, this function will throw an `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` when attempting to acquire the `https://developer.android.com/reference/androidx/xr/arcore/ArDevice` instance.

The returned flow is **cold** : a new stream of tilt updates is created for each collector. The flow emits new `https://developer.android.com/reference/androidx/xr/arcore/TiltGesture.State` objects containing `https://developer.android.com/reference/androidx/xr/arcore/Tilt` (i.e., `https://developer.android.com/reference/androidx/xr/arcore/Tilt#UP()` or `https://developer.android.com/reference/androidx/xr/arcore/Tilt#DOWN()`) based on the orientation derived from the device pose.

It is recommended to collect this flow from a coroutine scope with the same coroutine context used to create the XR `https://developer.android.com/reference/androidx/xr/runtime/Session`, as changes to `https://developer.android.com/reference/androidx/xr/arcore/ArDevice#state()` drive the emissions.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/Session session` | the active XR session configured with `https://developer.android.com/reference/androidx/xr/runtime/DeviceTrackingMode#SPATIAL()` |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/arcore/TiltGesture.State>` | a `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html` that emits the current `https://developer.android.com/reference/androidx/xr/arcore/TiltGesture.State`, starting with an initial state of `https://developer.android.com/reference/androidx/xr/arcore/TiltGesture.State#tilt()` as `https://developer.android.com/reference/androidx/xr/arcore/Tilt#UP()` and `https://developer.android.com/reference/androidx/xr/arcore/TiltGesture.State#progress()` as 0f |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` | if `https://developer.android.com/reference/androidx/xr/arcore/TiltGesture#detect(androidx.xr.runtime.Session)` is configured with `https://developer.android.com/reference/androidx/xr/runtime/DeviceTrackingMode#DISABLED()` |