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