# SubcomposeSlotReusePolicy

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

  ```
  interface SubcomposeSlotReusePolicy
  ```

*** ** * ** ***

This policy allows `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeLayout.composable#SubcomposeLayout(androidx.compose.ui.Modifier,kotlin.Function2)` to retain some of slots which we were used but not used anymore instead of disposing them. Next time when you try to compose a new slot instead of creating a completely new slot the layout would reuse the kept slot. This allows to do less work especially if the slot contents are similar.

## Summary

| ### Nested types |
|---|
| `class https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeSlotReusePolicy.SlotIdsSet : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-collection/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?>` Set containing slot ids currently available to reuse. |

| ### Public functions |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeSlotReusePolicy#areCompatible(kotlin.Any,kotlin.Any)(slotId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?, reusableSlotId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?)` Returns true if the content previously composed with `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeSlotReusePolicy#areCompatible(kotlin.Any,kotlin.Any)` is compatible with the content which is going to be composed for `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeSlotReusePolicy#areCompatible(kotlin.Any,kotlin.Any)`. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeSlotReusePolicy#getSlotsToRetain(androidx.compose.ui.layout.SubcomposeSlotReusePolicy.SlotIdsSet)(slotIds: https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeSlotReusePolicy.SlotIdsSet)` This function will be called with `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeSlotReusePolicy#getSlotsToRetain(androidx.compose.ui.layout.SubcomposeSlotReusePolicy.SlotIdsSet)` set populated with the slot ids available to reuse. | Cmn |

## Public functions

### areCompatible

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

```
fun areCompatible(slotId: Any?, reusableSlotId: Any?): Boolean
```

Returns true if the content previously composed with `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeSlotReusePolicy#areCompatible(kotlin.Any,kotlin.Any)` is compatible with the content which is going to be composed for `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeSlotReusePolicy#areCompatible(kotlin.Any,kotlin.Any)`. Slots could be considered incompatible if they display completely different types of the UI.

### getSlotsToRetain

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

```
fun getSlotsToRetain(slotIds: SubcomposeSlotReusePolicy.SlotIdsSet): Unit
```

This function will be called with `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeSlotReusePolicy#getSlotsToRetain(androidx.compose.ui.layout.SubcomposeSlotReusePolicy.SlotIdsSet)` set populated with the slot ids available to reuse. In the implementation you can remove slots you don't want to retain.