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 |
Objects
OrbiterDefaults |
Contains default values used by Orbiters. |
SpatialElevationLevel |
Defines standardized resting elevation levels for spatial UI elements. |
Top-level functions summary
Unit |
@ComposableCreate a 3D area that the app can render spatial content into with optional |
Unit |
@ComposableA composable that creates an orbiter along the top or bottom edges of a view. |
Unit |
@ComposableA composable that creates an orbiter along the start or end edges of a view. |
Unit |
@Composable
|
Unit |
@ComposableComposable that creates a panel in 3D space when spatialization is enabled. |
Unit |
@ComposableA composable that creates a panel in 3D space to hoist Popup based composables. |
Unit |
@ComposableCreate a 3D area that the app can render spatial content into. |
Top-level functions
ApplicationSubspace
@Composable
@ComposableOpenTarget(index = -1)
fun ApplicationSubspace(
modifier: SubspaceModifier = SubspaceModifier,
allowUnboundedSubspace: Boolean = false,
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, this Subspace is automatically bounded by the system's 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. SubspaceModifiers like SubspaceModifier.fillMaxSize will expand to fill this recommended box. This default can be overridden by applying a custom size-based modifier. For unbounded behavior, set [allowUnboundedSubspace] = true.
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 | |
|---|---|
modifier: SubspaceModifier = SubspaceModifier |
The |
allowUnboundedSubspace: Boolean = false |
If true, the default recommended content box constraints will not be applied, allowing the Subspace to be infinite. Defaults to false, providing a safe, bounded space. |
content: @Composable @SubspaceComposable SpatialBoxScope.() -> Unit |
The 3D content to render within this Subspace. |
Orbiter
@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 are typically used to control the content within spatial panels and other entities that they're anchored to. They allow the content to have more space and give users quick access to features like navigation without obstructing the main content.
The size of the Orbiter is constrained by the dimensions of the parent spatial component it is anchored to (e.g., a androidx.xr.compose.subspace.SpatialPanel). If it's not placed within a specific spatial component, it defaults to the main window's size. Consequently, an Orbiter's content cannot be larger than its parent's dimensions.
| Parameters | |
|---|---|
position: ContentEdge.Horizontal |
The edge of the orbiter. Use |
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 |
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 |
content: @Composable @UiComposable () -> Unit |
The content of the orbiter. Example: Orbiter(position = ContentEdge.Top, offset = 10.dp) { |
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 are typically used to control the content within spatial panels and other entities that they're anchored to. They allow the content to have more space and give users quick access to features like navigation without obstructing the main content.
The size of the Orbiter is constrained by the dimensions of the parent spatial component it is anchored to (e.g., a androidx.xr.compose.subspace.SpatialPanel). If it's not placed within a specific spatial component, it defaults to the main window's size. Consequently, an Orbiter's content cannot be larger than its parent's dimensions.
| Parameters | |
|---|---|
position: ContentEdge.Vertical |
The edge of the orbiter. Use |
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 |
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 |
content: @Composable @UiComposable () -> Unit |
The content of the orbiter. Example: Orbiter(position = ContentEdge.Start, offset = 10.dp) { |
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() |
|
content: @Composable () -> Unit |
the composable content to be displayed within the popup. |
Subspace
@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. |