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
Popup. Fix overriding pressOwner
on multitouch
#704
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, I think we're running into the problem that we haven't researched, discussed or decided what is the behavior we want (with regards to who receives which events when), so we keep running into more cases where we're not sure what should happen. I think we should either do the foundational work of deciding what the right behavior is, or leave the current behavior untouched (only fix obvious bugs). If we change the behavior, we risk breaking existing code for no good reason.
compose/ui/ui/src/skikoMain/kotlin/androidx/compose/ui/ComposeScene.skiko.kt
Outdated
Show resolved
Hide resolved
val previousPressOwner = pressOwner | ||
if (previousPressOwner != null) { | ||
previousPressOwner.processPointerInput(event) | ||
return | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure that's what we want to do? It means events will continue to be sent to the very first pressed owner, even if none current touches started within it:
- Touch[id=1] on owner1 -> sent to owner1
- Touch[id=2] on owner2 -> sent to owner1
- Release[id=1] -> sent to owner1
- Touch[id=3] -> sent to owner1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. The logic here is (and was, but with implementation issues) that the gesture starts with first touch and ends until last one. If we start to interact with owner1, we should sent all events to it for correctly handling all kinds of gestures
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That logic makes sense to me on the face of it, but without a real investigation, I don't have certainty. Also, if we decide that that's a principle for us, it's worth documenting it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a video from Android with expected behavior to PR description
if (owner == lastHoverOwner) { | ||
// Owner wasn't changed | ||
return false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe put this test first, since it's faster than iterating over pointers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will be logically incorrect because this check makes sense only for mouse.
For speed comparison: it won't be differ because it should end on first iteration - mouse always have only one pointer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ==
test was first before, and it doesn't have any side effects, so I don't know...
@@ -453,4 +459,48 @@ class PopupTest { | |||
scene.sendPointerEvent(PointerEventType.Release, Offset(11f, 11f), button = PointerButton.Primary) | |||
background.events.assertReceivedNoEvents() | |||
} | |||
|
|||
@Test | |||
fun secondClickDoesNotDismissPopup() = runSkikoComposeUiTest( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the best place to test the low-level touch dispatching is by examining popup behavior. There should be a test for the low-level dispatching by itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It just follows the existing structure. It was like that because Popup was the single usage of it
compose/ui/ui/src/skikoTest/kotlin/androidx/compose/ui/window/PopupTest.kt
Show resolved
Hide resolved
@@ -633,28 +637,43 @@ class ComposeScene internal constructor( | |||
// If pressOwner is under focusedOwner, hover state must be updated | |||
owner = null | |||
} | |||
if (processHover(event, owner)) { | |||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is subjective, but let's avoid return-in-the-middle, if we can in the future (a return in a loop is okay if it is in the beginning/ending of the loop). It can complicate code pathes comparing to small if's.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Disagree here. It reduces indention and nesting so makes the code more readable.
What's true here is that this kind of "pre" checks works better near the function start, but anyway
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indention and nesting
extracting to a separate function works better in this case
What's true here is that this kind of "pre" checks works better near the function start
checks at the start are okay.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this particular case this function handles hover and move. So the check is like
if (consumed) {
return
}
// Do next action
As an improvement I can suggest adding explicit consumed
variable, but not inverting the condition
pressOwner
on multitouchpressOwner
on multitouch
Proposed Changes
It's part of #691
pressOwner
on second simultaneousPress
event (second touch or second button);Testing
Test: run tests from
PopupTest
or play withPopup
in test application.This video shows expected behaviour (on Android). It does NOT dismiss
Popup
and does not send events to background if they initiated by second touch while first touch belongs toPopup
Screenrecorder-2023-07-25-12-17-36-381.0.mp4
Issues Fixed
Fixes JetBrains/compose-multiplatform#3349