I’m working on a Jetpack Compose UI in my Android application and I’m encountering an issue with a vertically scrollable component. Here’s the code I’m using
@OptIn(ExperimentalFoundationApi::class)
@Composable
fun TabWithDetails(
modifier: Modifier = Modifier,
pagerState: PagerState,
scrollEnabled: Boolean = false,
pagerData: List<PagerData>
) {
val coroutineScope = rememberCoroutineScope()
Column(
modifier = Modifier
.fillMaxHeight()
.verticalScroll(rememberScrollState())
) {
LazyRow {
itemsIndexed(pagerData) { index, item ->
AddTab(
title = item.title, onClick = {
coroutineScope.launch {
pagerState.scrollToPage(index)
}
}, selected = pagerState.currentPage == index
)
}
}
HorizontalPager(state = pagerState, userScrollEnabled = scrollEnabled) { index ->
pagerData[index].content()
}
}
}
I tried replacing Column with LazyColumn and removed Modifier.verticalScroll(), but it didn’t solve the issue. Any help would be greatly appreciated.
Also, I have tried using the solution mentioned here: https://proandroiddev.com/nested-scroll-with-jetpack-compose-9c3b054d2e12
But it was also not working.
Crash Log:
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.ScrollingLayoutNode.measure-3p2s80s(Scroll.kt:385)
at androidx.compose.ui.node.LayoutModifierNodeCoordinator.measure-BRTryo0(LayoutModifierNodeCoordinator.kt:116)