fix(alarms): bring a card home when its swipe is disabled mid-gesture

A card whose alarm starts ringing during a drag or the throw-away
animation slides back instead of staying displaced, and the delete is
re-checked after the animation, so it cannot land on a ringing alarm.
This commit is contained in:
makiolaj committed 2026-10-22 07:44:28 +02:00
1 parent af12b7bb34
commit 62da327771
2 files changed
+15 -2

No files matched your search

@@ -14,6 +14,7 @@ import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
@@ -65,6 +66,7 @@ internal fun SwipeToDelete(
content: @Composable () -> Unit,
) {
val currentOnDelete by rememberUpdatedState(onDelete)
val currentEnabled by rememberUpdatedState(enabled)
val scope = rememberCoroutineScope()
val haptics = LocalHapticFeedback.current
val settleSpec = MaterialTheme.motionScheme.defaultSpatialSpec<Float>()
@@ -78,6 +80,12 @@ internal fun SwipeToDelete(
// Derived, so a drag recomposes this once as the red appears, not per frame.
val revealed by remember { derivedStateOf { travel.value > 0f } }
// Disabled mid-drag or mid-settle: the gesture that would have brought the
// card home is gone, so it comes home on its own.
LaunchedEffect(enabled) {
if (!enabled) travel.animateTo(0f, settleSpec)
}
Box(
modifier = modifier
.onSizeChanged { width = it.width }
@@ -130,7 +138,9 @@ internal fun SwipeToDelete(
scope.launch {
if (width > 0 && delete) {
travel.animateTo(width.toFloat(), settleSpec)
currentOnDelete()
// Re-read after the animation: the card may have been
// disabled meanwhile (its alarm started ringing).
if (currentEnabled) currentOnDelete()
// Normally the row has left the list long before this.
// If it is still here (the delete found nothing, or an
// Undo brought the same item back), it slides home
+4 -1
View File
@@ -1742,7 +1742,10 @@ alarm is the exception: deleting it was a dismissal in all but name, so it comes
back as a dismissal would have left it (cycle closed, a one-shot switched off)
and never rings again, and a ringing transient alarm, which that dismissal would
have deleted anyway, offers no Undo at all. A snooze that lapsed while the alarm
was gone is closed by the resolver on restore, and gets no notification.
was gone is closed by the resolver on restore, and gets no notification. An
alarm deleted just before its time and restored just after it rings at once,
since the occurrence is still inside the fire grace window: Undo means "as if it
had not been deleted", and that alarm would have rung.
The pending deletion lives in `AlarmUndo`, a singleton, not in either
ViewModel. The editor is popped the moment its alarm is gone, so its ViewModel