Smorg
03/22/2021, 8:58 AMLazyVerticalGrid
in a Column
in a ComposeView
that’s a child of a NestedScrollView
and I am getting this:
java.lang.IllegalStateException: Nesting scrollable in the same direction layouts like ScrollableContainer and LazyColumn is not allowed.
...
I have seen a couple of this in here as well, but can’t find any that matches the state of my layout. Please how can I fix this?Albert Chang
03/22/2021, 10:10 AMComposeView
or the LazyVerticalGrid
as a workaround. If you cannot, there's no way to fix it.Smorg
03/22/2021, 11:02 AMColton Idle
03/22/2021, 4:52 PMAndrey Kulikov
03/22/2021, 5:28 PMColton Idle
03/22/2021, 5:36 PMTimo Drick
03/22/2021, 7:03 PMinline fun <T> LazyListScope.gridItems(
columns: Int,
gridPadding: Dp = 0.dp,
contentPadding: PaddingValues = PaddingValues(),
items: List<T>,
crossinline itemContent: @Composable LazyItemScope.(item: T) -> Unit
) {
val chunkedItems = items.chunked(columns)
itemsIndexed(chunkedItems) { index, rowList ->
val layoutDirection = LocalLayoutDirection.current
val topPadding = if (index > 0) gridPadding else contentPadding.calculateTopPadding()
val startPadding = contentPadding.calculateLeftPadding(layoutDirection)
val endPadding = contentPadding.calculateEndPadding(layoutDirection)
val bottomPadding = contentPadding.calculateBottomPadding()
Row(Modifier.padding(top = topPadding, start = startPadding, bottom = bottomPadding, end = endPadding)) {
val rowModifier = Modifier.weight(1f)
rowList.forEachIndexed { index, item ->
if (index > 0) Spacer(Modifier.width(gridPadding))
Box(rowModifier) {
itemContent(item)
}
}
val emptyRows = (columns - rowList.size)
repeat(emptyRows) { // fill empty cells
Spacer(Modifier.width(gridPadding))
Spacer(modifier = rowModifier)
}
}
}
}
Timo Drick
03/22/2021, 7:07 PMSmorg
03/22/2021, 8:33 PMLazyVerticalGrid
(LazyColumn in your case) in a view-system NestedScrollView.
I get the explanation @Colton Idle and @Andrey Kulikov made though, and it seems the best solution is to have a fixed height somewhere.Smorg
03/22/2021, 8:37 PMLazyVerticalGrid
btw, and my expectation is that it would become scrollable, but that doesn’t seem to be the case.Timo Drick
03/23/2021, 12:59 AMTimo Drick
03/23/2021, 1:00 AMTimo Drick
03/23/2021, 1:01 AMTimo Drick
03/23/2021, 1:02 AM