4

I have a Column(modifier = Modifier.verticalScroll(mainScrollState)) and I want to use LazyColumn inside Column WITHOUT specifying height of LazyColumn explicitly.

Now it gives me java.lang.IllegalStateException: Vertically scrollable component was measured with an infinity maximum height constraints, which is disallowed.

I tried using NestedScrollConnection but it didn't give me right solution. Any workarounds?

My whole composable looks like:

Scaffold() {
    Column() {
       Column() { 
          LazyColumn { ... }
       }
       Column() { ... }
    }
}
Sosiskin
  • 45
  • 1
  • 5
  • Depending on how many elements you have above the LazyColumn, you could actually list them as elements at the start of the LazyColumn. – eimmer Jun 08 '22 at 13:47
  • Does this answer your question? [What is the equivalent of \[NestedScrollView + RecyclerView\] or \[Nested RecyclerView (Recycler inside another recycler) in Jetpack compose](https://stackoverflow.com/questions/66908737/what-is-the-equivalent-of-nestedscrollview-recyclerview-or-nested-recyclerv) – nglauber Jun 08 '22 at 14:03
  • Unfortunately, no I've seen these answers, but those variants do not apply to my case. – Sosiskin Jun 08 '22 at 14:16
  • 2
    Check this out: https://youtu.be/1ANt65eoNhQ?t=896 – nglauber Jun 08 '22 at 14:23
  • I think this is the easiest and most correct answer :D Thanks! – Sosiskin Jun 08 '22 at 14:29

1 Answers1

0

I use this workaround

Column(
    modifier = Modifier
        .fillMaxWidth()
        .verticalScroll(rememberScrollState())
) {
    LazyColumn(
        modifier = Modifier.heightIn(2000.dp) // set the maximum height possible in your case
    ) {
        // your content
    }
}

You may use heightIn(), so compose will know the exact height of element. This works like wrapContentHeight, but there is a maximum height allowed

I think it's more suitable for small number of items, though

Ivan
  • 21
  • 3