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

Kshitij Patil

12/06/2020, 8:39 PM
I'm getting this error when I moved a composable to separate fragment This Composable is being rendered inside a
FragmentContainerView
hosted inside a LinearLayout but sadly I need to use that LinearLayout in the xml
, what can be done to make this work?
Copy code
java.lang.IllegalStateException: Nesting scrollable in the same direction layouts like ScrollableContainer and LazyColumnFor 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().
        at androidx.compose.foundation.ScrollKt.assertNotNestingScrollableContainers-k00exg4(Scroll.kt:464)
        at androidx.compose.foundation.lazy.LazyListState.measure-5vC3nwU$foundation_release(LazyListState.kt:248)
        at androidx.compose.foundation.lazy.LazyListKt$LazyList$1.invoke(LazyList.kt:62)
        at androidx.compose.foundation.lazy.LazyListKt$LazyList$1.invoke(LazyList.kt)
        at androidx.compose.ui.layout.SubcomposeLayoutState$createMeasureBlocks$1.measure-8A2P9vY(SubcomposeLayout.kt:211)
        at androidx.compose.ui.node.InnerPlaceable.performMeasure-BRTryo0(InnerPlaceable.kt:47)
        at androidx.compose.ui.node.LayoutNodeWrapper.measure-BRTryo0(LayoutNodeWrapper.kt:124)
        at androidx.compose.foundation.layout.PaddingModifier.measure-za8Wrwc(LayoutPadding.kt:210)
        at androidx.compose.ui.node.ModifiedLayoutNode.performMeasure-BRTryo0(ModifiedLayoutNode.kt:36)
        at androidx.compose.ui.node.LayoutNodeWrapper.measure-BRTryo0(LayoutNodeWrapper.kt:124)
        at androidx.compose.ui.node.DelegatingLayoutNodeWrapper.performMeasure-BRTryo0(DelegatingLayoutNodeWrapper.kt:105)
        at androidx.compose.ui.node.LayerWrapper.performMeasure-BRTryo0(LayerWrapper.kt:67)
        at androidx.compose.ui.node.LayoutNodeWrapper.measure-BRTryo0(LayoutNodeWrapper.kt:124)
        at androidx.compose.ui.node.DelegatingLayoutNodeWrapper.performMeasure-BRTryo0(DelegatingLayoutNodeWrapper.kt:105)
        at androidx.compose.ui.node.LayoutNodeWrapper.measure-BRTryo0(LayoutNodeWrapper.kt:124)
        at androidx.compose.ui.node.DelegatingLayoutNodeWrapper.performMeasure-BRTryo0(DelegatingLayoutNodeWrapper.kt:105)
        at androidx.compose.ui.node.LayoutNodeWrapper.measure-BRTryo0(LayoutNodeWrapper.kt:124)
        at androidx.compose.ui.node.DelegatingLayoutNodeWrapper.performMeasure-BRTryo0(DelegatingLayoutNodeWrapper.kt:105)
        at androidx.compose.ui.node.LayoutNodeWrapper.measure-BRTryo0(LayoutNodeWrapper.kt:124)
        at androidx.compose.ui.node.OuterMeasurablePlaceable$remeasure$2.invoke(OuterMeasurablePlaceable.kt:91)
        at androidx.compose.ui.node.OuterMeasurablePlaceable$remeasure$2.invoke(OuterMeasurablePlaceable.kt)
        at androidx.compose.runtime.snapshots.SnapshotStateObserver.observeReads(SnapshotStateObserver.kt:133)
        at androidx.compose.ui.platform.AndroidComposeView.observeMeasureModelReads(AndroidComposeView.kt:482)
        at androidx.compose.ui.node.OuterMeasurablePlaceable.remeasure-BRTryo0(OuterMeasurablePlaceable.kt:90)
        at androidx.compose.ui.node.OuterMeasurablePlaceable.measure-BRTryo0(OuterMeasurablePlaceable.kt:63)
        at androidx.compose.ui.node.LayoutNode.measure-BRTryo0(LayoutNode.kt:1232)
        at androidx.compose.ui.layout.RootMeasureBlocks.measure-8A2P9vY(RootMeasureBlocks.kt:36)
        at androidx.compose.ui.node.InnerPlaceable.performMeasure-BRTryo0(InnerPlaceable.kt:47)
        at androidx.compose.ui.node.LayoutNodeWrapper.measure-BRTryo0(LayoutNodeWrapper.kt:124)
        at androidx.compose.ui.node.DelegatingLayoutNodeWrapper.performMeasure-BRTryo0(DelegatingLayoutNodeWrapper.kt:105)
        at androidx.compose.ui.node.LayoutNodeWrapper.measure-BRTryo0(LayoutNodeWrapper.kt:124)
        at androidx.compose.ui.node.DelegatingLayoutNodeWrapper.performMeasure-BRTryo0(DelegatingLayoutNodeWrapper.kt:105)
        at androidx.compose.ui.node.LayoutNodeWrapper.measure-BRTryo0(LayoutNodeWrapper.kt:124)
        at androidx.compose.ui.node.DelegatingLayoutNodeWrapper.performMeasure-BRTryo0(DelegatingLayoutNodeWrapper.kt:105)
        at androidx.compose.ui.node.LayoutNodeWrapper.measure-BRTryo0(LayoutNodeWrapper.kt:124)
        at androidx.compose.ui.node.DelegatingLayoutNodeWrapper.performMeasure-BRTryo0(DelegatingLayoutNodeWrapper.kt:105)
        at androidx.compose.ui.node.LayoutNodeWrapper.measure-BRTryo0(LayoutNodeWrapper.kt:124)
        at androi
I learned that I was using 
LazyColumn
 inside a 
Column
 and rectified my mistake but this error seems to continue showing regardless of any change.
c

Colton Idle

12/06/2020, 8:48 PM
I had your same error like 2 days ago when I was trying to build a like... a list within a list? i thought compose would just be able to handle it, but it wasn't. The error message kind of points you in the right direction here even though it took a while for the message to make sense to me. Basically if you need a list within a list, or just a bunch of different things in a single list, you can do
Copy code
LazyColumn{
item{ HeaderComposeable() }
items(myitems){
MyListItemComposable(it)
}

item{ AnotherHeader() }
items(anotherList){
AnotherComposable(it)
}
}
idk if that helps at all, but this doc helped me understand the idea behind the dsl https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/package-summary#top-level-functions
Also the source has these ListDemos which were also helpful
k

Kshitij Patil

12/06/2020, 8:51 PM
Agreed. But it seems like it's complaining about parent
LinearLayout
itself in which this Composable is getting rendered
It turns out Simple LinearLayout is not considered as a scrollable container but Linear Layout with weighted children is a scrollable container and thus it prevents us from using LazyColumn in such scenarios
🤯 1
3 Views