Skip to content

Commit 33c4bc2

Browse files
authored
Fix rethrowing cancellation exceptions (#563)
* Fix missing import * Rethrow cancellation-exceptions
1 parent 80802cb commit 33c4bc2

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

compose/snippets/src/androidTest/java/com/example/compose/snippets/semantics/SemanticsSnippets.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.example.compose.snippets.semantics
1818

19+
import androidx.compose.material3.Text
1920
import androidx.compose.runtime.Composable
2021
import androidx.compose.ui.semantics.Role
2122
import androidx.compose.ui.semantics.SemanticsProperties

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ fun CustomPredictiveBackHandle() {
659659
// For each backEvent that comes in, we manually seekTo the reported back progress
660660
try {
661661
seekableTransitionState.seekTo(backEvent.progress, targetState = Screen.Home)
662-
} catch (e: CancellationException) {
662+
} catch (_: CancellationException) {
663663
// seekTo may be cancelled as expected, if animateTo or subsequent seekTo calls
664664
// before the current seekTo finishes, in this case, we ignore the cancellation.
665665
}
@@ -671,6 +671,7 @@ fun CustomPredictiveBackHandle() {
671671
// When the predictive back gesture is cancelled, we snap to the end state to ensure
672672
// it completes its seeking animation back to the currentState
673673
seekableTransitionState.snapTo(seekableTransitionState.currentState)
674+
throw e
674675
}
675676
}
676677
val coroutineScope = rememberCoroutineScope()

compose/snippets/src/main/java/com/example/compose/snippets/predictiveback/PredictiveBackSnippets.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import androidx.compose.ui.Modifier
3737
import androidx.compose.ui.geometry.Offset
3838
import androidx.compose.ui.graphics.Color
3939
import androidx.compose.ui.graphics.TransformOrigin
40+
import androidx.compose.ui.graphics.graphicsLayer
4041
import androidx.compose.ui.input.pointer.util.VelocityTracker
4142
import androidx.compose.ui.platform.LocalDensity
4243
import androidx.compose.ui.unit.dp
@@ -110,7 +111,10 @@ private fun PredictiveBackHandlerBasicExample() {
110111

111112
Box(
112113
modifier = Modifier
113-
.fillMaxSize(boxScale)
114+
.graphicsLayer {
115+
scaleX = boxScale
116+
scaleY = scaleX
117+
}
114118
.background(Color.Blue)
115119
)
116120

@@ -127,6 +131,7 @@ private fun PredictiveBackHandlerBasicExample() {
127131
} catch (e: CancellationException) {
128132
// code for cancellation
129133
boxScale = 1F
134+
throw e
130135
}
131136
}
132137
// [END android_compose_predictivebackhandler_basic]
@@ -180,8 +185,10 @@ private fun PredictiveBackHandlerManualProgress() {
180185
closeDrawer(velocityTracker.calculateVelocity().x)
181186
} catch (e: CancellationException) {
182187
openDrawer(velocityTracker.calculateVelocity().x)
188+
throw e
189+
} finally {
190+
velocityTracker.resetTracking()
183191
}
184-
velocityTracker.resetTracking()
185192
}
186193
// [END android_compose_predictivebackhandler_manualprogress]
187194
}

0 commit comments

Comments
 (0)