-
Notifications
You must be signed in to change notification settings - Fork 180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add in predictive back snippets for NavHost and predictive back handler #394
Conversation
Here is the summary of changes. You are about to add 3 region tags.
This comment is generated by snippet-bot.
|
@googlebot hello |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I wasn't able to review before merging. Added a few comments and suggestions.
// [START android_compose_predictiveback_navhost] | ||
NavHost( | ||
navController = navController, | ||
startDestination = "home", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should use type safe routes. To do this declare:
@Serializable data object Home
@Serializable data object Settings
before the function.
Then to use it do startDestination = Home
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahhh, thanks for the tip of changing them to safe routes, Don!
) | ||
// [END android_compose_predictiveback_navhost] | ||
{ | ||
composable("home") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
composable<Home>
navController = navController, | ||
) | ||
} | ||
composable("settings") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
composable<Settings>
// code for progress | ||
boxScale = 1F - (1F * backEvent.progress) | ||
} | ||
// code for completion |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this have a completion state? From the looks of it, it should be boxScale = 0F
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, it should have a completion state. Added it into the #399 PR.
val navController = rememberNavController() | ||
|
||
// [START android_compose_predictiveback_navhost] | ||
NavHost( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure of the context in which this is being used but I think it's important to mention that NavHost
supports predictive back out of the box. There's nothing extra required, aside from defining the animations you want to use between destinations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we do mention NavHost supports PB out of the box. This snippets shows a custom in-app animations example for PB
Add in the predictive back snippets for NavHost implementation and the Predictive Back Handler for a navigation drawer