SubcomposeLayoutState

Class

Common
class SubcomposeLayoutState(private val slotReusePolicy: SubcomposeSlotReusePolicy)

State used by SubcomposeLayout.

slotReusePolicy the policy defining what slots should be retained to be reused later.

Secondary Constructors

constructor() : this(NoOpSubcomposeSlotReusePolicy)

State used by SubcomposeLayout.

constructor(
    maxSlotsToRetainForReuse: Int
) : this(SubcomposeSlotReusePolicy(maxSlotsToRetainForReuse))

State used by SubcomposeLayout.

Parameters

maxSlotsToRetainForReusewhen 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.

Functions

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

Composes the content for the given slotId. This makes the next scope.subcompose(slotId) call during the measure pass faster as the content is already composed.

If the slotId 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 PrecomposedSlotHandle.dispose on a returned object to dispose the content.

Parameters

slotIdunique id which represents the slot to compose into.
contentthe composable content which defines the slot.

Returns

PrecomposedSlotHandle instance which allows you to dispose the content.
fun createPausedPrecomposition(
        slotId: Any?,
        content: @Composable () -> Unit,
    ): PausedPrecomposition

Creates PausedPrecomposition, which allows to perform the composition in an incremental manner.

Parameters

slotIdunique id which represents the slot to compose into.
contentthe composable content which defines the slot.`

Returns

PausedPrecomposition for the given slotId. 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.