'Which one should I choose between Modal drawers and modal navigation drawer in Scaffold when I use Navigation Compose?
I have read the article.
I know there are two ways to implement a modal navigation drawer, one is Modal drawers, and another is modal navigation drawer in Scaffold.
I hope to use Navigation Compose in my project, I found a sample project to learn.
At present, the author of the sample project use Code A to implement a modal navigation drawer.
I don't know if the Code B can do the same work, could you tell me ?
Code A
@Composable
fun TodoNavGraph(
...
) {
NavHost(
...
) {
composable(
TodoDestinations.TASKS_ROUTE,
arguments = listOf(... )
) { entry ->
AppModalDrawer(...) {
TasksScreen(
userMessage = entry.arguments?.getInt(USER_MESSAGE_ARG)!!,
...
)
}
}
composable(TodoDestinations.STATISTICS_ROUTE) {
AppModalDrawer(...) {
StatisticsScreen(...)
}
}
}
}
@Composable
fun AppModalDrawer(
...
) {
ModalDrawer(
drawerState = drawerState,
drawerContent = {
AppDrawer( ...)
}
) {
content()
}
}
@Composable
private fun AppDrawer(...){
...
}
@Composable
fun TasksScreen(
...
) {
Scaffold(
...
) {
...
}
}
Code B
@Composable
fun TodoNavGraph(
...
) {
NavHost(
...
) {
composable(
TodoDestinations.TASKS_ROUTE,
arguments = listOf(... )
) { entry ->
TasksScreen(
userMessage = entry.arguments?.getInt(USER_MESSAGE_ARG)!!,
...,
AppDrawer(...)
)
}
composable(TodoDestinations.STATISTICS_ROUTE) {
StatisticsScreen(..., AppDrawer(...) )
}
}
}
@Composable
fun TasksScreen(
...
AppDrawer: @Composable () -> Unit
) {
Scaffold(
...,
drawerContent = { AppDrawer(...) }
) {
...
}
}
@Composable
private fun AppDrawer(... ){
...
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
