Spring back a cancelled back preview even though its job is cancelled
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user