Skip to content

Some event kinds shouldn't allow non-zero pressure #30412

Description

@dkwingsmt

Reasoning

Currently most pointer event classes accepts a parameter pressure in their unnamed constructors and pass it to their superclass PointerEvent. This allows them to have non-zero pressure, which however doesn't always makes sense. More specifically, a non-zero pressure indicates that the pointer is in contact with the screen with certain force. The following table lists all event types and whether they are supposed to have a non-zero pressure:

Pointer event kind Does non-zero pressure make sense?
PointerAddedEvents No. This event indicates the start of the device tracking the pointer, which should contain no movement.
PointerCancelEvents No. This event indicates the end the pointer being directed towards this device, which should contain no movement.
PointerScrollEvents No. It's a pointer signal and doesn't change the state of the pointer.
PointerSignalEvents No. Pointer signals doesn't change the state of the pointer.
PointerUpEvents No. The pointer has stopped making contact with the device, hence the pressure must be zero.
PointerMoveEvents Yes. The pointer is moving while in contact with the device.
PointerDownEvents Yes. The pointer has made contact with the device.
PointerExitEvents No. This event only includes situations where the pointer is not in contact with the device.
PointerEnterEvents No. This event only includes situations where the pointer is not in contact with the device.
PointerHoverEvents No. The pointer is moving while not in contact with the device.
PointerRemovedEvents No. This event indicates the end of the device tracking the pointer, which should contain no movement.

This parameter was brought in by #24554, which added pressure to every pointer event classes to support force press gesture. According to discussion, this change was questioned (here among many others) at first, but eventually made it due to miscommunication. A later PR which added Enter and Exit likely followed the same pattern for consistency.

Changes

We propose to remove pressure from the unnamed constructors of the following classes:

  • PointerAddedEvent
  • PointerRemovedEvent
  • PointerHoverEvent
  • PointerEnterEvent
  • PointerExitEvent
  • PointerUpEvent
  • PointerCancelEvent

Instead, each class will pass pressure = 0.0 to its superclass.

A proposed PR can be found at #30414.

Impact

This change will break code that explicitly creates an instance of the aforementioned classes and specifying pressure.

To migrate the affected code,

  • If your constructor has pressure = 0.0, simply remove this argument and the behavior will be the same.
  • If your constructor has a non-zero pressure, migrate based on why it was needed. For example,
    • A PointerHoverEvent in this way is likely a misuse from PointerMoveEvent, which is defined as moving while the pointer is in contact with the device (per class documentation), where a non-zero pressure makes sense.
    • A PointerAddedEvent in this way should be expanded into an Added followed by a Down with the requested pressure and down.
    • A PointerRemovedEvent or PointerCancelEvent in this way should be expanded into a Move with the requested pressure and down followed by a Removed or Cancel.

This change will not break code that uses events dispatched by Flutter framework, including all gestures.

Activity

  1. added
    frameworkflutter/packages/flutter repository. See also f: labels.
    c: API breakBackwards-incompatible API changes
    on Apr 3, 2019
  2. self-assigned this
    on Apr 3, 2019
  3. JediBurrell commented on Apr 3, 2019

    @JediBurrell

    It currently takes all mouse events, as with the down property, which would explain it. I see it more of a scale situation, where this callback overrides PointerMoveEvent (though this is not mentioned). Unless I'm misinterpreting it, this seems intentional.

  4. dkwingsmt commented on Apr 3, 2019

    @dkwingsmt
    ContributorAuthor

    It currently takes all mouse events, as with the down property, which would explain it. I see it more of a scale situation, where this callback overrides PointerMoveEvent (though this is not mentioned). Unless I'm misinterpreting it, this seems intentional.

    Sorry, I don't quite get you, can you elaborate?
    As far as my understanding of your point,

    • PointerHoverEvent does not allow customization of down, instead sets down = false.
    • The definition of Hover and Move are described in their doc, where hover The pointer has moved with respect to the device while the pointer is not in contact with the device." while Move is "The pointer has moved with respect to the device while the pointer is in contact with the device." They are not interchangeable.
  5. changed the title [-]PointerHoverEvent shouldn't allow non-zero pressure[/-] [+]Some event kinds shouldn't allow non-zero pressure[/+] on Apr 3, 2019
  6. JediBurrell commented on Apr 4, 2019

    @JediBurrell

    Upon further looking, I can see I was indeed misinterpreting it. I could have sworn down returned its value, but you're right. My apologies.

  7. github-actions commented on Aug 30, 2021

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  8. locked as resolved and limited conversation to collaborators on Aug 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

c: API breakBackwards-incompatible API changesframeworkflutter/packages/flutter repository. See also f: labels.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions