androidx.xr.compose.subspace.semantics

Interfaces

SubspaceSemanticsPropertyReceiver

Scope provided by semantics blocks, letting you set key/value pairs for use in testing, accessibility, etc.

Classes

SubspaceSemanticsConfiguration

Configuration of semantics properties for a spatial node.

Extension functions summary

SubspaceModifier

Add semantics key/value pairs to the layout node, for use in testing, accessibility, etc.

SubspaceModifier

Applies a tag to allow modified element to be found in tests.

Extension properties summary

String

Developer-set content description of the accessibility node.

String

Test tag attached to this semantics node.

Extension functions

SubspaceModifier.semantics

fun SubspaceModifier.semantics(properties: SubspaceSemanticsPropertyReceiver.() -> Unit): SubspaceModifier

Add semantics key/value pairs to the layout node, for use in testing, accessibility, etc.

Mental Model (Picture Frame vs. Canvas): When building a combined UI in Compose for XR, think of a Subspace node (such as SpatialPanel) as a "Picture Frame" existing in 3D space, and the standard 2D Compose UI elements inside it as the "Canvas".

Interop & Merging Guidance: The 3D Subspace semantics tree and the 2D foundational semantics tree operate as distinct hierarchies. Spatial containers do not support merging descendant semantics (mergeDescendants = true).

import androidx.compose.foundation.layout.Column
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
import androidx.xr.compose.spatial.Subspace
import androidx.xr.compose.subspace.SpatialPanel
import androidx.xr.compose.subspace.layout.SubspaceModifier
import androidx.xr.compose.subspace.semantics.contentDescription
import androidx.xr.compose.subspace.semantics.semantics
import androidx.xr.compose.subspace.semantics.testTag

@Composable
fun AppContent() {
    // Mental Model: The "Picture Frame" (3D Container) vs. the "Canvas" (2D Content)
    Subspace {
        SpatialPanel(
            modifier =
                SubspaceModifier.semantics {
                    // Set spatial semantics on the 3D container (the "Picture Frame")
                    testTag = "main_settings_panel"
                    contentDescription = "System Settings Window"
                }
        ) {
            // Standard 2D Compose UI goes inside (the "Canvas").
            // These elements use standard Modifier.semantics for TalkBack and interactions.
            Column {
                Text("System Settings")
                Button(
                    onClick = { /* do something */ },
                    modifier = Modifier.semantics { contentDescription = "Perform action" },
                ) {
                    Text("Click Me")
                }
            }
        }
    }
}
Parameters
properties: SubspaceSemanticsPropertyReceiver.() -> Unit

Builder block where the semantics properties are defined.

SubspaceModifier.testTag

fun SubspaceModifier.testTag(tag: String): SubspaceModifier

Applies a tag to allow modified element to be found in tests.

This is a convenience method for a semantics that sets SubspaceSemanticsPropertyReceiver.testTag.

Parameters
tag: String

String used to identify the modified element in tests.

Extension properties

SubspaceSemanticsPropertyReceiver.contentDescription

var SubspaceSemanticsPropertyReceiver.contentDescriptionString

Developer-set content description of the accessibility node.

SubspaceSemanticsPropertyReceiver.testTag

var SubspaceSemanticsPropertyReceiver.testTagString

Test tag attached to this semantics node.