androidx.compose.foundation.layout

BoxWithConstraints

Composable function · from org.jetbrains.compose.foundation:foundation-layout:1.12.2

One of the box types. It works like Box. Only the parameters that differ are described here.

A Box that tells its content how much space it has. Inside, maxWidth and maxHeight give the available size in dp.

BoxWithConstraints {
    if (maxWidth < 400.dp) NarrowLayout() else WideLayout()
}

Use it when a part of the screen changes with its own size. For the whole window, use window size classes; see the Adaptive layouts guide.

Parameters

@Composable
fun BoxWithConstraints(
    modifier: Modifier = Modifier,
    contentAlignment: Alignment = Alignment.TopStart,
    propagateMinConstraints: Boolean = false,
    content: @Composable @UiComposable BoxWithConstraintsScope.() -> Unit,
)

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

The children, from bottom to top.

Same as in Box: modifier, contentAlignment, propagateMinConstraints.

Box types