androidx.xr.compose.spatial

Interfaces

ContentEdge

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

Classes

ContentEdge.Horizontal
ContentEdge.Vertical

Represents vertical edges (start or end).

OrbiterOffsetType

Represents the type of offset used for positioning an orbiter.

SpatialDialogProperties

Properties for configuring a SpatialDialog.

Objects

OrbiterDefaults

Contains default values used by Orbiters.

SpatialElevationLevel

Defines standardized resting elevation levels for spatial UI elements.

Top-level functions summary

Unit

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

Unit
@Composable
@ComposableOpenTarget(index = -1)
Orbiter(
    position: ContentEdge.Horizontal,
    offset: Dp,
    offsetType: OrbiterOffsetType,
    alignment: Alignment.Horizontal,
    shape: SpatialShape,
    elevation: Dp,
    shouldRenderInNonSpatial: Boolean,
    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: ContentEdge.Vertical,
    offset: Dp,
    offsetType: OrbiterOffsetType,
    alignment: Alignment.Vertical,
    shape: SpatialShape,
    elevation: Dp,
    shouldRenderInNonSpatial: Boolean,
    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(elevation: Dp, content: @Composable () -> Unit)

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

Unit
@Composable
SpatialPopup(
    alignment: Alignment,
    offset: IntOffset,
    onDismissRequest: (() -> Unit)?,
    elevation: Dp,
    properties: PopupProperties,
    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? = null,
    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. The ApplicationSubspace will inherit its position and scale from the system's recommended position and scale.

By default, with no constraints provided, this Subspace is bounded by a recommended content box. This box represents a comfortable, human-scale area in front of the user, sized to occupy a significant portion of their view on any given device. Using this default is the suggested way to create responsive spatial layouts that look great without hardcoding dimensions.

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

On XR devices that cannot currently render spatial UI, the ApplicationSubspace will still create its scene and all of its internal state, even though nothing may be rendered. This is to ensure that the state is maintained consistently in the spatial scene and to allow preparation for the support of rendering spatial UI. State should be maintained by the compose runtime and events that cause the compose runtime to lose state (app process killed or configuration change) will also cause the ApplicationSubspace to lose its state.

Parameters
constraints: VolumeConstraints? = null

The volume constraints to apply to this ApplicationSubspace. If null (the default), the Subspace will be sized based on the system's recommended content box. This default provides a device-specific volume appropriate for comfortable viewing and interaction.

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

The 3D content to render within this Subspace.

@Composable
@ComposableOpenTarget(index = -1)
fun Orbiter(
    position: ContentEdge.Horizontal,
    offset: Dp = 0.dp,
    offsetType: OrbiterOffsetType = OrbiterOffsetType.OuterEdge,
    alignment: Alignment.Horizontal = Alignment.CenterHorizontally,
    shape: SpatialShape = OrbiterDefaults.Shape,
    elevation: Dp = OrbiterDefaults.Elevation,
    shouldRenderInNonSpatial: Boolean = true,
    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.

Parameters
position: ContentEdge.Horizontal

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

offset: Dp = 0.dp

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

offsetType: OrbiterOffsetType = OrbiterOffsetType.OuterEdge

The type of offset used for positioning the orbiter.

alignment: Alignment.Horizontal = Alignment.CenterHorizontally

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

shape: SpatialShape = OrbiterDefaults.Shape

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

elevation: Dp = OrbiterDefaults.Elevation

The z-direction elevation level of this Orbiter.

shouldRenderInNonSpatial: Boolean = true

In a non-spatial environment, if true the orbiter content is rendered as if the orbiter wrapper was not present and removed from the flow otherwise. In spatial environments, this flag is ignored.

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: ContentEdge.Vertical,
    offset: Dp = 0.dp,
    offsetType: OrbiterOffsetType = OrbiterOffsetType.OuterEdge,
    alignment: Alignment.Vertical = Alignment.CenterVertically,
    shape: SpatialShape = OrbiterDefaults.Shape,
    elevation: Dp = OrbiterDefaults.Elevation,
    shouldRenderInNonSpatial: Boolean = true,
    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.

Parameters
position: ContentEdge.Vertical

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

offset: Dp = 0.dp

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

offsetType: OrbiterOffsetType = OrbiterOffsetType.OuterEdge

The type of offset used for positioning the orbiter.

alignment: Alignment.Vertical = Alignment.CenterVertically

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

shape: SpatialShape = OrbiterDefaults.Shape

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

elevation: Dp = OrbiterDefaults.Elevation

The z-direction elevation level of this Orbiter.

shouldRenderInNonSpatial: Boolean = true

In a non-spatial environment, if true the orbiter content is rendered as if the orbiter wrapper was not present and removed from the flow otherwise. In spatial environments, this flag is ignored.

content: @Composable @UiComposable () -> Unit

The content of the orbiter.

Example:

Orbiter(position = OrbiterEdge.Start, offset = 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 dialog appears on top of the content at the base elevation level.

In non-spatialized environments, a standard Compose Dialog is utilized to display the content.

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(
    elevation: Dp = 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
elevation: Dp = 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,
    elevation: Dp = SpatialElevationLevel.Level3,
    properties: PopupProperties = PopupProperties(),
    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).

elevation: Dp = SpatialElevationLevel.Level3

the elevation value of the SpatialPopUp.

properties: PopupProperties = PopupProperties()

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, its size will be determined by the system's recommended content box. This provides a device-specific volume that represents a comfortable, human-scale viewing area, making it the recommended way to create responsive spatial layouts. See ApplicationSubspace for more detailed information and customization options for this top-level behavior.

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).

On XR devices that cannot currently render spatial UI, the Subspace will still create its scene and all of its internal state, even though nothing may be rendered. This is to ensure that the state is maintained consistently in the spatial scene and to allow preparation for the support of rendering spatial UI. State should be maintained by the compose runtime and events that cause the compose runtime to lose state (app process killed or configuration change) will also cause the Subspace to lose its state.

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

The 3D content to render within this Subspace.