SpatialActivityPanel

Functions summary

Unit

Creates a SpatialActivityPanel that launches and displays an Activity within it.

Unit
@Composable
@SubspaceComposable
SpatialActivityPanel(
    intent: Intent,
    modifier: SubspaceModifier,
    shape: SpatialShape,
    interactionPolicy: InteractionPolicy?
)

This function is deprecated. The `Intent` parameter has been replaced with a `SpatialActivityPanelController` to make launching additional activities more explicit.

Functions

SpatialActivityPanel

@Composable
@SubspaceComposable
fun SpatialActivityPanel(
    controller: SpatialActivityPanelController,
    modifier: SubspaceModifier = SubspaceModifier,
    shape: SpatialShape = SpatialPanelDefaults.shape
): Unit

Creates a SpatialActivityPanel that launches and displays an Activity within it.

This SpatialActivityPanel can render any Activity that the application has permission to invoke as an embedded activity.

The panel size is determined solely by the layout constraints and the provided modifier it does not resize based on the activity content.

import androidx.compose.runtime.remember
import androidx.xr.compose.spatial.Subspace
import androidx.xr.compose.subspace.SpatialActivityPanel
import androidx.xr.compose.subspace.rememberSpatialActivityPanelController

// Because the controller is remembered, passing a different intent parameter
// on recomposition will not update the controller or launch a new activity.
val controller = rememberSpatialActivityPanelController(intent)

Subspace { SpatialActivityPanel(controller = controller) }
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.remember
import androidx.compose.ui.platform.LocalContext
import androidx.xr.compose.spatial.Subspace
import androidx.xr.compose.subspace.SpatialActivityPanel
import androidx.xr.compose.subspace.rememberSpatialActivityPanelController

val context = LocalContext.current
val controller =
    rememberSpatialActivityPanelController(Intent(context, DashboardActivity::class.java))

Subspace {
    SpatialActivityPanel(controller = controller)

    LaunchedEffect(pendingItemId) {
        val itemId = pendingItemId ?: return@LaunchedEffect
        val detailIntent =
            Intent(context, DetailActivity::class.java).apply { putExtra("ITEM_ID", itemId) }

        controller.startActivity(detailIntent)
    }
}
import androidx.compose.foundation.layout.Column
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.key
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.platform.LocalContext
import androidx.xr.compose.spatial.Subspace
import androidx.xr.compose.subspace.SpatialActivityPanel
import androidx.xr.compose.subspace.rememberSpatialActivityPanelController

val context = LocalContext.current
var selectedEmailId by remember { mutableStateOf<String?>(null) }

Column {
    Button(onClick = { selectedEmailId = "email_1" }) { Text("Open Email 1") }

    Button(onClick = { selectedEmailId = "email_2" }) { Text("Open Email 2") }

    if (selectedEmailId != null) {
        Subspace {
            // Using Compose key to force recreation of the controller and
            // the panel whenever the selected email changes. This tears down
            // the old activity stack and starts a new one for the new email.
            key(selectedEmailId) {
                val intent =
                    Intent(context, NewEmailActivity::class.java).apply {
                        putExtra("EMAIL_ID", selectedEmailId)
                    }
                SpatialActivityPanel(
                    controller = rememberSpatialActivityPanelController(intent)
                )
            }
        }
    }
}
Parameters
controller: SpatialActivityPanelController

The SpatialActivityPanelController used to manage the Activities displayed within this panel. It provides a mechanism to queue and dispatch android.content.Intents to the embedded Activity environment.

modifier: SubspaceModifier = SubspaceModifier

SubspaceModifiers to apply to the SpatialPanel. The layout size of the panel will dictate the viewport size allocated to the embedded Activity.

shape: SpatialShape = SpatialPanelDefaults.shape

The shape of this Spatial Panel.

SpatialActivityPanel

@Composable
@SubspaceComposable
fun SpatialActivityPanel(
    intent: Intent,
    modifier: SubspaceModifier = SubspaceModifier,
    shape: SpatialShape = SpatialPanelDefaults.shape,
    interactionPolicy: InteractionPolicy? = null
): Unit

Creates a SpatialActivityPanel and launches an Activity within it.

The only supported use case for this SpatialPanel is to launch activities that are a part of the same application.

Parameters
intent: Intent

The intent of an Activity to launch within this panel.

modifier: SubspaceModifier = SubspaceModifier

SubspaceModifiers to apply to the SpatialPanel. The depth field in size-based modifiers affects this panel's layout size, but will not affect how the panel is rendered. The rendered shape will be a flat rectangle that is positioned on the front face of the rectangular prism created by the layout size.

shape: SpatialShape = SpatialPanelDefaults.shape

The shape of this Spatial Panel.

interactionPolicy: InteractionPolicy? = null

An optional InteractionPolicy that can be set to detect 3D input events. Setting this will not intercept 2D input events and is intended to provide additional spatial input information.