I'm trying to embed a horizontally scrollable table within a Composable. However whenever I engage horizontalScrolling the container goes 'blank', as shown. Also figured out that the container or LazyColumn itself has to have a .size to constrain the viewable width, is this normal?
Is it something to do with the column weights? As shown the column is either incorrectly squashed or haywire.
LazyColumn(
Modifier
.padding(5.dp)
.size(400.dp)
// this makes things go blank
.horizontalScroll(rememberScrollState())
) {
item {
Row(
Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceEvenly
) {
TableCell(
text = "Invoice",
weight = column1Weight,
alignment = TextAlign.Center,
title = true
)
TableCell(text = "Date", weight = column2Weight, title = true)
TableCell(text = "Status", weight = column3Weight, title = true)
TableCell(text = "Status", weight = column4Weight, title = true)
TableCell(text = "Status", weight = column5Weight, title = true)
TableCell(text = "Status", weight = column6Weight, title = true)
}
Divider(
color = Color.LightGray,
modifier = Modifier
.height(1.dp)
.fillMaxHeight()
.fillMaxWidth()
)
}
itemsIndexed(invoiceList) { _, invoice ->
Row(
Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween
) {
TableCell(
text = invoice.invoice,
weight = column1Weight,
alignment = TextAlign.Center
)
TableCell(text = invoice.date, weight = column2Weight, alignment = TextAlign.Center)
TableCell(text = invoice.status, weight = column3Weight)
TableCell(
text = invoice.amount,
weight = column4Weight,
alignment = TextAlign.Center
)
TableCell(text = invoice.filler, weight = column5Weight)
TableCell(text = invoice.killer, weight = column6Weight)
}
Divider(
color = Color.LightGray,
modifier = Modifier
.height(1.dp)
.fillMaxHeight()
.fillMaxWidth()
)
}
}
}
Spacer(modifier = Modifier
.fillMaxWidth()
.size(20.dp))
// second table
}
@Composable
fun RowScope.TableCell(
text: String,
weight: Float,
alignment: TextAlign = TextAlign.Center,
title: Boolean = false
) {
Text(
text = text,
Modifier
.weight(weight)
.padding(10.dp)
,
fontWeight = if (title) FontWeight.Bold else FontWeight.Normal,
textAlign = alignment,
color = Color.White
)
}