# SubcomposeLayoutState

Artifact: [androidx.compose.ui:ui](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/layout/SubcomposeLayout.kt+class:androidx.compose.ui.layout.SubcomposeLayoutState) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0) Common/AllAndroid/JVM
- Cmn

  ```
  class SubcomposeLayoutState
  ```

*** ** * ** ***

State used by `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeLayout.composable#SubcomposeLayout(androidx.compose.ui.Modifier,kotlin.Function2)`.

`https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeLayoutState#slotReusePolicy()` the policy defining what slots should be retained to be reused later.

## Summary

| ### Nested types |
|---|
| `sealed interface https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeLayoutState.PausedPrecomposition` A `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeLayoutState.PausedPrecomposition` is a subcomposition that can be composed incrementally as it supports being paused and resumed. |
| `interface https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeLayoutState.PrecomposedSlotHandle` Instance of this interface is returned by `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeLayoutState#precompose(kotlin.Any,kotlin.Function0)` function. |

| ### Public constructors |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeLayoutState#SubcomposeLayoutState()()` State used by `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeLayout.composable#SubcomposeLayout(androidx.compose.ui.Modifier,kotlin.Function2)`. | Cmn |
| `[SubcomposeLayoutState](https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeLayoutState#SubcomposeLayoutState(kotlin.Int))(maxSlotsToRetainForReuse: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` **This function is deprecated.** This constructor is deprecated | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeLayoutState#SubcomposeLayoutState(androidx.compose.ui.layout.SubcomposeSlotReusePolicy)(slotReusePolicy: https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeSlotReusePolicy)` | Cmn |

| ### Public functions |
|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeLayoutState.PausedPrecomposition` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeLayoutState#createPausedPrecomposition(kotlin.Any,kotlin.Function0)(slotId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?, content: @https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable () -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)` Creates `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeLayoutState.PausedPrecomposition`, which allows to perform the composition in an incremental manner. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeLayoutState.PrecomposedSlotHandle` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeLayoutState#precompose(kotlin.Any,kotlin.Function0)(slotId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?, content: @https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable () -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)` Composes the content for the given `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeLayoutState#precompose(kotlin.Any,kotlin.Function0)`. | Cmn |

## Public constructors

### SubcomposeLayoutState

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

```
SubcomposeLayoutState()
```

State used by `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeLayout.composable#SubcomposeLayout(androidx.compose.ui.Modifier,kotlin.Function2)`.

### SubcomposeLayoutState

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0) Deprecated in [1.2.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.2.0)

```
[SubcomposeLayoutState](https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeLayoutState#SubcomposeLayoutState(kotlin.Int))(maxSlotsToRetainForReuse: Int)
```

> [!CAUTION]
> **This function is deprecated.**   
> This constructor is deprecated, use this instead:
>
> ```kotlin
> SubcomposeLayoutState(SubcomposeSlotReusePolicy(maxSlotsToRetainForReuse))
> ```

State used by `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeLayout.composable#SubcomposeLayout(androidx.compose.ui.Modifier,kotlin.Function2)`.

| Parameters |
|---|---|
| `maxSlotsToRetainForReuse: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | when non-zero the layout will keep active up to this count slots which we were used but not used anymore instead of disposing them. Later when you try to compose a new slot instead of creating a completely new slot the layout would reuse the previous slot which allows to do less work especially if the slot contents are similar. |

### SubcomposeLayoutState

Cmn Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.2.0)

```
SubcomposeLayoutState(slotReusePolicy: SubcomposeSlotReusePolicy)
```

## Public functions

### createPausedPrecomposition

Cmn Added in [1.9.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.9.0)

```
fun createPausedPrecomposition(slotId: Any?, content: @Composable () -> Unit): SubcomposeLayoutState.PausedPrecomposition
```

Creates `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeLayoutState.PausedPrecomposition`, which allows to perform the composition in an incremental manner.

| Parameters |
|---|---|
| `slotId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?` | unique id which represents the slot to compose into. |
| `content: @https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable () -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | the composable content which defines the slot.\] |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeLayoutState.PausedPrecomposition` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeLayoutState.PausedPrecomposition` for the given `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeLayoutState#createPausedPrecomposition(kotlin.Any,kotlin.Function0)`. It allows to perform the composition in an incremental manner. Performing full or partial precomposition makes the next scope.subcompose(slotId) call during the measure pass faster as the content is already composed. |

### precompose

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

```
fun precompose(slotId: Any?, content: @Composable () -> Unit): SubcomposeLayoutState.PrecomposedSlotHandle
```

Composes the content for the given `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeLayoutState#precompose(kotlin.Any,kotlin.Function0)`. This makes the next scope.subcompose(slotId) call during the measure pass faster as the content is already composed.

If the `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeLayoutState#precompose(kotlin.Any,kotlin.Function0)` was precomposed already but after the future calculations ended up to not be needed anymore (meaning this slotId is not going to be used during the measure pass anytime soon) you can use `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeLayoutState.PrecomposedSlotHandle#dispose()` on a returned object to dispose the content.

| Parameters |
|---|---|
| `slotId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?` | unique id which represents the slot to compose into. |
| `content: @https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable () -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | the composable content which defines the slot. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeLayoutState.PrecomposedSlotHandle` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeLayoutState.PrecomposedSlotHandle` instance which allows you to dispose the content. |