Christopher Mederos
06/30/2023, 2:38 AMnavigation-compose
?
In this pattern the navigation graph is defined in a NavHost
composable that directs to other compostables (which are each a top-level screen). Accordingly, I have a view model for each screen. However, I would like to access some view model functions like "save" from the top app bar. The top app bar is defined in a scaffold, so it doesn't have access to the view model that I'm injecting as a parameter in the screen-level composable.
I'm thinking that I should define a custom scope that achieves something similar to koin's built in _by_ koinNavGraphViewModel()
?Mark
07/02/2023, 11:35 AMChristopher Mederos
07/03/2023, 12:14 AMNavBackStackEntry.LocalOwnersProvider
to create a scope in which the NavBackStackEntry serves as the view model store owner. This automatically happens when inside a composable that was reached using the NavHost from navigation-compose. However, you can manually add it when you want to access the BackStackEntry's view model store outside of that particular nav graph destination.
However, doing so essentially breaks the purpose of the back stack lifecycle anyhow, so I've decided it's best not to access the viewmodel store elsewhere. In the case of my TopAppBar example... I moved the bar to a per-screen scaffold instead, and the only use a global scaffold for a bottom app bar with navigation only