BoxWithConstraints
@Composable
fun BoxWithConstraints(
modifier: Modifier = Modifier,
contentAlignment: Alignment = Alignment.TopStart,
propagateMinConstraints: Boolean = false,
content: @Composable @UiComposable BoxWithConstraintsScope.() -> Unit,
)
A composable that defines its own content according to the available space, based on the incoming
constraints or the current LayoutDirection
.
The composable will compose the given children, and will position the resulting layout elements
in a parent layout which behaves similar to a Box
. The layout will size itself to fit the
content, subject to the incoming constraints. When children are smaller than the parent, by
default they will be positioned inside the layout according to the contentAlignment
. For
individually specifying the alignments of the children layouts, use the BoxScope.align
modifier. By default, the content will be measured without the Box
's incoming min constraints,
unless propagateMinConstraints
is true
. As an example, setting propagateMinConstraints
to
true
can be useful when the BoxWithConstraints
has content on which modifiers cannot be
specified directly and setting a min size on the content of the BoxWithConstraints
is needed.
If propagateMinConstraints
is set to true
, the min size set on the BoxWithConstraints
will
also be applied to the content, whereas otherwise the min size will only apply to the
BoxWithConstraints
. When the content has more than one layout child the layout children will be
stacked one on top of the other (positioned as explained above) in the composition order.
Parameters
modifier | Modifier to be applied to the layout. |
contentAlignment | The default alignment inside the BoxWithConstraints . |
propagateMinConstraints | Whether the incoming min constraints should be passed to content. |
content | The content of the BoxWithConstraints . |