From 2696705a4b8d934442302c325e8e333cd57ed29b Mon Sep 17 00:00:00 2001 From: Jonas Kalderstam Date: Wed, 18 Dec 2024 21:35:33 +0100 Subject: [PATCH] fixed crash when a table was empty Signed-off-by: Jonas Kalderstam --- .../feeder/ui/compose/layouts/Table.kt | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/nononsenseapps/feeder/ui/compose/layouts/Table.kt b/app/src/main/java/com/nononsenseapps/feeder/ui/compose/layouts/Table.kt index 02eb324173..37ee572622 100644 --- a/app/src/main/java/com/nononsenseapps/feeder/ui/compose/layouts/Table.kt +++ b/app/src/main/java/com/nononsenseapps/feeder/ui/compose/layouts/Table.kt @@ -180,6 +180,22 @@ private fun TableCaptionPreview() { } } +@Preview +@Composable +private fun EmptyTableShouldNotCrashPreview() { + Surface { + Text("No table to show") + Table(tableData = TableData(0, 0)) { _, _ -> + Box( + modifier = + Modifier + .size(25.dp) + .background(Color.Gray), + ) + } + } +} + @Suppress("DataClassPrivateConstructor") data class TableData private constructor( val cells: List, @@ -206,8 +222,8 @@ data class TableData private constructor( } } - val rows: Int = cells.maxOf { it.row + it.rowSpan } - val columns: Int = cells.maxOf { it.column + it.colSpan } + val rows: Int = if (cells.isEmpty()) 0 else cells.maxOf { it.row + it.rowSpan } + val columns: Int = if (cells.isEmpty()) 0 else cells.maxOf { it.column + it.colSpan } companion object { /**