Skip to content

Commit c79a414

Browse files
authored
update to use type safe routes (#399)
1 parent 0d07b08 commit c79a414

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ import androidx.navigation.compose.composable
4646
import androidx.navigation.compose.rememberNavController
4747
import kotlin.coroutines.cancellation.CancellationException
4848
import kotlinx.coroutines.flow.Flow
49+
import kotlinx.serialization.Serializable
50+
51+
@Serializable data object Home
52+
@Serializable data object Settings
4953

5054
@Composable
5155
private fun PredictiveBackOverrideExit(
@@ -56,7 +60,7 @@ private fun PredictiveBackOverrideExit(
5660
// [START android_compose_predictiveback_navhost]
5761
NavHost(
5862
navController = navController,
59-
startDestination = "home",
63+
startDestination = Home,
6064
popExitTransition = {
6165
scaleOut(
6266
targetScale = 0.9f,
@@ -70,13 +74,13 @@ private fun PredictiveBackOverrideExit(
7074
)
7175
// [END android_compose_predictiveback_navhost]
7276
{
73-
composable("home") {
77+
composable<Home> {
7478
HomeScreen(
7579
modifier = modifier,
7680
navController = navController,
7781
)
7882
}
79-
composable("settings") {
83+
composable<Settings> {
8084
SettingsScreen(
8185
modifier = modifier,
8286
navController = navController,
@@ -119,6 +123,7 @@ private fun PredictiveBackHandlerBasicExample() {
119123
boxScale = 1F - (1F * backEvent.progress)
120124
}
121125
// code for completion
126+
boxScale = 0F
122127
} catch (e: CancellationException) {
123128
// code for cancellation
124129
boxScale = 1F

0 commit comments

Comments
 (0)