问题 - 向下滚动会导致底部工作表滚动而不是将滚动优先级赋予 LazyColumn(RecyclerView 没有这个问题。它被 NestedScrollView 包裹)
我刚刚在 CoordinatorLayout 中引入了一个 Compose LazyColumn 替换 Recycler。Coordinator(作为底部工作表实现)本身可以在查看和展开状态之间自由滚动。我的问题是在 LazyColumn 中向下拖动项目区域时,底部工作表会拾取滚动而不是 LazyColumn 。如果我在 LazyColumn 上先向上然后向下滚动(不释放),则滚动由 LazyColumn 拾取,滚动优先级赋予 LazyColumn(预期行为。)
BottomSheetFragment
|-CoordinatorLayout
|--ConstraintLayout (BottomSheetBehavior)
|---MyListFragment
|----ComposeView
|-----Theme
|------Surface
|-------Box
|--------LazyColumn
Compose 新手,所以我希望有人能告诉我如何纠正这种新的滚动行为?
**编辑 我正在通过切换协调器的 ^^ BottomSheetBehavior.isDragglable 来完成这项工作,但它确实需要我释放拖动而不是从列表滚动平滑过渡到底部工作表滚动 - 任何人都建议修复?:
fun MyUi(listener:Listener) {
val listState = rememberLazyListState()
LaunchedEffect(listState) {
listState.interactionSource.interactions.collect {
//at the top of the list so allow sheet scrolling
listener.allowSheetDrag(listState.firstVisibleItemScrollOffset == 0)
}
}
val nestedScrollConnection = remember {
object : NestedScrollConnection {
override fun onPreScroll(available: Offset, source: NestedScrollSource): Offset {
Timber.i("NestedScrollConnection onPreScroll($available: Offset, $source: NestedScrollSource)")
return super.onPreScroll(available, source)
}
override fun onPostScroll(consumed: Offset, available: Offset, source: NestedScrollSource): Offset {
Timber.i("NestedScrollConnection onPostScroll($consumed: Offset, $available: Offset, $source: NestedScrollSource)")
if (available.y > 0.0 && consumed.y == 0.0f) {
//scolling down up but we're already at the top - kick over to sheet scrolling
listener.allowSheetDrag(true)
}
return super.onPostScroll(consumed, available, source)
}
}
}
Box(
modifier = Modifier
.fillMaxSize()
.nestedScroll(nestedScrollConnection)
) {
LazyColumn(
modifier =
Modifier
.fillMaxSize()
.padding(vertical = 12.dp), state = listState
) {
item {
Row() {}
}
}
}
}
然后在片段中:
override fun allowSheetDrag(allowSheetDrag: Boolean) {
bottomSheetFragment?.bottomSheetBehavior?.isDraggable = allowSheetDrag
}