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

henrikhorbovyi

01/25/2022, 12:48 AM
Hello, everyone 🙂 What's the best way to implement a nested scroll screen on Compose? My hierarchy is:
Copy code
MyScreen:
    Column():
        Text("Nice Title")
        LazyVerticalGrid:
            items(n) { MyItem() }
2
t

Timo Drick

01/25/2022, 12:56 AM
Maybe you could specify you question a little bit more in detail. Just guessing what you want: Write
Copy code
MyScreen:
    Column():
        Text("Nice Title")
        LazyVerticalGrid(modifier = Modifier.weight(1f)):
            items(n) { MyItem() }
This will give the Grid the rest of available space on the screen inside of the Column.
If you want that the text also scrolls i think this is currently not really possible with this LazyVerticalGrid Maybe better usind LazyColumn and than creating the grid on your own.
h

henrikhorbovyi

01/25/2022, 1:37 AM
Actually, I wanted to achieve the following behavior:
And I did it using a header item
👍 1
But I was wondering if there was a better way
t

Timo Drick

01/25/2022, 10:37 AM
Nested scrolling can be used if you want e.g. that the header appears when you scroll up a little bit. Than you could put the header outside of the LazyGrid and do some nested scroll logic to handle scroll events that happen inside of the LazyGrid.
👍 1
h

henrikhorbovyi

01/25/2022, 4:50 PM
I tried to read about this nestedscroll docs before, but I found too much boilerplate compared with my screenshot above resulting the same behavior
But I'll give it a try
4 Views