I don’t have context to give you a meaningful answer, but if and only if the only thing you want is an alternative way to write that bit of code, you likely can do a
conditional modifier extension:
fun Modifier.thenIf(
predicate: Boolean,
block: () -> Modifier,
) = then(if (predicate) block() else this)
And now you can rewrite that code as such:
Modifier
.thenIf(label != null) {
Modifier
.padding(8.dp)
.semantics(mergeDescendants = true) {
// no-op
}
}
.background(colors.backgroundColor(enabled).value, shape)
.defaultMinSize(
minWidth = 120.dp,
minHeight = 24.dp
)
That isn’t much better than the
apply
+
if
you did - if you are willing to give more details, maybe we can find an alternative solution.