Skip to content
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

Merged
merged 5 commits into from Jul 25, 2023

Conversation

MatkovIvan
Copy link
Member

@MatkovIvan MatkovIvan commented Jul 24, 2023

Proposed Changes

It's part of #691

  • Do not override pressOwner on second simultaneous Press event (second touch or second button);
  • Refactor handling hover owner (move to separate function for future re-use). No behaviour change here.

Testing

Test: run tests from PopupTest or play with Popup 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 to Popup

Screenrecorder-2023-07-25-12-17-36-381.0.mp4

Issues Fixed

Fixes JetBrains/compose-multiplatform#3349

Copy link

@m-sasha m-sasha left a 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.

Comment on lines +603 to +607
val previousPressOwner = pressOwner
if (previousPressOwner != null) {
previousPressOwner.processPointerInput(event)
return
}
Copy link

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:

  1. Touch[id=1] on owner1 -> sent to owner1
  2. Touch[id=2] on owner2 -> sent to owner1
  3. Release[id=1] -> sent to owner1
  4. Touch[id=3] -> sent to owner1

Copy link
Member Author

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

Copy link

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.

Copy link
Member Author

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

Comment on lines +660 to +662
if (owner == lastHoverOwner) {
// Owner wasn't changed
return false
Copy link

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.

Copy link
Member Author

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

Copy link

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(
Copy link

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.

Copy link
Member Author

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

@m-sasha m-sasha self-requested a review July 25, 2023 10:53
@MatkovIvan MatkovIvan merged commit a49b9c0 into jb-main Jul 25, 2023
2 checks passed
@MatkovIvan MatkovIvan deleted the ivan.matkov/fix-press-owner branch July 25, 2023 10:56
@@ -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
Copy link
Collaborator

@igordmn igordmn Jul 25, 2023

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.

Copy link
Member Author

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

Copy link
Collaborator

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.

Copy link
Member Author

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

@igordmn igordmn changed the title Fix overriding pressOwner on multitouch Popup. Fix overriding pressOwner on multitouch Jul 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants