Hi guys! Is there a way to conditionally consume c...
# compose
t
Hi guys! Is there a way to conditionally consume click events?
á
You can concatenate modifiers like this:
Copy code
modifier.then(
        if (condition) {
            Modifier.clickable { }
        } else {
            Modifier
            // Not clickable
        }
This way you can add different modifiers according to your condition https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier#then
t
Thanks Adam!
a
You can do it even simplier with
Copy code
Modifier.clickable(enabled=condition){}
But this is not a consumption, just disabling
t
^ It will consume click events even if disabled