nglauber
05/14/2021, 12:26 AMnavController
to all my screens (of course if I want to navigate to somewhere else from that screen)?
Should I create a compositionLocalOf
for it?Abhishek Dewan
05/14/2021, 12:45 AMnglauber
05/14/2021, 12:51 AM@Composable
fun withNavigator(navController: NavController, content: @Composable () -> Unit) {
CompositionLocalProvider(LocalMainNavigator provides navController) {
content()
}
}
and use it like this:
withNavigator(navController) {
WelcomeScreen()
}
nglauber
05/14/2021, 12:54 AMNavHost
with this function, it works think smart
so don’t need to wrap all screens…Francesc
05/14/2021, 1:10 AMIan Lake
05/14/2021, 1:17 AMAbhishek Dewan
05/14/2021, 1:23 AMIan Lake
05/14/2021, 1:31 AMIan Lake
05/14/2021, 1:34 AMAbhishek Dewan
05/14/2021, 1:42 AMnglauber
05/14/2021, 2:03 AMIan Lake
05/14/2021, 2:10 AMnglauber
05/14/2021, 2:13 AMTopAppBar
. Once I’m not passing the navController
to my screens, should I pass a callback to pop current the screen?Francesc
05/14/2021, 2:15 AMnglauber
05/14/2021, 2:17 AMFrancesc
05/14/2021, 2:17 AMIan Lake
05/14/2021, 2:19 AMTopAppBar
is part of each individual screen, then yeah, you'd want to hook the click events there up to a lambda that calls navController.navigateUp()
nglauber
05/14/2021, 2:21 AMIan Lake
05/14/2021, 2:25 AMTopAppBar
? 😝Ian Lake
05/14/2021, 2:28 AMTopAppBar
at a Scaffold
level outside of your NavHost
(that'd be appropriate if ~every screen has the same type of bar - and why the rememberNavController()
pattern exists - to hoist the state out of the NavHost
) or the separate TopAppBar
in each screen (which is better if you need something custom in each)nglauber
05/14/2021, 2:31 AMbryankeltonadams
10/26/2023, 11:15 PM