Skip to content

Improve PointerInputChange consumption logic#1419

Merged
Gowsky merged 4 commits intomasterfrom
fix-for-consumed-pointer-events
Apr 12, 2026
Merged

Improve PointerInputChange consumption logic#1419
Gowsky merged 4 commits intomasterfrom
fix-for-consumed-pointer-events

Conversation

@Gowsky
Copy link
Copy Markdown
Member

@Gowsky Gowsky commented Apr 11, 2026

androidx.compose.foundation.gestures.detectTapGestures used for detecting tap and long press interactions has caused an excessive PointerInputChange consumption leading to other detectTapGestures higher up the Modifier chain to be non functional.

This resolves #1391.

Interactions whose handling changes

The onInteraction callback signature changes from (Interaction) -> Unit to (Interaction) -> Boolean. The return value indicates whether the event was handled and its PointerInputChange should be consumed. In CartesianChartHostImpl, this returns true when MarkerController.shouldAcceptInteraction accepts the interaction, and false otherwise.

  • Tap — Previously detected via androidx.compose.foundation.gestures.detectTapGestures, which unconditionally consumed pointer input. Now uses a custom implementation (awaitFirstDown + waitForUpOrCancellation) that only consumes the PointerInputChange when onInteraction returns true.
  • LongPress — Same as Tap: replaces detectTapGestures with a custom implementation (awaitLongPressOrCancellation) that conditionally consumes based on the onInteraction return value.
  • Press — Never consumed (false from the consumption check).
  • Release — Never consumed (false from the consumption check).
  • Move — Consumed only when consumeMoveEvents && !scrollState.scrollEnabled (previously consumed via PointerInputChange.consume() under the same condition, but inline rather than via the unified consume flag).
  • Enter — Consumed based on the onInteraction return value.
  • Exit — Consumed based on the onInteraction return value.
  • Scroll (Zoom) — Always consumes all pointer changes when zoom fires.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adjusts pointer input handling for Cartesian charts to avoid over-consuming PointerInputChanges (particularly around tap/long-press detection), which previously could break detectTapGestures higher in the Modifier chain (resolving #1391).

Changes:

  • Changes the onInteraction callback to return Boolean so interaction handlers can decide whether events should be consumed.
  • Replaces androidx.compose.foundation.gestures.detectTapGestures with a custom implementation that conditionally consumes tap/long-press events.
  • Enables Kotlin context parameters for the vico:compose module to support a context-based helper used by the new tap detection logic.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
vico/compose/src/commonMain/kotlin/com/patrykandpatrick/vico/compose/cartesian/Modifier.kt Implements conditional consumption logic and adds a custom tap/long-press gesture detector.
vico/compose/src/commonMain/kotlin/com/patrykandpatrick/vico/compose/cartesian/CartesianChartHost.kt Updates interaction handling to return whether the interaction was accepted (for consumption decisions).
vico/compose/build.gradle.kts Adds -Xcontext-parameters to support the new context-parameter helper.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Patrick Michalik <120058021+patrickmichalik@users.noreply.github.com>
@Gowsky Gowsky merged commit edc8dc2 into master Apr 12, 2026
3 checks passed
@Gowsky Gowsky deleted the fix-for-consumed-pointer-events branch April 12, 2026 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants