https://kotlinlang.org logo
#compose
Title
# compose
s

Stylianos Gakis

03/08/2023, 4:07 PM
Is there no grid-like layout which also lets you define the spacings between the items laid out in the grid? LazyVerticalGrid doesn’t seem to provide any such configuration.
s

Stylianos Gakis

03/08/2023, 4:12 PM
Aha! Gotta use the spacings, it did not cross my mind, thanks a lot! With that said, a side-question, there’s only a lazy grid there, now I want to show like 8 items, which means having it be lazy is a waste, there isn’t any such configuration I suppose right?
c

Chris Sinco [G]

03/08/2023, 6:13 PM
Not at the moment, but I don’t know if it’s a huge waste. I think it matters more if you find that the lazy composition is not ideal versus composition of all 8 at the same time
s

Stylianos Gakis

03/09/2023, 1:12 AM
Actually a more important thing here. I am in this case where I can a simple column which you can scroll but usually is at most 1.5x the screen’s height. Inside it, I want one of the items to be a grid-like layout. I used LazyVerticalGrid and I obviously get the crash of having a scrollable in a scrollable item. This would also be fixed with a simple grid layout which is not lazy and does not force scrolling. For now I will fallback to a custom simple Layout() which lays out the items in this grid pattern unfortunately 🤷‍♂️ And wrapping the entire thing in this grid layout (as suggested here) but giving it full-span for the non-grid items isn’t really smth I wanna do, as the grid is a small part of the screen, not the emphasis, plus I’d then need to be careful of what span I give to all the other items, especially if I go with adaptive GridCells instead of with a fixed number.
c

Chris Sinco [G]

03/09/2023, 1:38 AM
True, though the lazy loading is helpful in the future when you need it
a

Albert Chang

03/09/2023, 1:59 AM
I’d then need to be careful of what span I give to all the other items
Just a reminder that you can use
span = { GridItemSpan(maxLineSpan) }
so that you don't need to pass the actual number.
s

Stylianos Gakis

03/09/2023, 7:29 AM
Another issue with this. This grid with usually 8 thin items (56.dp height each, therefore usually takes up only 224 dp height + paddings so making it scrollable really isn’t important) is somewhat part of the design system, meaning that I’ll be reusing it in a bunch of screens, so I’ve extracted it in a function in a module. If this were to be used only there I’d have to make this an extension on
LazyGridItemScope
and then wherever I might need to add it would need to convert entire screens to also be lazy grids. I really feel like it would be very justified for this layout to exist in a non-lazy form. It’s like saying that Column could also not exist and one could simply use the lazy version instead. A non lazy, non automatically scrolling version of the grid layout imo really has its place in compose foundation. But with all that said, thanks a lot for helping me through this, for now I’ll simply go with a Layout which I’ll try not to mess up and will keep an eye out on if this layout is ever going to exist for compose.
c

Chris Sinco [G]

03/09/2023, 3:33 PM
I think this could exist at some point, but given the non-lazy nature, it’s likely not the highest priority given one can make this relatively quickly with rows/columns or like your custom layout
4 Views