First implementation of LazyColumn.
This commit is contained in:
parent
75dfa46ae8
commit
e8e34f3d58
3 changed files with 32 additions and 13 deletions
1
.idea/gradle.xml
generated
1
.idea/gradle.xml
generated
|
@ -1,5 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="GradleMigrationSettings" migrationVersion="1" />
|
||||
<component name="GradleSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
|
|
|
@ -7,6 +7,8 @@ import androidx.navigation.compose.composable
|
|||
import com.bbc.denadrive.home.DetailsScreen
|
||||
import com.bbc.denadrive.home.HomeScreen
|
||||
import com.bbc.denadrive.home.ScaffoldWithSidebar
|
||||
import androidx.compose.material3.Text
|
||||
import com.bbc.denadrive.home.MyListVisualizer
|
||||
|
||||
@Composable
|
||||
fun NavigationGraph(navController: NavHostController) {
|
||||
|
@ -23,6 +25,6 @@ fun NavigationGraph(navController: NavHostController) {
|
|||
DetailsScreen(itemId, navController)
|
||||
}
|
||||
|
||||
composable("prova") { ScaffoldWithSidebar() }
|
||||
composable("prova") { ScaffoldWithSidebar { lista -> MyListVisualizer(lista) } }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ import androidx.navigation.NavHostController
|
|||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.gestures.detectTapGestures
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Menu
|
||||
import androidx.compose.material.icons.filled.MoreVert
|
||||
|
@ -33,6 +34,7 @@ import androidx.compose.ui.input.pointer.pointerInput
|
|||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import kotlinx.coroutines.launch
|
||||
import androidx.compose.foundation.lazy.items
|
||||
|
||||
//import androidx.compose.material3.icons.Icons
|
||||
//import androidx.compose.material3.icons.filled.Menu
|
||||
|
@ -53,11 +55,15 @@ fun DetailsScreen(itemId: String?, navController: NavHostController) {
|
|||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun ScaffoldWithSidebar() {
|
||||
fun ScaffoldWithSidebar(
|
||||
toBeDisplayed: @Composable (List<String>) -> Unit
|
||||
) {
|
||||
// State to control the drawer
|
||||
val drawerState = rememberDrawerState(initialValue = DrawerValue.Closed)
|
||||
val scope = rememberCoroutineScope()
|
||||
|
||||
val lista = listOf<String>("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",)
|
||||
|
||||
// ModalNavigationDrawer
|
||||
ModalNavigationDrawer(
|
||||
drawerState = drawerState,
|
||||
|
@ -70,9 +76,9 @@ fun ScaffoldWithSidebar() {
|
|||
.background(Color.White)
|
||||
) {
|
||||
RectangularButton(backgroundColor = Color.White, text = "Text 1") { }
|
||||
Spacer(modifier = Modifier.height(10.dp))
|
||||
// Spacer(modifier = Modifier.height(10.dp))
|
||||
RectangularButton(backgroundColor = Color.White, text = "Text 2") { }
|
||||
Spacer(modifier = Modifier.height(10.dp))
|
||||
// Spacer(modifier = Modifier.height(10.dp))
|
||||
RectangularButton(backgroundColor = Color.White, text = "Text 3") { }
|
||||
}
|
||||
},
|
||||
|
@ -108,7 +114,8 @@ fun ScaffoldWithSidebar() {
|
|||
.padding(16.dp),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Text("Main Content", fontSize = 24.sp)
|
||||
toBeDisplayed(lista)
|
||||
// Text("Main Content", fontSize = 24.sp)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
@ -127,7 +134,6 @@ fun RectangularButton(
|
|||
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.padding(8.dp)
|
||||
.fillMaxWidth()
|
||||
.height(48.dp) // Set the height of the button
|
||||
.background(color = backgroundColor) // Set the background color
|
||||
|
@ -143,7 +149,8 @@ fun RectangularButton(
|
|||
},
|
||||
onTap = { onClick() } // Call the onClick action
|
||||
)
|
||||
},
|
||||
}
|
||||
.padding(8.dp),
|
||||
contentAlignment = Alignment.Center // Center the text
|
||||
) {
|
||||
Text(text = text, style = MaterialTheme.typography.bodyLarge) // Button text
|
||||
|
@ -151,14 +158,23 @@ fun RectangularButton(
|
|||
}
|
||||
|
||||
@Composable
|
||||
fun MyApp() {
|
||||
ScaffoldWithSidebar()
|
||||
fun MyListVisualizer (
|
||||
lista: List<String>
|
||||
) {
|
||||
LazyColumn {
|
||||
items(lista) { messaggio -> Text(text=messaggio, fontSize = 30.sp) }
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun MainActivityContent() {
|
||||
MyApp()
|
||||
}
|
||||
//@Composable
|
||||
//fun MyApp() {
|
||||
// ScaffoldWithSidebar()
|
||||
//}
|
||||
|
||||
//@Composable
|
||||
//fun MainActivityContent() {
|
||||
// MyApp()
|
||||
//}
|
||||
|
||||
|
||||
//@OptIn(ExperimentalMaterial3Api::class)
|
||||
|
|
Loading…
Add table
Reference in a new issue