Skip to content

Commit

Permalink
Make optional the sending of extra events in InputDispatcher on mouse…
Browse files Browse the repository at this point in the history
… press/release/scroll.

This behavior is specific to Android, and should thus be optional.

Test: No additional tests needed; the change is in the tests in CMP.
Change-Id: Idf7982d744a810b7392175b93f75d6e59c94cfc7
  • Loading branch information
m-sasha committed Dec 9, 2024
1 parent bb53640 commit 08b4009
Showing 1 changed file with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ internal expect fun createInputDispatcher(
*
* Chaining methods:
* * [advanceEventTime]
*
* [exitHoverOnPress] and [moveOnScroll] allow controlling Android-specific behaviors that may not
* be appropriate on other platforms. While it is a quick and simple solution, if more significant
* differences are discovered, this problem may need to be revisited for a more robust solution.
*
* Note that the extra events sent due to [exitHoverOnPress] and [moveOnScroll] are in fact filtered
* out on Android before they reach any Compose elements. They nevertheless need to be sent for the
* benefit of any interop Android views inside Compose, which expect an Android-native model of the
* event stream.
*/
@OptIn(InternalComposeApi::class)
internal abstract class InputDispatcher(
Expand Down Expand Up @@ -396,9 +405,11 @@ internal abstract class InputDispatcher(
}
mouse.setButtonBit(buttonId)

// Exit hovering if necessary
if (mouse.isEntered && exitHoverOnPress) {
mouse.exitHover()
// Exit hovering if necessary (Android-specific behavior)
if (exitHoverOnPress) {
if (mouse.isEntered) {
mouse.exitHover()
}
}
// down/move + press
mouse.enqueuePress(buttonId)
Expand Down Expand Up @@ -464,10 +475,12 @@ internal abstract class InputDispatcher(
mouse.unsetButtonBit(buttonId)
mouse.enqueueRelease(buttonId)

// When no buttons remaining, enter hover state immediately
if (exitHoverOnPress && mouse.hasNoButtonsPressed && isWithinRootBounds(currentMousePosition)) {
mouse.enterHover()
mouse.enqueueMove()
// When no buttons remaining, enter hover state immediately (Android-specific behavior)
if (exitHoverOnPress) {
if (mouse.hasNoButtonsPressed && isWithinRootBounds(currentMousePosition)) {
mouse.enterHover()
mouse.enqueueMove()
}
}
}

Expand Down

0 comments on commit 08b4009

Please sign in to comment.