Interface

PointerInputModifierNode

A androidx.compose.ui.Modifier.Node that receives PointerInputChanges, interprets them, and consumes the aspects of the changes that it is react to such that other PointerInputModifierNodes don't also react to them.

PointerInputModifierNodeSample

@ExperimentalComposeUiApi
@Sampled
@Composable
fun PointerInputModifierNodeSample() {
    class OnPointerEventNode(var callback: (PointerEvent) -> Unit) :
        PointerInputModifierNode, Modifier.Node() {
        override fun onPointerEvent(
            pointerEvent: PointerEvent,
            pass: PointerEventPass,
            bounds: IntSize,
        ) {
            if (pass == PointerEventPass.Initial) {
                callback(pointerEvent)
            }
        }

        override fun onCancelPointerInput() {
            // Do nothing
        }
    }

    data class PointerInputElement(val callback: (PointerEvent) -> Unit) :
        ModifierNodeElement<OnPointerEventNode>() {
        override fun create() = OnPointerEventNode(callback)

        override fun update(node: OnPointerEventNode) {
            node.callback = callback
        }

        override fun InspectorInfo.inspectableProperties() {
            name = "onPointerEvent"
            properties["callback"] = callback
        }
    }
Jetpack Compose beyond MaterialFree components, screens and templates for apps that don’t look like Google’s. Copy them into your app, or let your coding agent add them.Browse for free

Content updated: