I want an enabled switch to consume the click events and a disabled switch to pass the click event to its parent Composable.
Why does a disabled Switch
consume click events?
A minified example of the issue,
@Composable
fun DisabledSwitch() {
Row(
modifier = Modifier
.fillMaxWidth()
.clickable {}
.padding(16.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween,
) {
Text("Disabled Switch")
Switch(
checked = false,
enabled = false,
onCheckedChange = {
// This cannot be null
// as I need to handle click events when the switch is enabled
},
)
}
}
Clicking on the Text
triggers the Text
clickable, but clicking on the disabled Switch
does not trigger the Text
clickable (parent composable click handler).