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

Brian Donovan

01/05/2022, 5:40 PM
Hey all, I am calling a composable with lazy column inside of another compsable (homescreen) and getting this error. The problem I am running into is that I can’t have a vertical scrollState with a lazy column? What would be this fix?
java.lang.IllegalStateException: Vertically scrollable component was measured with an infinity maximum height constraints, which is disallowed. One of the common reasons is nesting layouts like LazyColumn and Column(Modifier.verticalScroll()). If you want to add a header before the list of items please add a header as a separate item() before the main items() inside the LazyColumn scope. There are could be other reasons for this to happen: your ComposeView was added into a LinearLayout with some weight, you applied Modifier.wrapContentSize(unbounded = true) or wrote a custom layout. Please try to remove the source of infinite constraints in the hierarchy above the scrolling container.
how to put a LazyColumn inside Column(Modifier.verticalScroll())
a

Alex

01/05/2022, 6:08 PM
Used to be the case that nesting these two scrollables was not allowed, albeit the error message was a different one. Maybe this changed with RC01, but in 1.0.5 and up until at least 1.1.0-beta03 nesting a LazyColumn inside of a scrollable container was not allowed.
b

Brian Donovan

01/05/2022, 6:09 PM
so no solution with this?? this sucks!!!
a

Alex

01/05/2022, 6:13 PM
You should rethink how you nest your Composables. If you think Compose sucks because of these little starting issues (compose got out of beta just a few months ago), honestly just go back to xml 👋
b

Brian Donovan

01/05/2022, 6:45 PM
What can I put these in?
I tried a Column but didn’t work
a

Afzal Najam

01/05/2022, 7:04 PM
Put it inside an
item()
block
👍 1
b

Brian Donovan

01/05/2022, 7:16 PM
I added a sticky header but the content scrolls under it. The logo is a svg, do I need to add a background or something?
a

Afzal Najam

01/05/2022, 7:18 PM
do I need to add a background or something
Yup, that would “fix” it.
b

Brian Donovan

01/05/2022, 7:23 PM
I guess that wouldn’t be the right way?
it still shows on top
a

Afzal Najam

01/05/2022, 7:23 PM
What do you mean? A sticky header is supposed to show on top of the content, isn’t it? Do you want it to scroll with the content instead?
b

Brian Donovan

01/05/2022, 7:30 PM
No, I want the logo to stick just like this, but the content to disappear when I scroll to the top instead of the image below
a

Afzal Najam

01/05/2022, 7:32 PM
Adding a background didn’t achieve that? Also, seems to me that you want a TopAppBar basically. You could try Scaffold to have a TopAppBar and then the
LazyColumn
in its content.
b

Brian Donovan

01/05/2022, 7:36 PM
I’ll try that!
At the end of the list, the card doesn’t fully show. Is there something I can do to make sure the last card on the list shows fully?
a

Afzal Najam

01/05/2022, 8:19 PM
contentPadding
argument on
LazyColumn
would solve that.
c

Colton Idle

01/06/2022, 3:24 AM
Or you can put your LazyColumn in a col. Example: Col{ TopAppBar LazyColumn(Modifier.weight(1f)) BottomTabBar } and your content wouldn't draw under the bottomBar
I think a scaffold also has that behavior out of the box
14 Views