Build apps faster with our new App builder! Check it out →

defaultMinSize

Common

Modifier in Compose Foundation Layout

Constrain the size of the wrapped layout only when it would be otherwise unconstrained: the [minWidth] and [minHeight] constraints are only applied when the incoming corresponding constraint is 0. The modifier can be used, for example, to define a default min size of a component, while still allowing it to be overidden with smaller min sizes across usages.

Last updated:

Installation

dependencies {
   implementation("androidx.compose.foundation:foundation-layout:1.8.0-alpha04")
}

Overloads

@Stable
fun Modifier.defaultMinSize(minWidth: Dp = Dp.Unspecified, minHeight: Dp = Dp.Unspecified)

Code Example

DefaultMinSizeSample

@Composable
fun DefaultMinSizeSample() {
    @Composable
    fun DefaultMinBox(modifier: Modifier = Modifier) {
        Box(modifier.defaultMinSize(minWidth = 100.dp, minHeight = 100.dp).background(Color.Blue))
    }
    // This will be a 100.dp x 100.dp blue box. Because we are not providing any min constraints
    // to the DefaultMinBox, defaultMinSize will apply its min constraints.
    DefaultMinBox()
    // This will be a 50.dp x 50.dp blue box. Because we are providing min constraints
    // to the DefaultMinBox, defaultMinSize will not apply its min constraints.
    DefaultMinBox(Modifier.requiredSizeIn(minWidth = 50.dp, minHeight = 50.dp))
    // Note that if DefaultMinBox used requiredSizeIn or sizeIn rather than
    // defaultMinSize, the min constraints would have been applied with either
    // of the above usages.
}
by @alexstyl