androidx.compose.ui

Modifier

Interface · from org.jetbrains.compose.ui:ui:1.12.2

A Modifier changes how an element is sized, placed, drawn and how it reacts to input. Pass it to the modifier parameter of any composable.

Modifier on its own is the empty modifier. Each call like .padding(16.dp) returns a new, longer one. The order matters: the chain is applied from outside to inside.

The Modifier guide lists what modifiers exist and how to use them.

The same two modifiers in a different order
The same two modifiers in a different order
Row(horizontalArrangement = Arrangement.spacedBy(16.dp)) {
    // Padding first: the background is drawn inside the padding.
    Text(
        "padding, then background",
        Modifier.padding(16.dp).background(MaterialTheme.colorScheme.primaryContainer),
    )
    // Background first: the background also covers the padding.
    Text(
        "background, then padding",
        Modifier.background(MaterialTheme.colorScheme.primaryContainer).padding(16.dp),
    )
}
interface Modifier

Kinds of Modifier

Anywhere a Modifier is expected, you can pass any of these.

How to get one

Start with Modifier and add calls: Modifier.padding(16.dp).fillMaxWidth().

Ready-made values and functions that return it

Or create one of the kinds listed above.

Used by

Parameters that take a Modifier.

177 more

Functions

foldIn

fun <R> foldIn(initial: R, operation: (R, Element) -> R): R

Walks the chain from outside to inside. For library code.

foldOut

fun <R> foldOut(initial: R, operation: (Element, R) -> R): R

Walks the chain from inside to outside. For library code.

any

fun any(predicate: (Element) -> Boolean): Boolean

true if any element in the chain matches. Rarely needed in app code.

all

fun all(predicate: (Element) -> Boolean): Boolean

true if all elements in the chain match. Rarely needed in app code.

then

fun then(other: Modifier): Modifier

Joins two modifiers: Modifier.padding(8.dp).then(otherModifier). Useful to add a modifier only sometimes.

Nested types