From b7e73ee880449ade8d6162b56654083887fe669b Mon Sep 17 00:00:00 2001 From: Jean-Luc Makiola Date: Sun, 27 Sep 2026 12:11:10 +0200 Subject: [PATCH] Spring back a cancelled back preview even though its job is cancelled --- .../kotlin/de/jeanlucmakiola/floret/identity/Motion.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/identity/src/main/kotlin/de/jeanlucmakiola/floret/identity/Motion.kt b/identity/src/main/kotlin/de/jeanlucmakiola/floret/identity/Motion.kt index 1cc3721..b91a0a7 100644 --- a/identity/src/main/kotlin/de/jeanlucmakiola/floret/identity/Motion.kt +++ b/identity/src/main/kotlin/de/jeanlucmakiola/floret/identity/Motion.kt @@ -25,7 +25,9 @@ import androidx.compose.ui.graphics.graphicsLayer import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.unit.IntSize import androidx.compose.ui.unit.dp +import kotlinx.coroutines.NonCancellable import kotlinx.coroutines.delay +import kotlinx.coroutines.withContext import kotlin.coroutines.cancellation.CancellationException /** @@ -117,8 +119,10 @@ fun Modifier.predictiveBack( repeat(2) { withFrameNanos { } } if (currentVisible == true) progress.animateTo(0f) } - } catch (_: CancellationException) { - progress.animateTo(0f) + } catch (e: CancellationException) { + // A cancelled gesture also cancels this job, so the spring-back must not be. + withContext(NonCancellable) { progress.animateTo(0f) } + throw e } }