chanjungskim
12/13/2022, 10:41 PMIan Lake
12/13/2022, 10:51 PMrememberNavController()
inside your screen.Ian Lake
12/13/2022, 10:53 PMAddSupplementItem
passed a lambda to handle click events? You show how to handle navigating correctly at the graph level for your authGraphchanjungskim
12/13/2022, 11:13 PMchanjungskim
12/13/2022, 11:14 PMNavHost(...){
// otherGraphs()
supplementSearchScreen(navController)
}
something like this?
I thought, It will catch it if I create in any Composable function.Ian Lake
12/13/2022, 11:15 PMIan Lake
12/13/2022, 11:16 PMchanjungskim
12/13/2022, 11:16 PMIan Lake
12/13/2022, 11:17 PM• Pass lambdas that should be triggered by the composable to navigate, rather than theitself.NavController
Ian Lake
12/13/2022, 11:23 PMAddSupplementItem
should take a onItemClicked: () -> Unit
lambda, which then gets sent to whatever screen that composable is a part of (you don't show that part), which should also have a lambda parameter, all the way up the chain until it gets to your navigation graph and it is in that graph that you call navController.navigateToSupplementSearch()
or whatever action you wantchanjungskim
12/13/2022, 11:30 PMfun SupplementGrid(vitaminList: List<Vitamin>) {
// list of vitamin item. and also use AddSupplement()
}
And also it has parent composable function
@Composable
fun SupplementLayout(feedType: FeedType, supplements: List<Vitamin>) {
// call SupplementGrid()
}
and finally,
@Composable
fun NutritionScreen(
// it uses LazyColumn and one of item is SupplementLayout()
)
So, should I call the navController.navigateToSupplementSearch()
in the Screen() ?? after passing the onItemClicked: () -> Unit
until AddSupplementItem() ?chanjungskim
12/13/2022, 11:33 PMnavController.navigateToSupplementSearch()
in the NutritionScreen() and it crashes..Ian Lake
12/13/2022, 11:46 PMIan Lake
12/13/2022, 11:46 PMRootNavGraph
shouldn't know anything about NavController
at all. It should be lambdas all the way down so that the leaf node just triggers an event that goes up the hierarchy until you get to the layer that can handle that eventIan Lake
12/13/2022, 11:47 PMIan Lake
12/13/2022, 11:48 PMchanjungskim
12/13/2022, 11:52 PMappBarGraph(
onAddSupplementItem = {
navController.navigateToSupplementSearch()
}
)
like this?
Well, but appBarGraph is just for bottom navigation. And I'd like to separate the graphs and add new routes in the NavHost so that I can navigate all the ways in the app, even different graphs.Ian Lake
12/13/2022, 11:54 PMIan Lake
12/13/2022, 11:55 PMchanjungskim
12/13/2022, 11:56 PMmainGraph(
navigationToHome ={},
navigationToSetting = {},
onAddSupplementItem = {
navController.navigateToSupplementSearch()
},
onRemoveItem = {
},
// other events
)
Is this way correct?Ian Lake
12/13/2022, 11:57 PMchanjungskim
12/14/2022, 12:01 AMchanjungskim
12/14/2022, 12:01 AMIan Lake
12/14/2022, 12:07 AMmainGraph
level, they wouldn't go all the way up to the RootNavGraph
levelIan Lake
12/14/2022, 12:09 AMMainGraphState
object that you pass down as a single parameter, but at that point if you can't figure out what screens link to other screens and conceptualize that into small enough pieces, maybe your users are just as confused about your navigation model 🙃