Skip to content

Commit d7ba5e8

Browse files
committed
Add comments and fix custom seeking predictive back example.
1 parent 3432b15 commit d7ba5e8

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

compose/snippets/src/main/java/com/example/compose/snippets/animations/sharedelement/CustomizeSharedElementsSnippets.kt

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
package com.example.compose.snippets.animations.sharedelement
2020

21+
import android.util.Log
2122
import androidx.activity.compose.PredictiveBackHandler
2223
import androidx.compose.animation.AnimatedContent
2324
import androidx.compose.animation.AnimatedVisibility
@@ -653,19 +654,24 @@ fun CustomPredictiveBackHandle() {
653654

654655
PredictiveBackHandler(seekableTransitionState.currentState is Screen.Details) { progress ->
655656
try {
657+
// Whilst a back gesture is in progress, backEvents will be fired for each progress
658+
// update.
656659
progress.collect { backEvent ->
657-
// code for progress
660+
// For each backEvent that comes in, we manually seekTo the reported back progress
658661
try {
659662
seekableTransitionState.seekTo(backEvent.progress, targetState = Screen.Home)
660663
} catch (e: CancellationException) {
661-
// ignore the cancellation
664+
// seekTo may be cancelled as expected, if animateTo or subsequent seekTo calls
665+
// before the current seekTo finishes, in this case, we ignore the cancellation.
662666
}
663667
}
664-
// code for completion
668+
// Once collection has completed, we are either fully in the target state, or need
669+
// to progress towards the end.
665670
seekableTransitionState.animateTo(seekableTransitionState.targetState)
666671
} catch (e: CancellationException) {
667-
// code for cancellation
668-
seekableTransitionState.animateTo(seekableTransitionState.currentState)
672+
// When the predictive back gesture is cancelled, we snap to the end state to ensure
673+
// it completes its seeking animation back to the currentState
674+
seekableTransitionState.snapTo(seekableTransitionState.currentState)
669675
}
670676
}
671677
val coroutineScope = rememberCoroutineScope()

0 commit comments

Comments
 (0)