Hi there, I'm struggling to figure out how to make...
# compose
m
Hi there, I'm struggling to figure out how to make a mutable
NavHostController
. I have several NavHostController so I can navigate through sub-pages and would like to send an event to the root Composable so I get the current NavHostController. The idea behind is to use it in a topBar so I can pop element off the stack and go back to the previous view. Do you guys have any experience with that ?
i
Why are you using multiple NavHostControllers at all?
m
To deal with sub-pages. I need to store the navigation state of all the sub-pages of the app so the user can backtrack. I'm not entirely sure this is the right way to do it 😅 If you have a better solution I'm all in. Regarding my issue, I want to keep topBar and bottomBar at the highest level so they wrap the content. The children composables would then update the global navController with theirs if they have subpages. The idea was to perform a navController.popBackStack() when a certain action is done in the topBar.
i
I think you'll need to expand on what exactly you're trying to do. A single NavHostController does save the state of each destination on its back stack already
Do you mean you're trying to have multiple separate back stacks for, say, different bottom nav items?
m
Exactly, I need a stack per page containing sub-pages. When clicking on the bottom nav items, I need to be exactly on the sub-page I left and also be able to go back its own stack
i
It sounds like you should read the thread from two days ago about this exact case: https://kotlinlang.slack.com/archives/CJLTWPH7S/p1619027732314100?thread_ts=1619027732.314100&cid=CJLTWPH7S
m
Awesome, thank you so much.