Status Update
Comments
ex...@gmail.com <ex...@gmail.com> #2
I was able to get the switch to stop halfway (in the on state) on a device (see screenshot).
mo...@google.com <mo...@google.com> #4
Louis, can you look at it? I think this is an area that you're familiar with.
lp...@google.com <lp...@google.com> #5
Sounds swipeable related - Matvei have you seen something like this before?
ex...@gmail.com <ex...@gmail.com> #6
(Thanks for pointing to the duplicate; I had searched but did not notice a match based on the description.)
[Deleted User] <[Deleted User]> #7
I noticed the same issue, on androidx.compose.material:material:1.2.0
.
The full code of the button in video device-2022-08-01-123641.mp4
:
val checked2 = remember { mutableStateOf(true) }
Switch(
checked = checked2.value,
onCheckedChange = { checked2.value = it },
)
It's a bit difficult to get into this state, it tooking me 2 mins of clicking like a maniac. 😅
However, switches in our app are wrapped in another composable with Modifier.toggleable
, which makes it more likely to happen, somehow. See the other video, device-2022-08-01-124251.mp4
. It's a bit difficult to share the full code, but the gist of it is:
val checked2 = remember { mutableStateOf(true) }
SwitchCell(
checked = checked2.value,
onCheckedChange = { checked2.value = it },
)
@Composable
fun SwitchCell(
checked: Boolean,
onCheckedChange: ((Boolean) -> Unit),
modifier: Modifier = Modifier,
enabled: Boolean = true,
colors: SwitchCellColors = SwitchCellDefaults.colors(),
) {
Row(
modifier = modifier.toggleable(
value = checked,
onValueChange = { onCheckedChange(it) },
enabled = enabled,
role = Role.Switch
)
) {
Text("Switch Cell")
Switch(
checked = checked,
enabled = enabled,
onCheckedChange = null,
colors = colors.switchColors
)
}
}
jo...@google.com <jo...@google.com> #8
Thank you for sharing. Will try to repro! Agree with George, this is an amazing bug :D
wi...@shiftkey.com <wi...@shiftkey.com> #9
I was able to reproduce easily by clicking the track and then quickly moving the thumb back quickly as shown in the uploaded video.
edit: The video was captured using a real device but sharing screen with my mac and using quicktime to record the interaction.
jo...@google.com <jo...@google.com> #10
#9, which version are you seeing this on?
wi...@shiftkey.com <wi...@shiftkey.com> #11
This is on compose version 1.4.3. Is it fixed in a newer version? If so, I can see if the team will prioritize our compose upgrade schedule.
sh...@google.com <sh...@google.com>
sh...@google.com <sh...@google.com>
ap...@google.com <ap...@google.com> #12
Branch: androidx-main
commit f82b10a7e820d02cc43711db7cc041cefa08e868
Author: Shahd AbuDaghash <shahddaghash@google.com>
Date: Thu Nov 02 15:05:31 2023
Prevent catching the switch while animating on quick clicks
When clicking on the switch twice fast enough, it causes "catching" the switch while it is animating to one side. This is a result of passing `startDragImmediately` as true to Draggable when switch is animating. To prevent this from happening, `startDragImmediately` is exposed for anchoredDraggable and the switch now passes a false boolean to it. This will prevent catching the animating switch by only pressing on it.
Fixes: 215768437
Test: Manual test
Change-Id: Ic3a4893fedfa60261d7eca7c576d9e168a1ee788
M compose/material/material/src/androidInstrumentedTest/kotlin/androidx/compose/material/anchoredDraggable/AnchoredDraggableGestureTest.kt
M compose/material/material/src/commonMain/kotlin/androidx/compose/material/AnchoredDraggable.kt
M compose/material/material/src/commonMain/kotlin/androidx/compose/material/Switch.kt
sh...@google.com <sh...@google.com> #13
The issue has been fixed for the general cases (such as the double click on the switch), and we are currently investigating further improvements.
n....@avm.de <n....@avm.de> #14
Coming from
Code to reproduce:
var isChecked by remember {
mutableStateOf(false)
}
Switch(
checked = isChecked,
onCheckedChange = {
lifecycleScope.launch {
isChecked = !isChecked
delay(40)
isChecked = !isChecked
}
}
)
I've also attached a project which reproduces this bug (tested on emulator and Pixel 8 Pro).
Description
Compose 1.2.0-alpha01, AS Bumblebee RC1, Kotlin 1.6.10
If you click a Jetpack Compose switch in rapid succession (like a double click) it can "swap" the on and off sides (on is left and off is right). You can use this program to reproduce:
The screen recording "FastSwitch.mp4" shows the issue.
Furthermore, when the switch is inside a clickable
Row
(like it might be on a settings screen) and you click in the row outside the switch, you can get the switch to show a partially moved state. You can use this program to reproduce:The screen recording "FastSwitchInClickableRow.mp4" shows the issue.
Both happen on a device and in the emulator (I tried Pixel 4a in both cases), although on a device I was unable to get the switch stuck as much as halfway like in the emulator.