New Compose Multiplatform components arrived on Composables UICheck it out →

Modifier in Compose Foundation Layout

defaultMinSize

Common

Last updated:

Installation

dependencies {
   implementation("androidx.compose.foundation:foundation-layout:1.7.0-beta04")
}

Overloads

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

Code Example

DefaultMinSizeSample

@Composable
@Sampled
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.
}