From 62da327771e9929a2110c3ed71b130061e0808ab Mon Sep 17 00:00:00 2001 From: Jean-Luc Makiola Date: Thu, 22 Oct 2026 07:44:28 +0200 Subject: [PATCH] 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. --- .../clockula/ui/common/SwipeToDelete.kt | 12 +++++++++++- docs/ARCHITECTURE.md | 5 ++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/de/jeanlucmakiola/clockula/ui/common/SwipeToDelete.kt b/app/src/main/java/de/jeanlucmakiola/clockula/ui/common/SwipeToDelete.kt index 9ef68e2..680651a 100644 --- a/app/src/main/java/de/jeanlucmakiola/clockula/ui/common/SwipeToDelete.kt +++ b/app/src/main/java/de/jeanlucmakiola/clockula/ui/common/SwipeToDelete.kt @@ -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() @@ -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 diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index fd46477..33a736d 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -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