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:
SharedTransitionLayoutandModifier.sharedElement: an element flies from one screen to the next.Modifier.animateBounds(lookaheadScope): an element animates to its new size and position when the layout changes.- The adaptive pane layouts, like
ListDetailPaneScaffold, which animate panes when the window changes.
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
- Shared element transitions in Compose (Android Developers): the most common use
- animateBounds reference (Android Developers)
- LookaheadScope reference (Android Developers): how to write your own lookahead-aware modifiers
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
content: @Composable @UiComposable LookaheadScope.() -> UnitRequiredThe layouts that take part in lookahead. Inside, this is the scope; pass it to Modifier.animateBounds(this).
How to get one
Create it
LookaheadScope(content: @Composable @UiComposable LookaheadScope.() -> Unit)
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.