Hi everyone. I was wondering if anyone has created...
# compose-android
b
Hi everyone. I was wondering if anyone has created (or knows how to create) what I call a "Spreadsheet View" in Compose. Basically it's a grid (bonus points for a lazy grid) that can be scrolled horizontally and vertically, and it has a header row that is sticky when scrolled vertically, as well as a header column that is sticky when scrolled horizontally. In my case it's ok for all grid cells to be a fixed width and height. I built this in the old view system a long time ago. It was a HUGE pain. I basically had to create 3 RecyclerViews (one for the header row, one for the header column, and one for the grid of data) and keep their scroll positions in sync. For the grid of data, I had to create a custom RecylerView.LayoutManager. Like I said, a HUGE pain. Below is a video of it working in the old view system. I'm not sure how I could achieve this with Compose? I asked this question a year or two ago, and got several "can't do it currently" answers. Wondering if that is still the case...
w
If you want a very simple non-lazy solution, Compose 1.9's 2D scrollable Modifier is probably enough for this. If you want something lazy/more complex, I ended up making a table view for my side project, although the code is pretty terrible: https://github.com/TheKeeperOfPie/ArtistAlleyDatabase/blob/master/modules%2Falley%2Fsrc%2FcommonMain%2Fkotlin%2Fcom%2Fthekeeperofpie%2Fartistalleydatabase%2Falley%2Fui%2FTwoWayGrid.kt I'm basically using the multi-list trick with synced scroll states. It's pretty janky and focusability causes the horizontal scroll to jump. I'm sure there's a solution but I actually built this for desktop usage so I'm not concerned with addressing it. I actually do have a separate 2D grid with true LazyLayout for my map feature, but that's even less optimized.
b
Interesting. I'll take a look at the 2D scrollable modifier. In my case, the grid won't ever be all that big, so lazy rendering isn't really a requirement, just a nice-to-have.
w
The main benefit of using the 2D modifier or a real lazy layout is that you'd get diagonal scrolling. Mine only scrolls in one direction at a time.
screen-20250814-162547.mp4
e
the androidx.compose.foundation.lazy.layout.LazyLayout docs have an example on building a lazy 1D grid from scratch. 2D is possible with LazyLayout, "just" a more state and layout to manage
I have not used it but searching google I found https://github.com/oleksandrbalan/lazytable which builds upon that
j
Have you had a look at Minabox! https://github.com/oleksandrbalan/minabox
❤️ 1