now to get a feel for subcomposeLayout. Seems like subcompose layout lets you build performant layouts. Interesting that they mention boxWIthConstraints is built with subcomposeLayout, because ive heard that you should try not to use boxWithConstraints since it's "heavy"
Colton Idle
07/29/2023, 1:35 AM
seems like this will do. maybe not good perf wise. but it gets the job done.
Copy code
var howManyItemsCanFitLeftToRight by remember { mutableIntStateOf(0) }
BoxWithConstraints(Modifier.fillMaxWidth()) {
howManyItemsCanFitLeftToRight = (this.maxWidth).div((itemSize)).toInt()
}
r
Rick Regan
07/29/2023, 2:09 AM
I use
BoxWithConstraints
in a similar manner. It seems to work well.
BTW, (maxWidth / itemSize).toInt() looks cleaner.
s
shikasd
07/29/2023, 2:24 AM
BoxWithConstraints is heavier, because it creates another subcomposition
It is a tradeoff between creating all items at once and then skipping them in measure vs creating a separate composition for some of items and paying a maintenance cost
c
Colton Idle
07/29/2023, 1:46 PM
Thanks all. So it seems like using BoxWithConstraints is subpar in this scenario. I will keep playing around with SubcomposeLayout to try to get the width, but I feel like im in over my head. lol