Giter VIP home page Giter VIP logo

Comments (3)

MatkovIvan avatar MatkovIvan commented on July 24, 2024

Compose should generate non-zero/unique change ID values similar to the behavior on Android.

Why? Could you please explain your use case? It doesn't seem as a bug for me.

This ID is unique in case of touch but not for mouse even on Android (to test this try to drag with bluetooth mouse connected to real device).

from compose-multiplatform.

Flipstream-pinball avatar Flipstream-pinball commented on July 24, 2024

Why? Could you please explain your use case? It doesn't seem as a bug for me.

Thank you for the additional information. To clarify, I'm writing a 3rd party client application that needs to support three button activation options:

  • Standard press/release: Does not react to drag events
  • Single drag-press: The button will only fire one click event per drag event that touches the button
  • Multi drag-press: The button will fire click events every time a drag event touches the button

The parent Box composable sets up a MutableStateFlow for the PointerInputChange onDrag ID's Long value that is passed to button composables within the Box that subscribe to the flow. In the case of single drag-press, the Button remembers the last ID to limit clicks to one per PointerInputChange ID.

I originally initialized the ID flow with a value of 0 which worked beautifully on Android and compose. Migrating to multiplatform, PointerInputChange always emitting a matching value of 0 meant buttons set to single drag-press always ignored drag events on desktop.

I've worked around the behavior by changing the ID flow to support null values, and added an additional drag end event handler to emit a null value to the MutableStateFlow. It works, although altering the flows to allow null values feels like an anti-pattern.

This ID is unique in case of touch but not for mouse even on Android (to test this try to drag with bluetooth mouse connected to real device).

The PointerInputChange documentation doesn't mention that IDs are unique for touch events only, which is why I believed this was a defect.

However, it sounds like this is expected behavior, and I suspect my "single drag-press" use case may be rare.

from compose-multiplatform.

MatkovIvan avatar MatkovIvan commented on July 24, 2024

I see, thanks for clarification.

From that mentioned docs:

id
The unique id of the pointer associated with this PointerInputChange.

"unique id of the pointer" - so mouse is a single pointer with id 0. Clicking the button doesn't create a new pointer, but starting the touch does. So, I believe that current behaviour matches documentation.

Closing as it's expected behaviour and you already found workaround.

from compose-multiplatform.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.