New Compose Multiplatform components arrived on Composables UICheck it out →

Modifier in Compose Ui

mouseScrollFilter

Adding this [modifier][Modifier] to the [modifier][Modifier] parameter of a component will allow it to intercept scroll events from mouse wheel and touchpad.

Last updated:

Installation

dependencies {
   implementation("androidx.compose.ui:ui:1.7.0-beta04")
}

Overloads

@Deprecated(
    "Use Modifier.pointerInput + PointerEventType.Scroll",
    replaceWith = ReplaceWith(
        "pointerInput(Unit) { \n" +
        "     awaitPointerEventScope {\n" +
        "         while (true) {\n" +
        "             val event = awaitPointerEvent()\n" +
        "             if (event.type == PointerEventType.Scroll) {\n" +
        "                 val scrollDelta = event.changes.first().scrollDelta\n" +
        "                 val bounds = this.size\n" +
        "                 if (onMouseScroll(scrollDelta, bounds)) {\n" +
        "                      event.changes.first().consume()\n" +
        "                 }\n" +
        "             }\n" +
        "         }\n" +
        "     }\n" +
        "}",
        "androidx.compose.ui.input.pointer.pointerInput"
    )

fun Modifier.mouseScrollFilter(
    onMouseScroll: (
        /**
         * Mouse wheel or touchpad event.
         */
        event: MouseScrollEvent,

        /**
         * Bounds of the container in which scroll event occurs.
         */
        bounds: IntSize
    ) -> Boolean
)

Parameters

namedescription
onMouseScrollThis callback is invoked when the user interacts with the mouse wheel or touchpad. While implementing this callback, return true to stop propagation of this event. If you return false, the scroll event will be sent to this [mouseScrollFilter]'s parent.