Status Update
Comments
po...@google.com <po...@google.com>
ap...@google.com <ap...@google.com> #2
Branch: androidx-main
commit f47b8cb1150e74b96db8c3d54c77d2db04d53197
Author: Matvei Malkov <malkov@google.com>
Date: Tue Jun 15 13:51:28 2021
Do not propogate clicks down when Modifier.clickable(enabled=false). Same for toggleable and selectable.
Right now clickable(enabled=false) behaves like there's no clickable at all. This is not correct, as the disabled meaning is not the meaning of absence. We need to consume clicks and don't propogate it up the hierarchy, e.g. Card that cointans disabled button shoudln't be clickable when user touches button. This will be also on par with Android views behaviour.
Fixes: 183908811
Relnote: Disabled Button, Card, Checkboxes and overall Modifier.clickable(enabled=false) will blocks clicks from going up to the parent.
Test: added new
Change-Id: Ic2c3b17121c3ab4676a995c4a83d15bac6c16aaa
M compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/ClickableTest.kt
M compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/SelectableTest.kt
M compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/ToggleableTest.kt
M compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/Clickable.kt
M compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/selection/Toggleable.kt
ma...@google.com <ma...@google.com> #3
Thanks a lot for filing this issue. It was a serious misconception in Modifier.clickable and its users that we were able to fix before hitting stable thanks to you!
[Deleted User] <[Deleted User]> #4
ma...@google.com <ma...@google.com> #5
Could you share a usecase when it is desirable to proxy click action to the parent card/box?
If the button is disabled - it's unavailable and nothing should happen when the user presses it.
[Deleted User] <[Deleted User]> #6
I have a custom layout. When it in the collapsed state - the parent should be clickable. Click on parrent should expand children. In this state children are clickable. Click on child item opens new screen, click on knob collapses the layout.
In previeous realization i had for children:
MoodCardStack(
date = date,
state = state,
itemPadding = Dimens.standard,
modifier = Modifier.padding(vertical = Dimens.small)
) {
if (moods[date]?.size == 1 && state.expanded) {
state.collapse()
}
moods[date]?.forEach { mood ->
key(mood) {
MoodCardItem(
userMood = mood,
modifier = Modifier
.fillMaxWidth()
.height(90.dp)
.clickable(
enabled = state.expanded || moods[date]?.size == 1,
indication = null,
interactionSource = remember { MutableInteractionSource() }
) {
onMoodClick(mood.id)
}
)
}
}
}
and for parent
Layout(
content = content,
modifier = Modifier
.clickable(
enabled = state.expanded.not() && collapseProgress.value == 0F,
indication = null,
interactionSource = remember { MutableInteractionSource() }
) { state.expand() }
.constrainAs(container) {
top.linkTo(parent.top)
start.linkTo(dateColumn.end, margin = Dimens.small)
end.linkTo(parent.end, margin = Dimens.standard)
width = Dimension.fillToConstraints
}
) { measurables, constraints ->
```
Now if MoodCardItem .clickable(false), the whole layout is not clickable. I had to dynamically create different modifiers with and without clickables. And this realization looks weird when the previous was more obvious.
ma...@google.com <ma...@google.com> #7
It seems like the card shouldn't be clickable at all when the layout is collapsed.
disabled clickable shouldn't allow other click gestures to go through, as it would be unpredictable for users and developers. Basically, the list goes:
Modifier.clickable(enabled = true)
== I can react to the click gestures and the action is available nowModifier.clickable(enabled = false)
== I can react to the click gestures, and the action is currently unavailable- no clickable modifier == I cannot react to the click gestures, so anyone else up the hierarchy can handle it for me.
I hope that helps.
Description
Jetpack Compose release version: 1.4.30 Android Studio Build: Android Studio Arctic Fox | 2020.3.1 Canary 12
Steps to Reproduce:
The button click does not work, but I don't know if it is correct to propagate to the lower box. If it is an existing ViewGroup, it will not be propagated to the lower part.