How I can pass the click event from child composab...
# compose
a
How I can pass the click event from child composable to its parent? e.g:
Copy code
Card(
  Modifier.clickable { doSomething() }
){
   CheckBox(
     .....,
     onCheckedChange = {  } // leave it empty and pass its event to parent
   )
   Text("Some label")
}
m
pass in a lambda that is invoked from the onCheckedChange
a
I don't want to manage multiple clicks for the same purpose, more easier to disable clicks from children composable and delegate it to the parent, but how I can achieve that?
o
Could you check if setting
onCheckedChange
to
null
does the trick? According to doc this should work 🤔
Copy code
If null, then this is passive and relies entirely on a higher-level component to control the "checked" state.
j
Can confirm changing it to null is the answer
a
Yes exactly what I want, thanks man!
m
I have a similar question to this, but my child composable is
Chip
which takes a non-null
onClick
arg. I have a
FlowRow
of
Chip
s and I only want the
FlowRow
to be clickable.
o
You could set your
Chip
to be
enabled = false
. But be aware, that it will change how chip is displayed. Maybe you will want to adjust chip disabled colors with
Copy code
colors = ChipDefaults.chipColors(
    disabledBackgroundColor = ...,
    disabledContentColor = ...,
)
m
When I do that, I don’t get any click events on the
FlowRow
o
Hmm, weird. You are using
.clickable
modifier on the FlowRow?
m
combinedClickable
passing in non-null
onClick
and
onLongClick
I suppose I could just stick a
Box
over the
Chip
and handle it that way, but I suspect there’s a proper way to do this
1143 Views