Has anyone tried to manage pages of a <Pager> (or ...
# compose
n
Has anyone tried to manage pages of a Pager (or similar component) as navigation destinations? I'm looking at the bottom sheet navigator PR for inspiration and feel like it could work, but I'm not sure if it's really worth the effort, as opposed to keep this part out of navigation and write ugly glue code.
i
Well, you could write your own NavHostPager that lets you define pages as part of a navigation graph (that's in fact what a lot of Wear OS implementations do - building up a stack of destinations that you can swipe to go back), but no, it wouldn't make any sense to try to write a Navigator for use with NavHost
Generally, your pager isn't something that is entirely app wide - login, a full screen detail view, etc. would all live outside of the pager. This means that the more common pattern is for the Composable hosting your Pager to be just one of many destinations in your graph
n
Our app might be the exception to this rule - some of the top level destinations (say profile, home, settings) are supposed to be navigatable in a pager fashion. I'm finding it hard to deal with this with a single NavController/NavHost as I would like to (especially since only some of the top level destinations will be part of the pager)
i
That sounds...exactly like what I described. Your Home screen destination is a Pager and is just one destination in your app and other non-Pager screens are the other destinations in your graph
n
Maybe I'm missing something but that'd treat 95% of the app content (if you include nested screens) as a single destination? I'll need to have three layers • Root navigation with say login vs. pager • Pager navigation done by finger, no easy nav library / deeplink support (unless I write a NavHostPager) • Inner NavHosts for navigating within each of the pager screens While if there was no pager, I could use one app-wide NavHost with nested graphs 😕 I'm starting to think that it should be possible to write a single NavHost that knows which destinations are in the Pager and which aren't, controlling the UI at two levels. Does this make any sense to you?
i
Generally, the Material guidelines strongly suggest not having tabs with their own back stacks / state. Anything that you navigate to from those pages would be part of that root navigation
Which means your home destination is just the few pages it contains; you'd add deep links to that destination, then manually change pages by looking at the incoming deep link: https://developer.android.com/reference/androidx/navigation/NavController.Companion#KEY_DEEP_LINK_INTENT()