Skip to content

Add snippets for Wear Navigation 3#904

Draft
ithinkihaveacat wants to merge 1 commit intoandroid:mainfrom
ithinkihaveacat:wear-nav3-snippets
Draft

Add snippets for Wear Navigation 3#904
ithinkihaveacat wants to merge 1 commit intoandroid:mainfrom
ithinkihaveacat:wear-nav3-snippets

Conversation

@ithinkihaveacat
Copy link
Copy Markdown
Contributor

No description provided.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces Wear OS Navigation3 support by updating project dependencies and adding a sample implementation. The changes include defining serializable destinations and setting up a NavDisplay with a swipe-to-dismiss strategy. Feedback focuses on ensuring the rememberSwipeDismissableSceneStrategy correctly handles back navigation via an onDismiss lambda and recommending the use of a SaveableStateHolder decorator to preserve UI state across transitions.

@Composable
fun WearAppWithViewModel() {
val backStack = rememberNavBackStack(Screen.Home)
val strategy = rememberSwipeDismissableSceneStrategy<NavKey>()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The rememberSwipeDismissableSceneStrategy function requires an onDismiss lambda to handle the back navigation when a swipe gesture is completed. Without this, the swipe-to-dismiss gesture will not update the back stack.

Suggested change
val strategy = rememberSwipeDismissableSceneStrategy<NavKey>()
val strategy = rememberSwipeDismissableSceneStrategy<NavKey> {
backStack.removeLast()
}

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.

1 participant