Is there a way to add a `LazyColumn` as a child to...
# compose-android
r
Is there a way to add a
LazyColumn
as a child to a
NestedScrollView
in an xml layout? There is already a RecyclerView there working which I want to replace with a compose
LazyColumn
but i'm getting an IllegalStateException. Error message in 🧵
Copy code
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.
                                                                                                    	at androidx.compose.foundation.CheckScrollableContainerConstraintsKt.checkScrollableContainerConstraints-K40F9xA(CheckScrollableContainerConstraints.kt:35)
                                                                                                    	at androidx.compose.foundation.lazy.LazyListKt$rememberLazyListMeasurePolicy$1$1.invoke-0kLqBqw(LazyList.kt:181)
s
remove the
NestedScrollView
. having a
RecyclerView
or
LazyColumn
inside defeats the purpose of using them as all items will need to be layout and there will be no recycling.
a
There’s no point in using NestedScrollView here. If you want nested scroll, just apply
Modifier.nestedScroll(rememberNestedScrollInteropConnection())
to the LazyColumn.
j
Also I think that compose nowadays handle nested scroll automatic, at least within Compose scope. But ah well 😄
a
Compose only automatically handle nested scroll between layouts inside compose or between compose parent and view child inside
AndroidView
.
r
@stojan I can't remove the
NestedScrollView
, I'm only trying to add a few things to a legacy layout without changing it too much.
@Albert Chang The
Modifier.nestedScroll(rememberNestedScrollInteropConnection())
doesn't work either. It still crashes with the same error.
i
A RecyclerView inside a NestedScrollView already wasn't doing any recycling - it was laying out every single item in the list. If you were happy with that behavior already, then you don't need LazyColumn - just use Column
👍 3
a
If your actual code is not the code in the screenshot, please make that clear in your question so that others can better understand what you really want to achieve.
659 Views