# SpatialMainPanel

## Functions summary

|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable @https://developer.android.com/reference/kotlin/androidx/xr/compose/subspace/SubspaceComposable https://developer.android.com/reference/kotlin/androidx/xr/compose/subspace/SpatialMainPanel.composable#SpatialMainPanel(androidx.xr.compose.subspace.layout.SubspaceModifier,androidx.xr.compose.subspace.layout.SpatialShape,androidx.xr.compose.subspace.layout.InteractionPolicy)( modifier: https://developer.android.com/reference/kotlin/androidx/xr/compose/subspace/layout/SubspaceModifier, shape: https://developer.android.com/reference/kotlin/androidx/xr/compose/subspace/layout/SpatialShape, interactionPolicy: https://developer.android.com/reference/kotlin/androidx/xr/compose/subspace/layout/InteractionPolicy? )` A composable that renders the Activity's main window's 2D UI content, defined in `https://developer.android.com/reference/kotlin/androidx/activity/compose/package-summary#(androidx.activity.ComponentActivity).setContent(androidx.compose.runtime.CompositionContext,kotlin.Function0)`, as a panel in a Subspace. |

## Functions

### SpatialMainPanel

Artifact: [androidx.xr.compose:compose](https://developer.android.com/jetpack/androidx/releases/xr-compose) [View Source](https://cs.android.com/search?q=file:androidx/xr/compose/subspace/SpatialPanel.kt+function:SpatialMainPanel) Added in [1.0.0-beta02](https://developer.android.com/jetpack/androidx/releases/xr-compose#1.0.0-beta02)

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

A composable that renders the Activity's main window's 2D UI content, defined in `https://developer.android.com/reference/kotlin/androidx/activity/compose/package-summary#(androidx.activity.ComponentActivity).setContent(androidx.compose.runtime.CompositionContext,kotlin.Function0)`, as a panel in a Subspace.

This composable acts as the bridge between the traditional 2D Android UI hierarchy and the 3D Subspace environment. Unlike `https://developer.android.com/reference/kotlin/androidx/xr/compose/subspace/SpatialPanel.composable#SpatialPanel(androidx.xr.compose.subspace.layout.SubspaceModifier,androidx.xr.compose.subspace.layout.SpatialShape,androidx.xr.compose.subspace.layout.InteractionPolicy,kotlin.Function0)`, which renders its own specific composable content, `https://developer.android.com/reference/kotlin/androidx/xr/compose/subspace/SpatialMainPanel.composable#SpatialMainPanel(androidx.xr.compose.subspace.layout.SubspaceModifier,androidx.xr.compose.subspace.layout.SpatialShape,androidx.xr.compose.subspace.layout.InteractionPolicy)` takes the entire view hierarchy from the Activity's main window and presents it on a movable, resizable panel in the Compose for XR's Spatial Scene Graph.

For the main window to be visible when `https://developer.android.com/reference/kotlin/androidx/xr/compose/spatial/Subspace.composable#Subspace(androidx.xr.compose.subspace.layout.SubspaceModifier,kotlin.Function1)` is present in the UI hierarchy, a `https://developer.android.com/reference/kotlin/androidx/xr/compose/subspace/SpatialMainPanel.composable#SpatialMainPanel(androidx.xr.compose.subspace.layout.SubspaceModifier,androidx.xr.compose.subspace.layout.SpatialShape,androidx.xr.compose.subspace.layout.InteractionPolicy)` *must* be included in the Subspace composition. If it is not composed, the underlying main panel entity is disabled by default. When `https://developer.android.com/reference/kotlin/androidx/xr/compose/subspace/SpatialMainPanel.composable#SpatialMainPanel(androidx.xr.compose.subspace.layout.SubspaceModifier,androidx.xr.compose.subspace.layout.SpatialShape,androidx.xr.compose.subspace.layout.InteractionPolicy)` is removed from the composition, it will again be disabled (hidden).

### How It Works

`https://developer.android.com/reference/kotlin/androidx/xr/compose/subspace/SpatialMainPanel.composable#SpatialMainPanel(androidx.xr.compose.subspace.layout.SubspaceModifier,androidx.xr.compose.subspace.layout.SpatialShape,androidx.xr.compose.subspace.layout.InteractionPolicy)` is backed by a single shared instance that will move the main content to its active usage. When the main content panel moves inside the composition, its state moves with it regardless of whether it is in a `https://developer.android.com/reference/kotlin/androidx/compose/runtime/MovableContent` block or not. Components that depend on the main panel's state (such as `https://developer.android.com/reference/kotlin/androidx/xr/compose/spatial/Orbiter.composable#Orbiter(androidx.xr.compose.spatial.ContentEdge.Horizontal,androidx.compose.ui.unit.Dp,androidx.xr.compose.spatial.OrbiterOffsetType,androidx.compose.ui.Alignment.Horizontal,androidx.xr.compose.subspace.layout.SpatialShape,androidx.compose.ui.unit.Dp,kotlin.Boolean,kotlin.Function0)`), will always access a single deterministic instance of the panel.

Only the first `SpatialMainPanel` added to the composition will be granted ownership of the main panel at any point in time. Subsequent instances of `SpatialMainPanel` will be queued to be shown, but will not be granted ownership of the main panel until the first instance is removed from composition. If the original owner is removed from and added back to composition, it will be added to the back of the queue.

The size of the panel in the Subspace is controlled by the standard Compose layout system, driven by the SubspaceModifier applied to it. Modifiers like SubspaceModifier.width directly dictate the panel's dimensions, following the same measurement and layout rules as other `https://developer.android.com/reference/kotlin/androidx/xr/compose/subspace/SubspaceComposable`s. To ensure stability, if the panel's layout size results in a width or height of zero, it will be automatically disabled to prevent crashes.

### Manifest Configuration

This panel requires the following specific configuration in the `AndroidManifest.xml` on the *base* activity for proper sizing and resizing behavior. Without it, resizing the main panel will

cause a crash.

```kotlin
<activity android:configChanges="orientation|screenSize|screenLayout|smallestScreenSize">
  ...
</activity>
```

```kotlin
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.xr.compose.spatial.Subspace
import androidx.xr.compose.subspace.SpatialMainPanel
import androidx.xr.compose.subspace.SpatialPanel
import androidx.xr.compose.subspace.SpatialRow

@Composable
fun MainPanelContent() {
    Text("Main panel")
}

@Composable
fun AppContent() {
    // 2D Content rendered to the main panel.
    MainPanelContent()

    // Spatial content rendered in full space mode.
    Subspace {
        SpatialRow {
            SpatialPanel { Text("Spatial panel") }
            SpatialMainPanel()
        }
    }
}
```

| Parameters |
|---|---|
| `modifier: https://developer.android.com/reference/kotlin/androidx/xr/compose/subspace/layout/SubspaceModifier = SubspaceModifier` | The `https://developer.android.com/reference/kotlin/androidx/xr/compose/subspace/layout/SubspaceModifier` to be applied to this panel, controlling its layout, size, and position within the parent. 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: https://developer.android.com/reference/kotlin/androidx/xr/compose/subspace/layout/SpatialShape = SpatialPanelDefaults.shape` | The shape of this Spatial Panel. |
| `interactionPolicy: https://developer.android.com/reference/kotlin/androidx/xr/compose/subspace/layout/InteractionPolicy? = null` | An optional `https://developer.android.com/reference/kotlin/androidx/xr/compose/subspace/layout/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. |