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

MBegemot

09/09/2020, 9:34 AM
Honestly there is no much to share simply change Checkbox keyword for Switch....
Copy code
Row(Modifier.padding(5.dp)) {
    Text("Selected")
    //Switch(checked = lselected, onCheckedChange = { lselected = !lselected} )
    Checkbox(checked = lselected, onCheckedChange = { lselected = !lselected} )
    Text("Unselected")
}
y

Yann Badoual

09/09/2020, 9:39 AM
Can you share the declaration of
lselected
too please?
m

matvei

09/09/2020, 11:05 AM
It's a know issue as now Switch invokes
onCheckChange
after initial composition with the same value that you set in the Switch. For what it worth, the more correct handling of the callback would be
onCheckedChange = { lselected = it }
as switch already gives you the hint about to which state it wants to change
If you change it like this -- there will be no oscillation
m

MBegemot

09/09/2020, 11:34 AM
Thank you so much, still both components checkbox and switch should work equally I guess ... some day .. in the future
m

matvei

09/09/2020, 12:20 PM
Could you please clarify what you mean by "equally"? What's the difference between Checkbox and Switch behaviour that you see aside from that bug?
m

MBegemot

09/09/2020, 12:25 PM
Jesus I don't want to argue at all, I'm quite satisfied, and I don't see any difference aside from that bug. I swear it!
😎 1
🤔 6
m

matvei

09/09/2020, 12:42 PM
Sorry if I sounded rude, I didn't mean it. Thanks for your report and if you will find anything unusual or unpredictable about selection controls in the future -- please do let me know 🙂
3 Views