<@UHAJKUSTU> is there a way to perform something w...
# decompose
v
@Arkadii Ivanov is there a way to perform something when the predictive back nav is cancelled ? I have achieved it like this, it works, but is it correct ? Code in thread
Copy code
actual fun <C : Any, T : Any> backAnimation(
    backHandler: BackHandler,
    onBack: () -> Unit,
    onCancel: () -> Unit
): StackAnimation<C, T> = predictiveBackAnimation(
    backHandler = backHandler,
    fallbackAnimation = stackAnimation(slide()),
    onBack = onBack,
    selector = { initialBackEvent, _, _ ->
        androidPredictiveBackAnimatable(initialBackEvent).let {
            AndroidPredictiveBackAnimation(it, onCancel)
        }
    },
)

@OptIn(ExperimentalDecomposeApi::class)
class AndroidPredictiveBackAnimation(
    private val animatable: PredictiveBackAnimatable,
    private val onCancel: () -> Unit
) : PredictiveBackAnimatable by animatable {

    override suspend fun cancel() {
        animatable.cancel()
        onCancel()
    }
}
a
Yes, this should work.