{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

SubcomposeLayoutState

public final class SubcomposeLayoutState


State used by SubcomposeLayout.

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

Summary

Nested types

Instance of this interface is returned by precompose function.

Public constructors

State used by SubcomposeLayout.

SubcomposeLayoutState(int maxSlotsToRetainForReuse)

This method is deprecated. This constructor is deprecated

Public methods

final boolean

Returns whether the SubcomposeLayout is in a LookaheadScope.

final @NonNull SubcomposeLayoutState.PrecomposedSlotHandle
precompose(Object slotId, @Composable @NonNull Function0<Unit> content)

Composes the content for the given slotId.

Public constructors

SubcomposeLayoutState

public SubcomposeLayoutState()

State used by SubcomposeLayout.

SubcomposeLayoutState

public SubcomposeLayoutState(int maxSlotsToRetainForReuse)

State used by SubcomposeLayout.

Parameters
int maxSlotsToRetainForReuse

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

public SubcomposeLayoutState(
    @NonNull SubcomposeSlotReusePolicy slotReusePolicy
)

Public methods

isInLookaheadScope

@ExperimentalComposeUiApi
public final boolean isInLookaheadScope()

Returns whether the SubcomposeLayout is in a LookaheadScope. Intermediate measure policy will be only invoked when in a LookaheadScope.

precompose

public final @NonNull SubcomposeLayoutState.PrecomposedSlotHandle precompose(Object slotId, @Composable @NonNull Function0<Unit> content)

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
Object slotId

unique id which represents the slot we are composing into.

@Composable @NonNull Function0<Unit> content

the composable content which defines the slot.

Returns
@NonNull SubcomposeLayoutState.PrecomposedSlotHandle

PrecomposedSlotHandle instance which allows you to dispose the content.