Barrufet
Barrufet

Reputation: 683

Scroll screen until list reaches top

So how do I scroll the screen with a lazy column on the inside? I just tried to test it setting a verticalScroll(remember..) in the parent box that holds the lazy column and many other composables but I got this error:

java.lang.IllegalStateException: Nesting scrollable in the same direction layouts like LazyColumn and Column(Modifier.verticalScroll()) is not allowed.

If you want to add a header before the list of items please take a look on LazyColumn component which has a DSL api which allows to first add a header via item() function and then the list of items via items().

So I want to scroll this screen to the point the 2 boxes disappear and lazy column stays at top. And if there are items then stay at top while scrolling. (But never disappear of the screen. Just like it's using its height)

enter image description here

Upvotes: 0

Views: 739

Answers (1)

Phil Dukhov
Phil Dukhov

Reputation: 87854

You can place your boxes into LazyColumn too, like this:

LazyColumn {
    item {
        Box {
            Text("Box 1")
        }
    }
    item {
        Box {
            Text("Box 2")
        }
    }
    items(dataItems) { dataItem ->
        // ..
    }
}

Upvotes: 2

Related Questions