is there a built in way to do measuring like lazy ...
# compose
m
is there a built in way to do measuring like lazy grid with
GridCells.Adaptive
does it? or I have to write logic myself?
a
what are you trying to achieve?
m
this (
GridCells.Adaptive
) documentation:
Copy code
/**
 * Defines a grid with as many rows or columns as possible on the condition that
 * every cell has at least [minSize] space and all extra space distributed evenly.
 *
 * For example, for the vertical [LazyVerticalGrid] Adaptive(20.dp) would mean that
 * there will be as many columns as possible and every column will be at least 20.dp
 * and all the columns will have equal width. If the screen is 88.dp wide then
 * there will be 4 columns 22.dp each.
 */
did it. copy pasted some of the actual
GridCells.Adaptive
code and that’s it
Copy code
private fun BoxWithConstraintsScope.calculateItemSize(
  density: Density,
  contentPadding: PaddingValues,
  arrangement: Arrangement.HorizontalOrVertical,
  minItemSize: Dp,
): Dp {
  with(density) {
    val horizontalPadding =
      contentPadding.calculateStartPadding(LayoutDirection.Ltr) +
        contentPadding.calculateEndPadding(LayoutDirection.Ltr)
    val spacing = arrangement.spacing.roundToPx()
    val rowWidth = constraints.maxWidth - horizontalPadding.roundToPx()
    val count = maxOf((rowWidth + spacing) / (minItemSize.roundToPx() + spacing), 1)
    val gridSizeWithoutSpacing = rowWidth - spacing * (count - 1)
    return (gridSizeWithoutSpacing / count).toDp()
  }
}
this is much better to be custom lazy layout but this also works