# SubcomposeLayoutState.PausedPrecomposition

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.PausedPrecomposition) Added in [1.9.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.9.0) Common/AllAndroid/JVM
- Cmn

  ```
  sealed interface 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.

Pausable subcomposition can be used between frames to prepare a subcomposition before it is required by the main composition. For example, this is used in lazy lists to prepare list items in between frames to that are likely to be scrolled in. The composition is paused when the start of the next frame is near, allowing composition to be spread across multiple frames without delaying the production of the next frame.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/PausedComposition` |   |

## Summary

| ### Public functions |
|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeLayoutState.PrecomposedSlotHandle` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeLayoutState.PausedPrecomposition#apply()()` Apply the composition. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeLayoutState.PausedPrecomposition#cancel()()` Cancels the paused composition. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeLayoutState.PausedPrecomposition#resume(androidx.compose.runtime.ShouldPauseCallback)(shouldPause: https://developer.android.com/reference/kotlin/androidx/compose/runtime/ShouldPauseCallback)` Resume the composition that has been paused. | Cmn |

| ### Public properties |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeLayoutState.PausedPrecomposition#isComplete()` Returns `true` when the `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeLayoutState.PausedPrecomposition` is complete. | Cmn |

## Public functions

### apply

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

```
fun apply(): SubcomposeLayoutState.PrecomposedSlotHandle
```

Apply the composition. This is the last step of a paused composition and is required to be called prior to the composition is usable.

Calling `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeLayoutState.PausedPrecomposition#apply()` should always be proceeded with a check of `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeLayoutState.PausedPrecomposition#isComplete()` before it is called and potentially calling `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeLayoutState.PausedPrecomposition#resume(androidx.compose.runtime.ShouldPauseCallback)` in a loop until `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeLayoutState.PausedPrecomposition#isComplete()` returns `true`. This can happen if `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeLayoutState.PausedPrecomposition#resume(androidx.compose.runtime.ShouldPauseCallback)` returned `true` but `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeLayoutState.PausedPrecomposition#apply()` was not synchronously called immediately afterwords. Any state that was read that changed between when `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeLayoutState.PausedPrecomposition#resume(androidx.compose.runtime.ShouldPauseCallback)` being called and `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeLayoutState.PausedPrecomposition#apply()` being called may require the paused composition to be resumed before applied.

| 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` you can use to premeasure the slot as well, or to dispose the composed content. |

### cancel

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

```
fun cancel(): Unit
```

Cancels the paused composition. This should only be used if the composition is going to be disposed and the entire composition is not going to be used.

### resume

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

```
fun resume(shouldPause: ShouldPauseCallback): Boolean
```

Resume the composition that has been paused. This method should be called until `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeLayoutState.PausedPrecomposition#resume(androidx.compose.runtime.ShouldPauseCallback)` returns `true` or `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeLayoutState.PausedPrecomposition#isComplete()` is `true` which has the same result as the last result of calling `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeLayoutState.PausedPrecomposition#resume(androidx.compose.runtime.ShouldPauseCallback)`. The `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeLayoutState.PausedPrecomposition#resume(androidx.compose.runtime.ShouldPauseCallback)` parameter is a lambda that returns whether the composition should be paused. For example, in lazy lists this returns `false` until just prior to the next frame starting in which it returns `true`

Calling `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeLayoutState.PausedPrecomposition#resume(androidx.compose.runtime.ShouldPauseCallback)` after it returns `true` or when `isComplete` is true will throw an exception.

| Parameters |
|---|---|
| `shouldPause: https://developer.android.com/reference/kotlin/androidx/compose/runtime/ShouldPauseCallback` | A lambda that is used to determine if the composition should be paused. This lambda is called often so should be a very simple calculation. Returning `true` does not guarantee the composition will pause, it should only be considered a request to pause the composition. Not all composable functions are pausable and only pausable composition functions will pause. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `true` if the composition is complete and `false` if one or more calls to `resume` are required to complete composition. |

## Public properties

### isComplete

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

```
val isComplete: Boolean
```

Returns `true` when the `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeLayoutState.PausedPrecomposition` is complete. `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeLayoutState.PausedPrecomposition#isComplete()` matches the last value returned from `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeLayoutState.PausedPrecomposition#resume(androidx.compose.runtime.ShouldPauseCallback)`. Once a `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeLayoutState.PausedPrecomposition` is `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeLayoutState.PausedPrecomposition#isComplete()` the `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeLayoutState.PausedPrecomposition#apply()` method should be called. If the `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeLayoutState.PausedPrecomposition#apply()` method is not called synchronously and immediately after `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeLayoutState.PausedPrecomposition#resume(androidx.compose.runtime.ShouldPauseCallback)` returns `true` then this `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeLayoutState.PausedPrecomposition#isComplete()` can return `false` as any state changes read by the paused composition while it is paused will cause the composition to require the paused composition to need to be resumed before it is used.