0

如果其他人也搜索过,只是想分享这段代码。当想用鼠标滚动时很有用,例如用 vysor。

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
    )
}
4

0 回答 0