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

requiredHeight

Common

Modifier in Compose Foundation Layout

Last updated:

Installation

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

Overloads

@Stable
fun Modifier.requiredHeight(intrinsicSize: IntrinsicSize)
@Stable
fun Modifier.requiredHeight(height: Dp)

Code Example

SimpleRequiredHeightModifier

@Composable
fun SimpleRequiredHeightModifier() {
    // The result is a 50.dp x 50.dp blue box centered in a 100.dp x 100.dp space.
    // Note that although a previous modifier asked it to be 100.dp height, this
    // will not be respected. They would be respected if height was used instead of requiredHeight.
    Box(
        Modifier.requiredHeight(100.dp).requiredHeight(50.dp).aspectRatio(1f).background(Color.Blue)
    )
}
by @alexstyl