Consider following Composable.
Box(
modifier = Modifier
.size(100.dp)
.background(Color.Blue)
.clickable {
// parent click listener
Timber.d("parent click")
}
) {
Box(
modifier = Modifier
.size(50.dp)
.background(Color.Red)
) {
// children
}
// ...
}
When clicking on the red Box the parent Composable consumes the click event even though the red box is in front of it.
This looks like a weird default behavior. Different from the View system.
However when the red Box has a click listener of its own the behavior is correct and the red Box click listener is triggered.
Box(
modifier = Modifier
.size(100.dp)
.background(Color.Blue)
.clickable {
// parent click listener
Timber.d("parent click")
}
) {
Box(
modifier = Modifier
.size(50.dp)
.background(Color.Red)
.clickable() {
Timber.d("Prevent parent clicks")
}
) {
// children
}
// ...
}
Is there a better way to let the red Box consume the event without putting an explicit clickable modifier on it?
