dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
21.97k stars 1.71k forks source link

Android: PanGestureRecognizer gets confused when changing ZIndex after the pan starts. #23284

Open mmiller-d8 opened 2 months ago

mmiller-d8 commented 2 months ago

Description

On Android only, when you have more than one VisualElement on the page with a PanGestureRecognizer attached and you change the Z-Index on drag start, the event routing seems to get confused.

When you start to drag, you get a couple of Pan events, but then they stop. If release pressure and then start dragging again, it works normally. Probably because the ZIndex is already set, but that's just a guess.

This issue only occurs on Android. iOS works fine. If you only have one object on the page with a PanGestureRecognizer it works fine. Once you have multiple, it occasionally works as expected, but usually doesn't.

Steps to Reproduce

  1. Create a new Maui App
  2. Create two borders on the page. Attach PanGestureRecognizers to them and all the other plumbing you have to do.
  3. Don't change the Z-Index. Note that everything works fine.
  4. Add code in Started to bring the item to the top so it isn't hidden by the other items on the page. Also put code in Completed to restore it to what it was initially.
  5. Drag it again and it will start to move and then stop.
  6. Release the object and then start dragging again. It will work as expected.

As an aside, if you add a TapGestureRecognizer and change the Z-Index with a tap before you start dragging, it works fine. So, it seems like changing the ZIndex once the drag has started is what is breaking it.

Also, my reproduction has a ton of extra code - I wrote custom gesture recognizers that inherit from PanGestureRecognizer to take care of all the plumbing you have to do. But - I'm writing debug output at the raw event so you can see what happens.

Edit: The raw event is handled in GestureRecognizers/PanGestureRecognizerBase.cs.

Link to public reproduction project repository

https://github.com/mmiller-d8/ApplyQueryAttributes

Version with bug

8.0.60 SR6

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android 34

Did you find any workaround?

Not really. I'm trying to think of one, but it would be pretty involved - like putting a touch effect to change it before the drag actually starts, but that would be messy. Especially since the drag end might conflict with the release.

Relevant log output

No response

github-actions[bot] commented 2 months ago

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Open similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

mmiller-d8 commented 2 months ago

Those do not appear to be the same. Those generally are about the drag event not firing. I have a very specific case that can be reproduced and (technically) resolved (don't change the z-index once the pan movement starts).