Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PressInteraction.Cancel is sent on mouse press and drag outside surface #4801

Open
adrientetar opened this issue May 10, 2024 · 1 comment
Open
Assignees
Labels
question Not a bug, but question or comment

Comments

@adrientetar
Copy link

I'm using a MutableInteractionSource.interactions for a Button control, to know when it's focused/pressed/hovered.
I noticed that, when I press the button, a PressInteraction.Press is sent (as you would expect), but then if I drag outside of the button while keeping pressed, PressInteraction.Cancel is sent, and mouse press isn't being tracked further (no PressInteraction.Release is sent when releasing the mouse button).
Is it on purpose?

On Mac at least, it looks like the usual behavior (system apps) is that if you press a button, and then move wherever, as long as you come back inside the button bounds when you release the mouse, it will be counted as a press.
The way InteractionSource works right now though, it's not possible to have the desktop press behavior. It works however if I use .onPointerEvent(PointerEventType.Press) and .onPointerEvent(PointerEventType.Release).

I'm wondering if, InteractionSource and onPointerEvent are supposed to have the same behaviors?

Affected platforms

  • Mac

Versions

  • Compose jvm 1.6.2
  • Kotlin version: 1.9.23
  • OS version(s) (required for Desktop and iOS issues): Mac OS 14.4.1
  • OS architecture (x86 or arm64): arm
  • Device (model or simulator for iOS issues): mac book pro
  • JDK (for desktop issues): JBR 17.0.10 or coretto 18, both exhibit this issue

To Reproduce
You can use this snippet on desktop

@adrientetar adrientetar added bug Something isn't working submitted labels May 10, 2024
@eymar
Copy link
Collaborator

eymar commented May 14, 2024

The observed behaviour is the same on Android, so it's inherited from Jetpack Compose.

From InteractionSource docs:

A common use case is androidx.compose.foundation.indication, where androidx.compose.foundation.Indication implementations can subscribe to an InteractionSource to draw indication for different Interactions, such as a ripple effect for PressInteraction.Press and a state overlay for DragInteraction.Start.

So using InteractionSource is not the best way to derive the actions on buttons (clicked, double-clicked, etc). Listening to Pointer Events is a better choice for this.

JFYI: When dragging after PointerEventType.Press there is also PointerEventType.Exit event before PointerEventType.Release.

Considering the visual effects manifested by a Button when I interact with it, I assume the behaviour of InteractionSource is correct. If your use case requires not visual effects, but some other logic probably PointerEvents is better option.

Could you please share more details about your use case?

@eymar eymar added question Not a bug, but question or comment and removed bug Something isn't working submitted labels May 14, 2024
@eymar eymar self-assigned this May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Not a bug, but question or comment
Projects
None yet
Development

No branches or pull requests

2 participants