Replies: 2 comments 1 reply
-
I've got something working. I'll leave the code here for your consideration: @Composable
fun WearApp(
) {
MaterialTheme {
Navigator(HomeScreen) { navigator ->
SwipeToDismissBox(
onDismissed = { navigator.pop() },
hasBackground = navigator.size >= 2,
) { isBackground ->
if (isBackground) {
val previousScreen = navigator.items[navigator.size - 2]
navigator.saveableState("currentScreen", previousScreen) {
previousScreen.Content()
}
} else
CurrentScreen()
}
}
}
} The use of Apart from that
Though I'm yet to know if this will make wear device produce |
Beta Was this translation helpful? Give feedback.
-
After fiddling a little with Voyager Navigation, @Composable
fun WearApp(
) {
MaterialTheme {
Navigator(HomeScreen) { navigator ->
SlideTransition(navigator) {
SwipeToDismissBox(
onDismissed = { navigator.pop() },
hasBackground = navigator.size >= 2,
) { isBackground ->
(if (isBackground) navigator.items[navigator.size - 2] else navigator.lastItem).Content()
}
}
}
}
} And it kind of works. Swiping right will nagivate back; screens will enter and exit by Voyager will instantiate a new screen (with a brand new view model) to render the background screen. After completing the "nagivate back" gesture, the previous screen's state is rightfully restored. I'm about to abandon completely the idea of animating navigation in favor of simply animating visibility. |
Beta Was this translation helpful? Give feedback.
-
Voyager Navigator supports back navigation by means of
BackHandler
.Unfortunately, wear devices completely ignore
onBackPressed
[citation needed].The Navigation component for wear ("androidx.wear.compose:compose-navigation") take extra measures for this, for instance in
SwipeDismissableNavHost
(and others likerememberSwipeDismissableNavController
).I can try something specific in my application to glue a
SwipeToDismissBox
and Voyager Navigator, though I don't know yet exactly how or how to even begin with.Have you ever considered supporting wear devices? Any ideas on how to tackle this? What are the obstacles ahead?
Beta Was this translation helpful? Give feedback.
All reactions