hey! I’m playing with BottomNavigation and Jetpack...
# compose
n
hey! I’m playing with BottomNavigation and Jetpack Navigation and I did an sample based on @Afzal Najam post ( thanks man🙏 https://afzaln.com/multiple-navigation-graphs-with-jetpack-compose-navigation/) Here’s my code: https://gist.github.com/nglauber/5061cbbafd63488131380b09c8943ad7 I have two questions: 1. When the second tab is selected and displaying its root content, is there a way to display the first tab when the user presses the system back key? 2. Could someone point out where can I find a way to save the
LazyColumn
scroll position? In my sample, the first tab is a list.
ok. I fixed #2 hoisting
rememberLazyListState()
a
I think if you want to display the first tab with the back button, you might want to put both tabs in a single nav graph. The second tab wouldn't need its own nav graph in this use case, right?
n
I tried the approach presented in documentation sample… but when I use a single nav graph and reselect the first tab, I missed the first tab back stack. Only the root composable of the first tab is displayed.
Another idea I had was: set a
NavHost
as a child of
Scaffold
, and the
NavHost
has two other `NavHost`’s inside of it (one for each tab)… But didn’t work 😕
k
May listen to back button click and do your logic manually
n
@Karthick I guess this should the simpler way to deal with this specific case… But I’m wondering why
NavHost
is not working with nested `NavHost`s… 🤔
k
I had similar requirement and I implemented self navigation for the fragment hosting the
BottomNavigation
as launching the same fragment will ultimately start with First Tab but you'll lose all the navgraph states with this approach
n
yeah… I’m having this same result @Kshitij Patil 😕 Basically, to summarize, I want to simulate the same navigation approach used by YouTube.
y
Two navigation graphs can solve the issue #1 https://github.com/egorikftp/BelarusResistanceFlag
👍 1
n
I did that 😉 thanks @Yahor