https://kotlinlang.org logo
Title
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:
.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
:nice: 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
inline fun Modifier.thenIf(take: Boolean, other: Modifier.() -> Modifier): Modifier =
    if (take) then(other()) else this
Which you can use like so:
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