尊重 MotionEvent.ACTION_SCROLL 的 LazyColumn

LazyColumn that respects MotionEvent.ACTION_SCROLL

如何强制 compose' LazyColumn 像 RecyclerView 或 ListView 等传统可滚动元素一样工作?

当想用鼠标滚动时很有用,例如带遮阳板。

解决办法是给修饰符加filter

const val VERTICAL_SCROLL_MULTIPLIER = -4

// Helps with scrolling with mouse wheel (just like recycler view/list view without compose)
@ExperimentalComposeUiApi
@Composable
fun MyLazyColumn(
    modifier: Modifier = Modifier,
    state: LazyListState, // rememberLazyListState()
    content: LazyListScope.() -> Unit
) {
    LazyColumn(
        state = state,
        modifier = modifier
            .pointerInteropFilter {
                if (it.action == MotionEvent.ACTION_SCROLL) {
                    state.dispatchRawDelta(it.getAxisValue(MotionEvent.AXIS_VSCROLL) * VERTICAL_SCROLL_MULTIPLIER)
                }
                false
            },
        content = content
    )
}