Improve PointerInputChange consumption logic#1419
Merged
Conversation
There was a problem hiding this comment.
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
onInteractioncallback to returnBooleanso interaction handlers can decide whether events should be consumed. - Replaces
androidx.compose.foundation.gestures.detectTapGestureswith a custom implementation that conditionally consumes tap/long-press events. - Enables Kotlin context parameters for the
vico:composemodule 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.
vico/compose/src/commonMain/kotlin/com/patrykandpatrick/vico/compose/cartesian/Modifier.kt
Show resolved
Hide resolved
vico/compose/src/commonMain/kotlin/com/patrykandpatrick/vico/compose/cartesian/Modifier.kt
Outdated
Show resolved
Hide resolved
vico/compose/src/commonMain/kotlin/com/patrykandpatrick/vico/compose/cartesian/Modifier.kt
Outdated
Show resolved
Hide resolved
patrickmichalik
approved these changes
Apr 12, 2026
vico/compose/src/commonMain/kotlin/com/patrykandpatrick/vico/compose/cartesian/Modifier.kt
Outdated
Show resolved
Hide resolved
vico/compose/src/commonMain/kotlin/com/patrykandpatrick/vico/compose/cartesian/Modifier.kt
Outdated
Show resolved
Hide resolved
vico/compose/src/commonMain/kotlin/com/patrykandpatrick/vico/compose/cartesian/Modifier.kt
Outdated
Show resolved
Hide resolved
Co-authored-by: Patrick Michalik <120058021+patrickmichalik@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
androidx.compose.foundation.gestures.detectTapGesturesused for detecting tap and long press interactions has caused an excessivePointerInputChangeconsumption leading to otherdetectTapGestureshigher up theModifierchain to be non functional.This resolves #1391.
Interactions whose handling changes
The
onInteractioncallback signature changes from(Interaction) -> Unitto(Interaction) -> Boolean. The return value indicates whether the event was handled and itsPointerInputChangeshould be consumed. InCartesianChartHostImpl, this returnstruewhenMarkerController.shouldAcceptInteractionaccepts the interaction, andfalseotherwise.androidx.compose.foundation.gestures.detectTapGestures, which unconditionally consumed pointer input. Now uses a custom implementation (awaitFirstDown+waitForUpOrCancellation) that only consumes thePointerInputChangewhenonInteractionreturnstrue.detectTapGestureswith a custom implementation (awaitLongPressOrCancellation) that conditionally consumes based on theonInteractionreturn value.falsefrom the consumption check).falsefrom the consumption check).consumeMoveEvents && !scrollState.scrollEnabled(previously consumed viaPointerInputChange.consume()under the same condition, but inline rather than via the unifiedconsumeflag).onInteractionreturn value.onInteractionreturn value.