Working drawer.
This commit is contained in:
parent
5f9996b2a7
commit
cd11e57a11
2 changed files with 18 additions and 6 deletions
|
@ -6,11 +6,12 @@ import androidx.navigation.compose.NavHost
|
||||||
import androidx.navigation.compose.composable
|
import androidx.navigation.compose.composable
|
||||||
import com.bbc.denadrive.home.DetailsScreen
|
import com.bbc.denadrive.home.DetailsScreen
|
||||||
import com.bbc.denadrive.home.HomeScreen
|
import com.bbc.denadrive.home.HomeScreen
|
||||||
|
import com.bbc.denadrive.home.ScaffoldWithSidebar
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun NavigationGraph(navController: NavHostController) {
|
fun NavigationGraph(navController: NavHostController) {
|
||||||
// Create a NavHost that defines the navigation graph
|
// Create a NavHost that defines the navigation graph
|
||||||
NavHost(navController = navController, startDestination = "home") {
|
NavHost(navController = navController, startDestination = "prova") {
|
||||||
// Define the home screen destination
|
// Define the home screen destination
|
||||||
composable("home") { HomeScreen(navController) }
|
composable("home") { HomeScreen(navController) }
|
||||||
|
|
||||||
|
@ -21,5 +22,7 @@ fun NavigationGraph(navController: NavHostController) {
|
||||||
// Pass the argument to the DetailsScreen
|
// Pass the argument to the DetailsScreen
|
||||||
DetailsScreen(itemId, navController)
|
DetailsScreen(itemId, navController)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
composable("prova") { ScaffoldWithSidebar() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.bbc.denadrive.home
|
package com.bbc.denadrive.home
|
||||||
|
|
||||||
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.material3.Button
|
import androidx.compose.material3.Button
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
@ -27,6 +28,8 @@ import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
//import androidx.compose.material3.icons.Icons
|
//import androidx.compose.material3.icons.Icons
|
||||||
//import androidx.compose.material3.icons.filled.Menu
|
//import androidx.compose.material3.icons.filled.Menu
|
||||||
//import androidx.compose.material3.icons.filled.MoreVert
|
//import androidx.compose.material3.icons.filled.MoreVert
|
||||||
|
@ -48,17 +51,19 @@ fun DetailsScreen(itemId: String?, navController: NavHostController) {
|
||||||
@Composable
|
@Composable
|
||||||
fun ScaffoldWithSidebar() {
|
fun ScaffoldWithSidebar() {
|
||||||
// State to control the drawer
|
// State to control the drawer
|
||||||
var isDrawerOpen by remember { mutableStateOf(false) }
|
val drawerState = rememberDrawerState(initialValue = DrawerValue.Closed)
|
||||||
|
val scope = rememberCoroutineScope()
|
||||||
|
|
||||||
// ModalNavigationDrawer
|
// ModalNavigationDrawer
|
||||||
ModalNavigationDrawer(
|
ModalNavigationDrawer(
|
||||||
drawerState = rememberDrawerState(initialValue = DrawerValue.Closed),
|
drawerState = drawerState,
|
||||||
drawerContent = {
|
drawerContent = {
|
||||||
// Drawer content
|
// Drawer content
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxSize()
|
.fillMaxHeight()
|
||||||
.padding(16.dp)
|
.fillMaxWidth(0.67f)
|
||||||
|
.background(Color.Red)
|
||||||
) {
|
) {
|
||||||
Text("Item 1", modifier = Modifier.clickable { /* Handle click */ })
|
Text("Item 1", modifier = Modifier.clickable { /* Handle click */ })
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
|
@ -74,7 +79,11 @@ fun ScaffoldWithSidebar() {
|
||||||
TopAppBar(
|
TopAppBar(
|
||||||
title = { Text("My App") },
|
title = { Text("My App") },
|
||||||
navigationIcon = {
|
navigationIcon = {
|
||||||
IconButton(onClick = { isDrawerOpen = true }) {
|
IconButton(onClick = {
|
||||||
|
scope.launch {
|
||||||
|
drawerState.open()
|
||||||
|
}
|
||||||
|
}) {
|
||||||
// Icon for the menu (three horizontal lines)
|
// Icon for the menu (three horizontal lines)
|
||||||
Icon(Icons.Filled.Menu, contentDescription = "Menu")
|
Icon(Icons.Filled.Menu, contentDescription = "Menu")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue