androidx.xr.compose.spatial

Interfaces

OrbiterEdge

An enum that represents the edges of a view where an orbiter can be placed.

Classes

ConstraintsBehavior

Defines the behavior for applying VolumeConstraints to an ApplicationSubspace.

EdgeOffset

Represents the offset of an orbiter from the main panel.

OrbiterEdge.Horizontal
OrbiterEdge.Vertical

Represents vertical edges (start or end).

OrbiterOffsetType

Represents the type of offset used for positioning an orbiter.

OrbiterSettings

Settings for an Orbiter.

SpatialDialogProperties

Properties for configuring a SpatialDialog.

SpatialElevationLevel

Represents the resting elevation level for spatial elements.

SpatialPopupProperties

SpatialPopup properties.

Objects

OrbiterDefaults

Contains default values used by Orbiters.

SubspaceDefaults

Defines default values used by the Subspace composables, primarily ApplicationSubspace.

Top-level functions summary

Unit
@Composable
@ComposableOpenTarget(index = -1)
ApplicationSubspace(
    constraints: VolumeConstraints,
    constraintsBehavior: ConstraintsBehavior,
    content: @Composable @SubspaceComposable SpatialBoxScope.() -> Unit
)

Create a 3D area that the app can render spatial content into with optional VolumeConstraints.

Unit
@Composable
@ComposableOpenTarget(index = -1)
Orbiter(
    position: OrbiterEdge.Horizontal,
    offset: Dp,
    alignment: Alignment.Horizontal,
    settings: OrbiterSettings,
    shape: SpatialShape,
    elevation: SpatialElevationLevel,
    content: @Composable @UiComposable () -> Unit
)

A composable that creates an orbiter along the top or bottom edges of a view.

Unit
@Composable
@ComposableOpenTarget(index = -1)
Orbiter(
    position: OrbiterEdge.Horizontal,
    offset: EdgeOffset,
    alignment: Alignment.Horizontal,
    settings: OrbiterSettings,
    shape: SpatialShape,
    elevation: SpatialElevationLevel,
    content: @Composable @UiComposable () -> Unit
)

A composable that creates an orbiter along the top or bottom edges of a view.

Unit
@Composable
@ComposableOpenTarget(index = -1)
Orbiter(
    position: OrbiterEdge.Vertical,
    offset: Dp,
    alignment: Alignment.Vertical,
    settings: OrbiterSettings,
    shape: SpatialShape,
    elevation: SpatialElevationLevel,
    content: @Composable @UiComposable () -> Unit
)

A composable that creates an orbiter along the start or end edges of a view.

Unit
@Composable
@ComposableOpenTarget(index = -1)
Orbiter(
    position: OrbiterEdge.Vertical,
    offset: EdgeOffset,
    alignment: Alignment.Vertical,
    settings: OrbiterSettings,
    shape: SpatialShape,
    elevation: SpatialElevationLevel,
    content: @Composable @UiComposable () -> Unit
)

A composable that creates an orbiter along the start or end edges of a view.

Unit
@Composable
SpatialDialog(
    onDismissRequest: () -> Unit,
    properties: SpatialDialogProperties,
    content: @Composable () -> Unit
)

SpatialDialog is a dialog that is elevated above the activity.

Unit
@Composable
SpatialElevation(
    spatialElevationLevel: SpatialElevationLevel,
    content: @Composable () -> Unit
)

Composable that creates a panel in 3D space when spatialization is enabled.

Unit
@Composable
SpatialPopup(
    alignment: Alignment,
    offset: IntOffset,
    onDismissRequest: (() -> Unit)?,
    properties: SpatialPopupProperties,
    content: @Composable () -> Unit
)

A composable that creates a panel in 3D space to hoist Popup based composables.

Unit

Create a 3D area that the app can render spatial content into.

Top-level functions

ApplicationSubspace

@Composable
@ComposableOpenTarget(index = -1)
fun ApplicationSubspace(
    constraints: VolumeConstraints = SubspaceDefaults.fallbackFieldOfViewConstraints,
    constraintsBehavior: ConstraintsBehavior = ConstraintsBehavior.FieldOfView,
    content: @Composable @SubspaceComposable SpatialBoxScope.() -> Unit
): Unit

Create a 3D area that the app can render spatial content into with optional VolumeConstraints.

ApplicationSubspace should be used to create the topmost Subspace in your application's spatial UI hierarchy. This composable will throw an IllegalStateException if it is used to create a Subspace that is nested within another Subspace or ApplicationSubspace. For nested 3D content areas, use the Subspace composable.

This composable is a no-op and does not render anything in non-XR environments (i.e., Phone and Tablet).

Parameters
constraints: VolumeConstraints = SubspaceDefaults.fallbackFieldOfViewConstraints

The volume constraints to apply to this ApplicationSubspace. The behavior of these constraints depends on the constraintsBehavior. By default, this is set to the default field of view constraints.

constraintsBehavior: ConstraintsBehavior = ConstraintsBehavior.FieldOfView

Specifies how the provided constraints should be applied. Use ConstraintsBehavior.Specified to directly use the provided constraints, or ConstraintsBehavior.FieldOfView to attempt to use calculated field of view constraints, falling back to the provided constraints if calculation fails or if the HEAD_TRACKING Android permission is not granted.

content: @Composable @SubspaceComposable SpatialBoxScope.() -> Unit

The 3D content to render within this Subspace

@Composable
@ComposableOpenTarget(index = -1)
fun Orbiter(
    position: OrbiterEdge.Horizontal,
    offset: Dp = 0.dp,
    alignment: Alignment.Horizontal = Alignment.CenterHorizontally,
    settings: OrbiterSettings = OrbiterDefaults.Settings,
    shape: SpatialShape = OrbiterDefaults.Shape,
    elevation: SpatialElevationLevel = OrbiterDefaults.Elevation,
    content: @Composable @UiComposable () -> Unit
): Unit

A composable that creates an orbiter along the top or bottom edges of a view.

Orbiters are floating elements that contain controls for spatial content. They allow the content to have more space and give users quick access to features like navigation without obstructing the main content.

In non-spatial environments, orbiters may be configured using OrbiterSettings.shouldRenderInNonSpatial to render their content as if the orbiter wrapper was not present or be removed from the flow entirely.

Parameters
position: OrbiterEdge.Horizontal

The edge of the orbiter. Use OrbiterEdge.Top or OrbiterEdge.Bottom.

offset: Dp = 0.dp

The offset of the orbiter based on the outer edge of the orbiter.

alignment: Alignment.Horizontal = Alignment.CenterHorizontally

The alignment of the orbiter. Use Alignment.CenterHorizontally or Alignment.Start or Alignment.End.

settings: OrbiterSettings = OrbiterDefaults.Settings

The settings for the orbiter.

shape: SpatialShape = OrbiterDefaults.Shape

The shape of this Orbiter when it is rendered in 3D space.

elevation: SpatialElevationLevel = OrbiterDefaults.Elevation

The z-direction elevation level of this Orbiter.

content: @Composable @UiComposable () -> Unit

The content of the orbiter.

Example:

Orbiter(position = OrbiterEdge.Top, offset = 10.dp) {
Text("This is a top edge Orbiter")
}
@Composable
@ComposableOpenTarget(index = -1)
fun Orbiter(
    position: OrbiterEdge.Horizontal,
    offset: EdgeOffset,
    alignment: Alignment.Horizontal = Alignment.CenterHorizontally,
    settings: OrbiterSettings = OrbiterDefaults.Settings,
    shape: SpatialShape = OrbiterDefaults.Shape,
    elevation: SpatialElevationLevel = OrbiterDefaults.Elevation,
    content: @Composable @UiComposable () -> Unit
): Unit

A composable that creates an orbiter along the top or bottom edges of a view.

Orbiters are floating elements that contain controls for spatial content. They allow the content to have more space and give users quick access to features like navigation without obstructing the main content.

In non-spatial environments, orbiters may be configured using OrbiterSettings.shouldRenderInNonSpatial to render their content as if the orbiter wrapper was not present or be removed from the flow entirely.

Parameters
position: OrbiterEdge.Horizontal

The edge of the orbiter. Use OrbiterEdge.Top or OrbiterEdge.Bottom.

offset: EdgeOffset

The offset of the orbiter based on the inner or outer edge of the orbiter. Use EdgeOffset.outer to create an EdgeOffset aligned to the outer edge of the orbiter or EdgeOffset.inner or EdgeOffset.overlap to create an EdgeOffset aligned to the inner edge of the orbiter.

alignment: Alignment.Horizontal = Alignment.CenterHorizontally

The alignment of the orbiter. Use Alignment.CenterHorizontally or Alignment.Start or Alignment.End.

settings: OrbiterSettings = OrbiterDefaults.Settings

The settings for the orbiter.

shape: SpatialShape = OrbiterDefaults.Shape

The shape of this Orbiter when it is rendered in 3D space.

elevation: SpatialElevationLevel = OrbiterDefaults.Elevation

The z-direction elevation level of this Orbiter.

content: @Composable @UiComposable () -> Unit

The content of the orbiter.

Example:

Orbiter(position = OrbiterEdge.Top, offset = outer(10.dp)) {
Text("This is a top edge Orbiter")
}
@Composable
@ComposableOpenTarget(index = -1)
fun Orbiter(
    position: OrbiterEdge.Vertical,
    offset: Dp = 0.dp,
    alignment: Alignment.Vertical = Alignment.CenterVertically,
    settings: OrbiterSettings = OrbiterDefaults.Settings,
    shape: SpatialShape = OrbiterDefaults.Shape,
    elevation: SpatialElevationLevel = OrbiterDefaults.Elevation,
    content: @Composable @UiComposable () -> Unit
): Unit

A composable that creates an orbiter along the start or end edges of a view.

Orbiters are floating elements that contain controls for spatial content. They allow the content to have more space and give users quick access to features like navigation without obstructing the main content.

In non-spatial environments, orbiters may be configured using OrbiterSettings.shouldRenderInNonSpatial to render their content as if the orbiter wrapper was not present or be removed from the flow entirely.

Parameters
position: OrbiterEdge.Vertical

The edge of the orbiter. Use OrbiterEdge.Start or OrbiterEdge.End.

offset: Dp = 0.dp

The offset of the orbiter based on the outer edge of the orbiter.

alignment: Alignment.Vertical = Alignment.CenterVertically

The alignment of the orbiter. Use Alignment.CenterVertically or Alignment.Top or Alignment.Bottom.

settings: OrbiterSettings = OrbiterDefaults.Settings

The settings for the orbiter.

shape: SpatialShape = OrbiterDefaults.Shape

The shape of this Orbiter when it is rendered in 3D space.

elevation: SpatialElevationLevel = OrbiterDefaults.Elevation

The z-direction elevation level of this Orbiter.

content: @Composable @UiComposable () -> Unit

The content of the orbiter.

Example:

Orbiter(position = OrbiterEdge.Start, offset = 10.dp) {
Text("This is a start edge Orbiter")
}
@Composable
@ComposableOpenTarget(index = -1)
fun Orbiter(
    position: OrbiterEdge.Vertical,
    offset: EdgeOffset,
    alignment: Alignment.Vertical = Alignment.CenterVertically,
    settings: OrbiterSettings = OrbiterDefaults.Settings,
    shape: SpatialShape = OrbiterDefaults.Shape,
    elevation: SpatialElevationLevel = OrbiterDefaults.Elevation,
    content: @Composable @UiComposable () -> Unit
): Unit

A composable that creates an orbiter along the start or end edges of a view.

Orbiters are floating elements that contain controls for spatial content. They allow the content to have more space and give users quick access to features like navigation without obstructing the main content.

In non-spatial environments, orbiters may be configured using OrbiterSettings.shouldRenderInNonSpatial to render their content as if the orbiter wrapper was not present or be removed from the flow entirely.

Parameters
position: OrbiterEdge.Vertical

The edge of the orbiter. Use OrbiterEdge.Start or OrbiterEdge.End.

offset: EdgeOffset

The offset of the orbiter based on the inner or outer edge of the orbiter. Use EdgeOffset.outer to create an EdgeOffset aligned to the outer edge of the orbiter or EdgeOffset.inner or EdgeOffset.overlap to create an EdgeOffset aligned to the inner edge of the orbiter.

alignment: Alignment.Vertical = Alignment.CenterVertically

The alignment of the orbiter. Use Alignment.CenterVertically or Alignment.Top or Alignment.Bottom.

settings: OrbiterSettings = OrbiterDefaults.Settings

The settings for the orbiter.

shape: SpatialShape = OrbiterDefaults.Shape

The shape of this Orbiter when it is rendered in 3D space.

elevation: SpatialElevationLevel = OrbiterDefaults.Elevation

The z-direction elevation level of this Orbiter.

content: @Composable @UiComposable () -> Unit

The content of the orbiter.

Example:

Orbiter(position = OrbiterEdge.Start, offset = outer(10.dp)) {
Text("This is a start edge Orbiter")
}

SpatialDialog

@Composable
fun SpatialDialog(
    onDismissRequest: () -> Unit,
    properties: SpatialDialogProperties = SpatialDialogProperties(),
    content: @Composable () -> Unit
): Unit

SpatialDialog is a dialog that is elevated above the activity.

When spatial dialogs are displayed the existing app content is pushed back and the dialog appears on top of the content at the base elevation level. When the dialog is dismissed the reverse happens with the dialog going away and the app content elevating back into place towards the user.

Parameters
onDismissRequest: () -> Unit

a callback to be invoked when the dialog should be dismissed.

properties: SpatialDialogProperties = SpatialDialogProperties()

the dialog properties.

content: @Composable () -> Unit

the content of the dialog.

SpatialElevation

@Composable
fun SpatialElevation(
    spatialElevationLevel: SpatialElevationLevel = SpatialElevationLevel.Level0,
    content: @Composable () -> Unit
): Unit

Composable that creates a panel in 3D space when spatialization is enabled.

SpatialElevation elevates content in-place. It uses the source position and constraints to determine the size and placement of the elevated panel while reserving space for the original element within the layout.

In non-spatial environments, the content is rendered normally without elevation.

SpatialElevation does not support a content lambda that has a width or height of zero.

Parameters
spatialElevationLevel: SpatialElevationLevel = SpatialElevationLevel.Level0

the desired elevation level for the panel in spatial environments.

content: @Composable () -> Unit

the composable content to be displayed within the elevated panel.

SpatialPopup

@Composable
fun SpatialPopup(
    alignment: Alignment = Alignment.TopStart,
    offset: IntOffset = IntOffset(0, 0),
    onDismissRequest: (() -> Unit)? = null,
    properties: SpatialPopupProperties = SpatialPopupProperties(),
    content: @Composable () -> Unit
): Unit

A composable that creates a panel in 3D space to hoist Popup based composables.

Parameters
alignment: Alignment = Alignment.TopStart

the alignment of the popup relative to its parent.

offset: IntOffset = IntOffset(0, 0)

An offset from the original aligned position of the popup. Offset respects the Ltr/Rtl context, thus in Ltr it will be added to the original aligned position and in Rtl it will be subtracted from it.

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

callback invoked when the user requests to dismiss the popup (e.g., by clicking outside).

properties: SpatialPopupProperties = SpatialPopupProperties()

PopupProperties configuration properties for further customization of this popup's behavior.

content: @Composable () -> Unit

the composable content to be displayed within the popup.

@Composable
@ComposableOpenTarget(index = -1)
fun Subspace(content: @Composable @SubspaceComposable SpatialBoxScope.() -> Unit): Unit

Create a 3D area that the app can render spatial content into.

If this is the topmost Subspace in the compose hierarchy then this will expand to fill all of the available space bounded by the SpatialUser's field of view in width and height and will not be bound by its containing window. In case the field of view width and height cannot be determined, the default field of view width and height values will be used.

If this is nested within another Subspace then it will lay out its content in the X and Y directions according to the layout logic of its parent in 2D space. It will be constrained in the Z direction according to the constraints imposed by its containing Subspace.

This is a no-op and does not render anything in non-XR environments (i.e. Phone and Tablet).

Subspace attempts to use the SpatialUser's field of view as width/height constraints for the subspace being created. If the calculation fails or if the HEAD_TRACKING Android permission is not granted, the default field of view width/height values will be used.

Parameters
content: @Composable @SubspaceComposable SpatialBoxScope.() -> Unit

The 3D content to render within this Subspace.