Modifier

interface Modifier
androidx.ui.core.Modifier

An immutable chain of modifier elements for use with Composables. A Composable that has a Modifier can be considered decorated or wrapped by that Modifier.

Modifiers may be compared for equality provided that all of their elements are objects, data classes or otherwise implement equals. A correct implementation of an Element must meet this requirement.

Modifier elements may be combined using wraps. Order is significant; modifier elements wrap the modifiers to their right

Composables that accept a Modifier as a parameter to be applied to the whole component represented by the composable function should name the parameter modifier and assign the parameter a default value of Modifier.None. It should appear as the first optional parameter in the parameter list; after all required parameters (except for trailing lambda parameters) but before any other parameters with default values. Any default modifiers desired by a composable function should be concatenated to the right or left of the modifier parameter's value in the composable function's implementation, keeping Modifier.None as the default parameter value. For example:

    @Composable fun Foo(modifier: Modifier = Modifier.None) {
        Column(modifier wraps defaultFooModifier) {
            // ...
        }
    }

The pattern above allows default modifiers to still be applied as part of the chain if a caller also supplies unrelated modifiers.

Composables that accept modifiers to be applied to a specific subcomponent foo should name the parameter fooModifier and follow the same guidelines above for default values and behavior. Subcomponent modifiers should be grouped together and follow the parent composable's modifier. For example:

    @Composable fun ButtonBar(
        onOk: () -> Unit,
        onCancel: () -> Unit,
        modifier: Modifier = Modifier.None,
        buttonModifier: Modifier = Modifier.None
    ) {
        Row(modifier) {
            Button("Cancel", buttonModifier, onClick = onCancel)
            Button("Ok", buttonModifier, onClick = onOk)
        }
    }

Summary

Nested classes

abstract

A single element contained within a Modifier chain.

An empty Modifier that contains no elements.

Public methods

abstract R
foldIn(initial: R, operation: (R, Modifier.Element) -> R)

Accumulates a value starting with initial and applying operation to the current value and each element from outside in.

abstract R
foldOut(initial: R, operation: (Modifier.Element, R) -> R)

Accumulates a value starting with initial and applying operation to the current value and each element from inside out.

open infix Modifier
wraps(other: Modifier)

Wraps another Modifier with this one, returning the new chain.

Public methods

foldIn

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

Accumulates a value starting with initial and applying operation to the current value and each element from outside in.

Elements wrap one another in a chain from left to right; an Element that appears to the left of another in a wraps expression or in operation's parameter order affects all of the elements that appear after it. foldIn may be used to accumulate a value starting from the parent or head of the modifier chain to the final wrapped child.

foldOut

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

Accumulates a value starting with initial and applying operation to the current value and each element from inside out.

Elements wrap one another in a chain from left to right; an Element that appears to the left of another in a wraps expression or in operation's parameter order affects all of the elements that appear after it. foldOut may be used to accumulate a value starting from the child or tail of the modifier chain up to the parent or head of the chain.

wraps

open infix fun wraps(other: Modifier): Modifier

Wraps another Modifier with this one, returning the new chain.