https://kotlinlang.org logo
#compose-wear
Title
# compose-wear
l

Lisandro Di Meo

05/05/2022, 1:39 PM
Hello ! I'm building a wear os app using compose, and using
SwipeDismissableNavHost
I've found that the swiping gesture is ignoring the
BackHandler
inside the composable. For example, if my nav graph is: A -> B -> C, and the swipe from C should redirect to A. I think I have to custom some behavior of the SwipeToDismissBox, but I'm not sure how. Any help is appreciated!
Copy code
composable(
    Paths.WORD,
    arguments = listOf(navArgument("language") { defaultValue = "EN" })
){ navBackStackEntry ->
    BackHandler() { navController.navigate(Paths.HOME) }
    CompleteWord(navController, listState, completeWordViewModel, navBackStackEntry.arguments?.getString("language")!!.toLanguage())
}
Slack Conversation
j

John Nichol

05/05/2022, 3:05 PM
@Steve Bower [G]
s

Steve Bower [G]

05/05/2022, 3:16 PM
Hi Lisandro - I'll have a look at this, but at first sight I would expect a) SwipeDismissableNavHost to always pop the navigation back stack when you swipe to dismiss b) the back button (e.g. on the emulator) to trigger the BackHandler you've configured.
l

Lisandro Di Meo

05/05/2022, 3:30 PM
b is happening correctly
But now you mention, I think I should change the backstack when going to this path in order to change swipedismissablenavhost to pop the navigation where i expect
s

Steve Bower [G]

05/05/2022, 3:40 PM
Yes, you could pop the backstack on the way to C so that swiping back takes you to A. That's nice, because it means you can configure different behaviour according to how you get to C (e.g. for A -> D -> C you might still want to swipe back to D).
🙌 1
Also, the NavController defaults its back button handler to popping the back stack - so changing the backstack on that path means everything is consistent and there's no need to configure a BackHandler.
l

Lisandro Di Meo

05/05/2022, 4:31 PM
Great! Thank you for helping 😄 I'll try that and let you know 🙌 🙌
11 Views