Skip to content
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

Merged
merged 5 commits into from
Nov 21, 2024

Conversation

trambui09
Copy link
Contributor

Add in the predictive back snippets for NavHost implementation and the Predictive Back Handler for a navigation drawer

Copy link

snippet-bot bot commented Nov 7, 2024

Here is the summary of changes.

You are about to add 3 region tags.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@ashnohe
Copy link

ashnohe commented Nov 20, 2024

@googlebot hello

@trambui09 trambui09 merged commit f4e4987 into main Nov 21, 2024
4 checks passed
@trambui09 trambui09 deleted the trambui/predictive-back branch November 21, 2024 21:28
Copy link
Contributor

@dturner dturner left a 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",
Copy link
Contributor

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

Copy link
Contributor Author

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") {
Copy link
Contributor

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") {
Copy link
Contributor

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
Copy link
Contributor

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

Copy link
Contributor Author

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(
Copy link
Contributor

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.

Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants