val modifierA = Modifier.size(100.dp)
val modifierB = Modifier.background(Color.Red)
How do you create a modifierC that is the concatenation of A and B?
I tried using .apply and .also, but to no avail.
val modifierA = Modifier.size(100.dp)
val modifierB = Modifier.background(Color.Red)
How do you create a modifierC that is the concatenation of A and B?
I tried using .apply and .also, but to no avail.
You can use Modifier.then
Concatenates this modifier with another.
val modifierA = Modifier.size(100.dp)
val modifierB = Modifier.background(Color.Red)
val modifierC = modifierA.then(modifierB)
Row {
Box(
modifier = Modifier
.then(modifierC)
)
Box(
modifier = Modifier
.then(Modifier.size(100.dp))
.then(Modifier.background(Color.Green))
)
Box(
modifier = Modifier
.size(100.dp)
.background(Color.Blue)
)
}
These three modifiers are equivalent, excluding color.
You can use the composed function:
Declare a just-in-time composition of a Modifier that will be composed for each element it modifies
Something like:
Box(modifierA.composed{ modifierB })
or
val modifierC = modifierA.composed{ modifierB }
Box(modifierC) {}