我有这样的场景,Lazycolumn 的顶部部分有一些水平滚动的项目,底部部分有多个功能项目(也是水平滚动的)。两个部分将同步水平滚动(如果任何功能项展开)。 我已经根据给定的建议完成了一些 poc 两个延迟滚动 面临的问题是,当滚动任何水平行时,第一次单击按钮不可单击,但下一次单击却可以正常工作。 请建议。
val pos = remember() {
mutableIntStateOf(0)
}
val scope = rememberCoroutineScope()
val productScroll = rememberLazyListState()
val featureScroll = rememberLazyListState()
LazyColumn() {
stickyHeader {
LazyRow(modifier = Modifier.wrapContentSize(), state = productScroll) {
println("SCROLLLL 1")
items(20) { index ->
Column(
modifier = Modifier
.size(100.dp)
.background(color = Color.Green)
) {
Text("item ", color = Color.Red)
Text("$index")
}
}
}
}
itemsIndexed(dataList.value?: emptyList(),
) { index, item ->
HeaderSection(item.header, item.isScroll, onHeaderClick = {
pos.intValue=index
})
if (pos.intValue==index) {
SectionBody(item, featureScroll)
}
}
}
LaunchedEffect(key1 = featureScroll.firstVisibleItemScrollOffset) {
scope.launch {
productScroll.scrollToItem(
featureScroll.firstVisibleItemIndex,
featureScroll.firstVisibleItemScrollOffset
)
}
}
LaunchedEffect(key1 = productScroll.firstVisibleItemScrollOffset) {
scope.launch {
featureScroll.scrollToItem(
productScroll.firstVisibleItemIndex,
productScroll.firstVisibleItemScrollOffset
)
}
}
上述问题陈述存在与使用两个 Launcheffect 相关的问题,这两个 Launcheffect 在彼此滚动之间创建循环,这就是屏幕不可点击的原因。我添加了一些条件来中断循环,例如(!productScroll.isScrollInProgress))。这解决了问题。