Skip to content

Commit

Permalink
Fix: Number of columns can't be zero
Browse files Browse the repository at this point in the history
  • Loading branch information
sevonj committed Nov 14, 2024
1 parent b14fd2a commit 1735cc6
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.unit.LayoutDirection
import androidx.compose.ui.unit.dp
import kotlin.math.max
import kotlin.math.roundToInt

data class ResponsiveGridData(val columnsCount: Int)

@Composable
fun ResponsiveGrid(tileSize: Float = 200f, content: LazyGridScope.(ResponsiveGridData) -> Unit) {
BoxWithConstraints(modifier = Modifier.fillMaxSize()) {
val cols = (this@BoxWithConstraints.maxWidth.value / tileSize).roundToInt()
val cols = max((this@BoxWithConstraints.maxWidth.value / tileSize).roundToInt(), 1)
val gridState = rememberLazyGridState()
val responsiveGridData = ResponsiveGridData(columnsCount = cols)

Expand Down

0 comments on commit 1735cc6

Please sign in to comment.