TiltGesture


object TiltGesture


Container for device tilt gesture detection logic and the Tilt state representation.

The primary way to use this is via the TiltGesture.detect method, which provides a Flow of Tilt states.

Summary

Nested types

Represents the tilt state of the device, transition progress.

Public functions

Flow<TiltGesture.State>
detect(session: Session)

Begins detecting the device's tilt state and returns a cold Flow of Tilt updates.

Public functions

detect

Added in 1.0.0-alpha10
fun detect(session: Session): Flow<TiltGesture.State>

Begins detecting the device's tilt state and returns a cold Flow of Tilt updates.

This function observes changes to the ArDevice.state obtained from the provided session. The device's tilt is calculated based on the devicePose.rotation from this state.

Precondition: The session must be configured with device tracking set to androidx.xr.runtime.Config.DeviceTrackingMode.LAST_KNOWN. If androidx.xr.runtime.Config.DeviceTrackingMode.DISABLED is used, this function will throw an IllegalStateException when attempting to acquire the ArDevice instance.

The returned flow is cold: a new stream of tilt updates is created for each collector. The flow emits new State objects containing Tilt (i.e., Tilt.UP or 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 Session, as changes to ArDevice.state drive the emissions.

Parameters
session: Session

The active XR session. It must be configured with device tracking enabled androidx.xr.runtime.Config.DeviceTrackingMode.LAST_KNOWN

Returns
Flow<TiltGesture.State>

A Flow that emits the current State, starting with an initial state of State.tilt as Tilt.UP and State.progress as 0f.