I'm using the Horologist sample to use wear navigation compose with the pager to switch pages but this does not work correctly.
Tolriq
06/20/2024, 5:48 PM
The horologist code is
Copy code
public fun getPageParam(backStack: NavBackStackEntry, remove: Boolean = false): Int? {
val pageNumber = backStack.arguments?.getInt(page, -1) ?: -1
if (remove) {
backStack.arguments?.remove(page)
}
return if (pageNumber < 0) null else pageNumber
}
But since the arguments are always copied and immutable you actually can't remove the parameter.
Tolriq
06/20/2024, 5:50 PM
This maybe more a question for @Ian Lake, but as anyone have an idea about how I can ensure that if I navigate down then back the page param is not returned again to avoid unwanted page change.
Arguments should be a key part of the identity of the destination , not something you use to pass events, so there's probably a different way to approach this problem in general
Ian Lake
06/20/2024, 11:27 PM
Note that the SavedStateHandle, which is started with the same fields as the arguments, is mutable, so maybe that's a better place to do this logic without changing everything
t
Tolriq
06/21/2024, 5:17 AM
Thanks for the details, I'm new to Jetpack navigation hence why I followed the Horologist approach. For direct navigation I can easily workaround. But for deep links since we can't build a stack I can't think of a way.