androidx.compose.ui.layout

LookaheadScope

Interface · from org.jetbrains.compose.ui:ui:1.12.2

Inside a LookaheadScope, Compose measures the layout twice. First a lookahead pass works out where everything will end up. Then the real pass can move each element there step by step. This is the base for animating size and position changes.

You rarely use it directly. These APIs are built on it:

LookaheadScope {
    // this is the LookaheadScope
    val itemModifier = Modifier.animateBounds(this)
    if (wide) Row { Item(itemModifier); Item(itemModifier) }
    else Column { Item(itemModifier); Item(itemModifier) }
}

Read more

interface LookaheadScope

Kinds of LookaheadScope

Anywhere a LookaheadScope is expected, you can pass any of these.

LookaheadScope { }

@Composable
fun LookaheadScope(
    content: @Composable @UiComposable LookaheadScope.() -> Unit,
)

content: @Composable @UiComposable LookaheadScope.() -> UnitRequired

The layouts that take part in lookahead. Inside, this is the scope; pass it to Modifier.animateBounds(this).

How to get one

Create it

Or create one of the kinds listed above.

Properties

lookaheadScopeCoordinates

val Placeable.PlacementScope.lookaheadScopeCoordinates: LayoutCoordinates

Returns the LayoutCoordinates of the LookaheadScope. This is only accessible from Placeable.PlacementScope (i.e. during placement time).

Functions

toLookaheadCoordinates

fun LayoutCoordinates.toLookaheadCoordinates(): LayoutCoordinates

Converts a LayoutCoordinates into a LayoutCoordinates in the Lookahead coordinate space. This can be used for layouts within LookaheadScope.

localLookaheadPositionOf

fun LayoutCoordinates.localLookaheadPositionOf(
    sourceCoordinates: LayoutCoordinates,
    relativeToSource: Offset = Offset.Zero,
    includeMotionFrameOfReference: Boolean = true,
): Offset

Converts relativeToSource in sourceCoordinates's lookahead coordinate space into local lookahead coordinates. This is a convenient method for 1) converting both this coordinates and sourceCoordinates into lookahead space coordinates using toLookaheadCoordinates, and 2) invoking LayoutCoordinates.localPositionOf with the converted coordinates.