https://kotlinlang.org logo
#compose
Title
# compose
m

myanmarking

01/07/2022, 9:27 AM
is there a better way to do this? Some items are disabled so they wont need click:
Copy code
.then(if (isEnabled) Modifier.clickable { onItemClicked(index) } else Modifier)
f

Filip Wiesner

01/07/2022, 9:27 AM
I believe the
clickable
modifier has
enabled
parameter 🤔
👍🏼 1
👍 1
👌 1
b

Benoît

01/07/2022, 10:22 AM
Because this often doesn't only apply to Modifiers that have an
enabled
field I made this function
Copy code
inline fun Modifier.thenIf(take: Boolean, other: Modifier.() -> Modifier): Modifier =
    if (take) then(other()) else this
Which you can use like so:
Copy code
Modifier.thenIf(myBoldean) {
    background(color).padding(12.dp)
}
z

Zach Klippenstein (he/him) [MOD]

01/07/2022, 5:47 PM
I think including the modifier but setting it to disabled changes how accessibility services see it. Would recommend testing with eg talkback to see which effect fits your design