# FollowingSubspace

## 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/compose/runtime/ComposableOpenTarget(index = -1) @https://developer.android.com/reference/kotlin/androidx/xr/compose/spatial/ExperimentalFollowingSubspaceApi [FollowingSubspace](https://developer.android.com/reference/kotlin/androidx/xr/compose/spatial/FollowingSubspace.composable#FollowingSubspace(androidx.xr.compose.subspace.FollowTarget,androidx.xr.compose.subspace.FollowBehavior,androidx.xr.compose.subspace.layout.SubspaceModifier,androidx.xr.compose.subspace.TrackedDimensions,kotlin.Function1))( target: https://developer.android.com/reference/kotlin/androidx/xr/compose/subspace/FollowTarget, behavior: https://developer.android.com/reference/kotlin/androidx/xr/compose/subspace/FollowBehavior, modifier: https://developer.android.com/reference/kotlin/androidx/xr/compose/subspace/layout/SubspaceModifier, dimensions: https://developer.android.com/reference/kotlin/androidx/xr/compose/subspace/TrackedDimensions, content: @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/SpatialBoxScope.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html )` **This function is deprecated.** FollowingSubspace is deprecated. |

## Functions

### FollowingSubspace

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/spatial/Subspace.kt+function:FollowingSubspace)

```
@Composable
@ComposableOpenTarget(index = -1)
@ExperimentalFollowingSubspaceApi
fun [FollowingSubspace](https://developer.android.com/reference/kotlin/androidx/xr/compose/spatial/FollowingSubspace.composable#FollowingSubspace(androidx.xr.compose.subspace.FollowTarget,androidx.xr.compose.subspace.FollowBehavior,androidx.xr.compose.subspace.layout.SubspaceModifier,androidx.xr.compose.subspace.TrackedDimensions,kotlin.Function1))(
    target: FollowTarget,
    behavior: FollowBehavior,
    modifier: SubspaceModifier = SubspaceModifier,
    dimensions: TrackedDimensions = androidx.xr.compose.subspace.TrackedDimensions.All,
    content: @Composable @SubspaceComposable SpatialBoxScope.() -> Unit
): Unit
```

> [!CAUTION]
> **This function is deprecated.**   
> FollowingSubspace is deprecated. Use Subspace with the follow parameter instead.

Create a user-centric 3D space that is ideal for spatial UI content that follows a target.

Each call to `FollowingSubspace` creates a new, independent spatial UI hierarchy. It does **not** inherit the spatial position, orientation, or scale of any parent `Subspace` it is nested within. Its scale is decided by the system's recommended scale. Its position in the world is determined solely by its `target` parameter. By default, this Subspace is automatically bounded by the system's recommended content box, similar to `https://developer.android.com/reference/kotlin/androidx/xr/compose/spatial/Subspace.composable#Subspace(androidx.xr.compose.subspace.layout.SubspaceModifier,kotlin.Function1)`.

When the target parameter is specified to be `https://developer.android.com/reference/kotlin/androidx/xr/compose/subspace/FollowTarget#ArDevice(androidx.xr.runtime.Session)`, the content will be positioned relative to the view of the AR device. This is sometimes referred to as head-locked content. For this API, it is required for device tracking to not be disabled in the session configuration. If it is disabled, this API will not return anything. The session configuration should resemble `session.configure( config = Config.Builder(session.config).setDeviceTracking(DeviceTrackingMode.SPATIAL).build() )` The `https://developer.android.com/reference/kotlin/androidx/xr/compose/subspace/FollowTarget#ArDevice(androidx.xr.runtime.Session)` is not compatible with `https://developer.android.com/reference/kotlin/androidx/xr/compose/subspace/FollowBehavior#Tight()`. Combining these together will cause this composable to not be displayed. For a near-tight experience, use `https://developer.android.com/reference/kotlin/androidx/xr/compose/subspace/FollowBehavior#Soft(kotlin.Int)` with a low duration value.

When the target parameter is specified to be `https://developer.android.com/reference/kotlin/androidx/xr/compose/subspace/FollowTarget#Anchor(androidx.xr.scenecore.AnchorSpace)`, the content will be positioned around an anchor. This is useful for placing UI elements on real-world surfaces or at specific spatial locations. The visual stability of the anchored content depends on the underlying system's ability to track the `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/AnchorSpace`. For creating, loading, and persisting anchors, please check `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/AnchorSpace` for more information.

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

## Managing Spatial Overlap

Because each call to any kind of Subspace function creates an independent 3D scene, these spaces are not aware of one another. This can lead to a scenario where a moving `FollowingSubspace` (like a head-locked menu) can intersect with content in another stationary Subspace. This overlap can cause jarring visual artifacts and z-depth ordering issues (Z-fighting), creating a confusing user experience. A Subspace does not perform automatic collision avoidance between these independent Subspaces. It is the developer's responsibility to manage the layout and prevent these intersections or to introduce custom hit handling.

### Guidelines for Preventing Overlap:

1. **Control Volume Size**: Carefully define the bounds of your Subspace instances. Instead of letting content fill the maximum recommended constraints, use sizing modifiers to create smaller, manageable content areas that are less likely to collide.

2. **Use Strategic Offsets** : Use `SubspaceModifier.offset` to position a Subspace. For example, a head-locked menu can be offset to appear in the user's peripheral vision, reducing the chance it will collide with central content. Also, consider placing different Subspace instances at different depths. This ensures that if they overlap, their z-depth ordering will be clear and predictable. Note, however, that while the visual ordering may be clear, Jetpack XR doesn't guarantee predictable interaction behaviors between UI elements in separate, overlapping Subspaces.

Use `https://developer.android.com/reference/kotlin/androidx/xr/compose/spatial/Subspace.composable#Subspace(androidx.xr.compose.subspace.layout.SubspaceModifier,kotlin.Function1)` with the follow parameter instead.

| Parameters |
|---|---|
| `target: https://developer.android.com/reference/kotlin/androidx/xr/compose/subspace/FollowTarget` | Specifies an area which the Subspace will move towards. |
| `behavior: https://developer.android.com/reference/kotlin/androidx/xr/compose/subspace/FollowBehavior` | Determines how the FollowingSubspace follows the target. It can be made to move faster and be more responsive. The default is FollowBehavior.Soft(). |
| `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 the content of this Subspace. |
| `dimensions: https://developer.android.com/reference/kotlin/androidx/xr/compose/subspace/TrackedDimensions = androidx.xr.compose.subspace.TrackedDimensions.All` | A set of boolean flags to determine the dimensions of movement that are tracked. Possible tracking dimensions are: translationX, translationY, translationZ, rotationX, rotationY, and rotationZ. By default, all dimensions are tracked. Any dimensions not listed will not be tracked. For example, if translationY is not listed, this means the content will not move as the user moves vertically up and down. |
| `content: @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/SpatialBoxScope.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | The 3D content to render within this Subspace. |