Skip to content

[CMP-7202] Introduce Unified Multiplatform Pointer Click Modifier#5570

Open
gagik894 wants to merge 3 commits intoJetBrains:masterfrom
gagik894:feature/on-pointer-click
Open

[CMP-7202] Introduce Unified Multiplatform Pointer Click Modifier#5570
gagik894 wants to merge 3 commits intoJetBrains:masterfrom
gagik894:feature/on-pointer-click

Conversation

@gagik894
Copy link
Copy Markdown

Summary

Introduces Modifier.onPointerClick in org.jetbrains.compose.components.input, providing a unified multiplatform API for handling pointer interactions (mouse buttons, stylus, keyboard modifiers) while preserving touch semantics.

Resolves: CMP-7202


Problem

  • Metadata Loss: Modifier.clickable does not expose hardware details (button type, modifiers, pointer type).
  • Inefficient Workarounds: Desktop/Web solutions rely on stacking multiple modifiers, increasing complexity and risk of inconsistent behavior.

Solution

Modifier.onPointerClick provides a single entry point for pointer-aware interactions via a structured PointerClickEvent.

Event Payload

  • position: Click position relative to component
  • buttons: PointerButtons (nullable for accessibility/synthesized events)
  • type: PointerType (Mouse, Touch, Stylus, etc.)
  • keyboardModifiers: Shift/Ctrl/Alt/Meta state
  • Helpers: isPrimaryAction, isSecondaryAction, isEraser

Implementation

  • Built as a DelegatingNode using pointer + semantics nodes
  • Processes events across pointer passes for correct cancellation behavior
  • Safely integrates keyboard modifiers and accessibility-triggered clicks
  • Decouples click handling from visual indication (primary actions trigger ripple by default)

Testing

  • Covers button routing, modifier propagation, cancellation, and bounds handling
  • Includes interactive demo for inspection and validation

gagik894 and others added 3 commits March 30, 2026 22:24
…r clicks

Introduce `onPointerClick` and `onPrimaryClick` modifiers to provide rich interaction metadata, including support for secondary/tertiary buttons and keyboard modifiers.

- Add `PointerClickEvent` to encapsulate click position, button state, pointer type, and keyboard modifiers.
- Implement `onPointerClick` modifier with support for custom press interaction triggers and visual indications.
- Implement `onPrimaryClick` convenience modifier for standard primary interactions.
- Ensure proper handling of touch slop, cancellation (e.g., during parent scrolling), and disabled states.
- Support synthesized clicks via semantics for accessibility and keyboard navigation.
- Include comprehensive test suite covering hardware buttons, modifiers, ripple lifecycles, and edge cases.

## Release Notes
Experimental Compose Multiplatform input library providing advanced hardware-aware pointer click modifiers.
Introduce a multi-platform demo suite to showcase the `onPointerClick` modifier across Android and Desktop.

- Add `input:demo:shared` module containing a "PointerClick Laboratory" to test hardware-aware routing, ripple policies, and event logging.
- Add `input:demo:androidApp` providing a standard Android activity wrapper for the demo.
- Add `input:demo:desktopApp` providing a JVM-based desktop entry point for the demo.
- Implement `UsePointerClick` screen to demonstrate:
    - Unified handling of Primary, Secondary, and Eraser inputs.
    - Custom ripple trigger policies based on button state.
    - Visual indication suppression (silent clicks).
    - Real-time event inspection including pointer type, keyboard modifiers, and coordinates.
- Update `components/settings.gradle.kts` to include the new demo modules.

## Release Notes
N/A
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.

1 participant