Made some more progress on SharkApp, sharing here ...
# compose-desktop
p
Made some more progress on SharkApp, sharing here if anyone’s looking for sample code that does some of these things: https://twitter.com/Piwai/status/1349070351108435968
jetpack compose 1
👍🏼 9
👍 1
🎉 6
c
That grid is custom? Nothing in compose that would do that already? Could of sworn I read something like this being built in.
p
It’s possible that I’d have missed it ! Yes it’s custom, here: https://github.com/pyricau/SharkApp/blob/main/src/main/kotlin/shark/GridLayout.kt I wanted all items to use a predefined width, but also use the height of the tallest item (ie all have the same size) so that the spacing is even everywhere. The other thing being a dynamic number of columns and rows based on how many cards fit in width.
c
That's interesting, I always figured you'd need to set a pre-determinded height. E.g. if you're building a carousel, it's basically impossible to do it if all the cards in the carousel are different heights. But looking at all the card heights in advance seems like an impossible task.
p
The trick here was to have a predefined item width. Then in the layout pass, before the actual measure, I can ask for the min height for each child, given the predefined item width. Here I did just that and kept the max item height as the height for all items
Copy code
val itemHeightPx = measurables.maxOf { it.minIntrinsicHeight(itemWidthPx) }
Then I tell the children to measure themselves to exact size:
Copy code
val childConstraints = Constraints.fixed(itemWidthPx, itemHeightPx)
    val placeables = measurables.map { measurable ->
      measurable.measure(childConstraints)
    }
c
Gotcha. Very cool and will definitely be helpful. Will try to take a look later tonight to see if there was possibly some built in layout that would give you that behavior.