Skip to content

Instantly share code, notes, and snippets.

@KatieBarnett
Created August 1, 2023 10:41
Show Gist options
  • Save KatieBarnett/40f0ec95bc8116c760c79d2beb3f28bd to your computer and use it in GitHub Desktop.
Save KatieBarnett/40f0ec95bc8116c760c79d2beb3f28bd to your computer and use it in GitHub Desktop.
Conditional Modifier
fun Modifier.conditional(
condition: Boolean,
ifTrue: Modifier.() -> Modifier,
ifFalse: (Modifier.() -> Modifier)? = null,
): Modifier {
return if (condition) {
then(ifTrue(Modifier))
} else if (ifFalse != null) {
then(ifFalse(Modifier))
} else {
this
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment