'LazyColumn that respects MotionEvent.ACTION_SCROLL

How to force compose' LazyColumn to act like traditional scrollable elements like RecyclerView or ListView?

Useful when want to scroll with mouse, e.g. with vysor.



Solution 1:[1]

The solution is to add filter to modifier

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ThinkDeep