From 08b4009ebb2d713e32c268dac7184ffbc474a973 Mon Sep 17 00:00:00 2001 From: Alexander Maryanovsky Date: Wed, 27 Nov 2024 11:37:15 +0200 Subject: [PATCH] Make optional the sending of extra events in InputDispatcher on mouse 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 --- .../compose/ui/test/InputDispatcher.kt | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/compose/ui/ui-test/src/commonMain/kotlin/androidx/compose/ui/test/InputDispatcher.kt b/compose/ui/ui-test/src/commonMain/kotlin/androidx/compose/ui/test/InputDispatcher.kt index 55e238da903b6..2628344121e52 100644 --- a/compose/ui/ui-test/src/commonMain/kotlin/androidx/compose/ui/test/InputDispatcher.kt +++ b/compose/ui/ui-test/src/commonMain/kotlin/androidx/compose/ui/test/InputDispatcher.kt @@ -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( @@ -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) @@ -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() + } } }