What's the recommended way to navigate from one gr...
# compose
c
What's the recommended way to navigate from one graph, to a non-start-destination on a different graph? (using navigation-compose aka nav2) An example would be clicking on the 'see profile' button on a social media post on a 'feed' tab. That should bring you to a specific screen for that 'profile' on the 'friends' tab. Should we just use the next graph (the friends tab) as the destination and provide a deeplink for the specific profile id for the intended profile screen?
not kotlin but kotlin colored 1
s
Another approach if you don't want to reuse the same destination, is to just have another destination, scoped under the correct graph which you are coming from, and have the implementation simply delegate to exactly the same screen code that exists in that other destination already. This would then mean that you would be under the "correct" hierarchy in case you rely on that for your bottom nav or whatever
d
This is more of a UX question - do you want Feed and Friends to potentially be showing the exact same content when you flick between the two tabs? (i.e. user has navigated to the same Profile on both tabs)
c
just have another destination, scoped under the correct graph
I have done it this way in past - It works well and keeps the hierarchy all on the same tab. From a UX perspective, it can be odd if you've entered the same screen on multiple tabs. I'm curious if there's a way to navigate to a different graph instead. In other words, the destination screen ('friends profile') would only ever appear on the ('friends') tab. If you then flicked between two two tabs - the feed tab would still be on the feed screen at the scroll position of the post that was clicked on, and the friends tab would still be on the profile screen for that ID. Thanks for the input folks
s
What I would do in the two tab scenario is that if you navigate to that destination from "outside" the normal graph, I'd just hide the bottom navigation completely for that screen, so you can't get into this problem. If that's an option for you
In order to do what you say, on the feed item press you could simply do two navigation events back to back. First navigate to the top level graph(and save state) of your details screen and then immediately also navigate to the feed details. That should keep the scroll position, and keep the backstacks proper. Only then pressing back might not do what your users would expect. Would you expect them to be able to go back to that other tab again if they press back?