Spring back a cancelled back preview even though its job is cancelled

This commit is contained in:
2026-09-27 12:11:10 +02:00
parent 1d6b1ed2a9
commit b7e73ee880
@@ -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
}
}