`Surface` has separate versions for having or not having an `onClick` parameter. The control I’m bui...
m
Surface
has separate versions for having or not having an
onClick
parameter. The control I’m building with it can be disabled, and then it shouldn’t be clickable. Normally I could conditionally apply
Modifier.clickable
, but with
Surface
I don’t see a clean way of achieving this without writing two separate `Surface`s to toggle between. Am I missing something?
r
You can use a conditional modifier. Example from SO:
fun Modifier.conditional(condition : Boolean, modifier : Modifier.() -> Modifier) : Modifier { return if (condition) { then(modifier(Modifier)) } else { this } }
I've used something similar myself a few times
Maybe we have something built-in for this now
But I don't know :)
m
I know, the problem here is that on
Surface
, you don’t use a Modifier to have it be clickable, the
Surface
itself has an
onClick
argument, and there is a separate version that doesn’t.
I think I’ll just use a Box instead so I can have a conditional
Modifier.clickable
.
Turns out I was in fact missing something. The clickable
Surface
also has an
enabled
argument that does exactly what I need. 😄
r
Ah my bad, I read your post too fast, sorry. And yeah I was going to mention
enabled
next
I should have my tea in the morning before I answer questions lol
c
I wonder if Card has an enabled property
i asked a pretty much identical question a few weeks back. lol
m
A Card also has the
enabled
argument, which answers your version of this question. 😄
c
Oh yeahhhh. Nice! Thank you! TIL!