Skip to content

Commit

Permalink
fixed crash when a table was empty
Browse files Browse the repository at this point in the history
Signed-off-by: Jonas Kalderstam <[email protected]>
  • Loading branch information
spacecowboy committed Dec 18, 2024
1 parent 32cb38f commit 2696705
Showing 1 changed file with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<TableCell>,
Expand All @@ -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 {
/**
Expand Down

0 comments on commit 2696705

Please sign in to comment.