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
Ian Lake
04/23/2021, 2:29 PM
Why are you using multiple NavHostControllers at all?
m
MaxUt
04/23/2021, 2:39 PM
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
Ian Lake
04/23/2021, 2:44 PM
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
Ian Lake
04/23/2021, 2:45 PM
Do you mean you're trying to have multiple separate back stacks for, say, different bottom nav items?
m
MaxUt
04/23/2021, 2:49 PM
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