State of Compose 2023 results are in! Click here to learn more

← Back to Compose UI

LookaheadLayout

Component
in
Compose UI
. Since 1.3.0

Overview

Code Examples

LookaheadLayout is a Layout that runs a lookahead measure and placement pass to determine the layout. Immediately afterwards, another measure and placement pass will begin, in which the measurement and placement of any layout can be adjusted based on the lookahead results via LookaheadLayoutScope.intermediateLayout.

During the lookahead pass, the layout adjustment logic defined in LookaheadLayoutScope.intermediateLayout will be skipped, so that any transient morphing of the layout is not taken into account when predetermining the target layout.

Once the lookahead is finished, another measure & layout pass will begin. LookaheadLayoutScope.intermediateLayout can be used to create an intermediate layout based on incoming constraints and the lookahead results. This can result in layouts that gradually change their sizes & positions towards the target layout calculated by the lookahead.

Caveat: SubcomposeLayout is not yet supported in LookaheadLayout. It will be supported in an upcoming release.

Overloads

LookaheadLayout

@Suppress("ComposableLambdaParameterPosition")
@ExperimentalComposeUiApi
@UiComposable
@Composable
fun LookaheadLayout(
    content: @Composable @UiComposable LookaheadLayoutScope.() -> Unit,
    modifier: Modifier = Modifier,
    measurePolicy: MeasurePolicy
)

Parameters

NameDescription
contentThe children composable to be laid out.
modifierModifiers to be applied to the layout.
measurePolicyThe policy defining the measurement and positioning of the layout