androidx.compose.ui.layout
approachLayout
Function · from org.jetbrains.compose.ui:ui:1.12.2
No hand-written docs yet.
Creates an approach layout intended to help gradually approach the destination layout calculated in the lookahead pass. This can be particularly helpful when the destination layout is anticipated to change drastically and would consequently result in visual disruptions.
Parameters
fun Modifier.approachLayout(
isMeasurementApproachInProgress: (lookaheadSize: IntSize) -> Boolean,
isPlacementApproachInProgress: Placeable.PlacementScope.(lookaheadCoordinates: LayoutCoordinates) -> Boolean = defaultPlacementApproachInProgress,
approachMeasure: ApproachMeasureScope.(measurable: Measurable, constraints: Constraints) -> MeasureResult,
): Modifier
isMeasurementApproachInProgress: (lookaheadSize: IntSize) -> BooleanRequired
isMeasurementApproachInProgress: (lookaheadSize: IntSize) -> BooleanRequiredNot described.
isPlacementApproachInProgress: Placeable.PlacementScope.(lookaheadCoordinates: LayoutCoordinates) -> BooleanOptional
isPlacementApproachInProgress: Placeable.PlacementScope.(lookaheadCoordinates: LayoutCoordinates) -> BooleanOptionalDefault: defaultPlacementApproachInProgress
Not described.
approachMeasure: ApproachMeasureScope.(measurable: Measurable, constraints: Constraints) -> MeasureResultRequired
approachMeasure: ApproachMeasureScope.(measurable: Measurable, constraints: Constraints) -> MeasureResultRequiredNot described.
Library docs
Creates an approach layout intended to help gradually approach the destination layout calculated in the lookahead pass. This can be particularly helpful when the destination layout is anticipated to change drastically and would consequently result in visual disruptions.
In order to create a smooth approach, an interpolation (often through animations) can be used in
approachMeasure to interpolate the measurement or placement from a previously recorded size
and/or position to the destination/target size and/or position. The destination size is available
in ApproachMeasureScope as ApproachMeasureScope.lookaheadSize. And the target position can
also be acquired in ApproachMeasureScope during placement by using
LookaheadScope.localLookaheadPositionOf with the layout's
Placeable.PlacementScope.coordinates. The sample code below illustrates how that can be
achieved.
isMeasurementApproachInProgress signals whether the measurement is in progress of approaching
destination size. It will be queried after the destination has been determined by the lookahead
pass, before approachMeasure is invoked. The lookahead size is provided to
isMeasurementApproachInProgress for convenience in deciding whether the destination size has
been reached.
isMeasurementApproachInProgress indicates whether the position is currently approaching
destination defined by the lookahead, hence it's a signal to the system for whether additional
approach placements are necessary. isPlacementApproachInProgress will be invoked after the
destination position has been determined by lookahead pass, and before the placement phase in
approachMeasure.
Once both isMeasurementApproachInProgress and isPlacementApproachInProgress return false, the
system may skip approach pass until additional approach passes are necessary as indicated by
isMeasurementApproachInProgress and isPlacementApproachInProgress.
IMPORTANT: It is important to be accurate in isPlacementApproachInProgress and
isMeasurementApproachInProgress. A prolonged indication of incomplete approach will prevent the
system from potentially skipping approach pass when possible.