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

IntrinsicMeasureScope

Known direct subclasses
MeasureScope

The receiver scope of a layout's measure lambda.

Known indirect subclasses
IntermediateMeasureScope

IntermediateMeasureScope provides access to lookahead results to allow intermediateLayout to leverage lookahead results to define intermediate measurements and placements to gradually converge with lookahead.

LazyLayoutMeasureScope

The receiver scope of a LazyLayout's measure lambda.

SubcomposeIntermediateMeasureScope

SubcomposeIntermediateMeasureScope is the receiver scope for the intermediate measurer policy that gets invoked during the intermediate measure pass.

SubcomposeMeasureScope

The receiver scope of a SubcomposeLayout's measure lambda which adds ability to dynamically subcompose a content during the measuring on top of the features provided by MeasureScope.


The receiver scope of a layout's intrinsic measurements lambdas.

Summary

Public properties

open Boolean

This indicates whether the ongoing measurement is for lookahead pass.

Cmn
LayoutDirection

The LayoutDirection of the Layout or LayoutModifier using the measure scope to measure their children.

Cmn

Inherited functions

From androidx.compose.ui.unit.Density
open Int

Convert Dp to Int by rounding

Cmn
open Int

Convert Sp to Int by rounding

Cmn
open Dp

Convert Sp to Dp.

Cmn
open Dp

Convert an Int pixel value to Dp.

Cmn
open Dp

Convert a Float pixel value to a Dp

Cmn
open DpSize

Convert a Size to a DpSize.

Cmn
open Float

Convert Dp to pixels.

Cmn
open Float

Convert Sp to pixels.

Cmn
open Rect

Convert a DpRect to a Rect.

Cmn
open Size

Convert a DpSize to a Size.

Cmn
open TextUnit

Convert Dp to Sp.

Cmn
open TextUnit

Convert an Int pixel value to Sp.

Cmn
open TextUnit

Convert a Float pixel value to a Sp

Cmn

Inherited properties

From androidx.compose.ui.unit.Density
Float

The logical density of the display.

Cmn
Float

Current user preference for the scaling factor for fonts.

Cmn

Public properties

isLookingAhead

@ExperimentalComposeUiApi
open val isLookingAheadBoolean

This indicates whether the ongoing measurement is for lookahead pass. IntrinsicMeasureScope implementations, especially MeasureScope implementations should override this flag to reflect whether the measurement is intended for lookahead pass.

import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.AnimationVector2D
import androidx.compose.animation.core.VectorConverter
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clipToBounds
import androidx.compose.ui.layout.LookaheadScope
import androidx.compose.ui.layout.layout
import androidx.compose.ui.unit.IntSize

var sizeAnim by remember {
    mutableStateOf<Animatable<IntSize, AnimationVector2D>?>(null)
}
var lookaheadSize by remember {
    mutableStateOf<IntSize?>(null)
}
val coroutineScope = rememberCoroutineScope()
LookaheadScope {
    // The Box is in a LookaheadScope. This means there will be a lookahead measure pass
    // before the main measure pass.
    // Here we are creating something similar to the `animateContentSize` modifier.
    Box(
        Modifier
            .clipToBounds()
            .layout { measurable, constraints ->
                val placeable = measurable.measure(constraints)

                val measuredSize = IntSize(placeable.width, placeable.height)
                val (width, height) = if (isLookingAhead) {
                    // Record lookahead size if we are in lookahead pass. This lookahead size
                    // will be used for size animation, such that the main measure pass will
                    // gradually change size until it reaches the lookahead size.
                    lookaheadSize = measuredSize
                    measuredSize
                } else {
                    // Since we are in an explicit lookaheadScope, we know the lookahead pass
                    // is guaranteed to happen, therefore the lookahead size that we recorded is
                    // not null.
                    val target = requireNotNull(lookaheadSize)
                    val anim = sizeAnim?.also {
                        coroutineScope.launch { it.animateTo(target) }
                    } ?: Animatable(target, IntSize.VectorConverter)
                    sizeAnim = anim
                    // By returning the animated size only during main pass, we are allowing
                    // lookahead pass to see the future layout past the animation.
                    anim.value
                }

                layout(width, height) {
                    placeable.place(0, 0)
                }
            }) {
        // Some content that changes size
    }
}

layoutDirection

val layoutDirectionLayoutDirection

The LayoutDirection of the Layout or LayoutModifier using the measure scope to measure their children.