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
22.21k stars 1.75k forks source link

Tapping to close a SwipeView will activate TapGestureRecognizers on .Content #23921

Open sjordanGSS opened 3 months ago

sjordanGSS commented 3 months ago

Description

When a SwipeView is swiped, it can be tapped to close. However, this tap will also activate TapGestureRecognizers attached to the Content views

Please note that although I have not tested other .NET MAUI versions, this bug is present in Xamarin.Forms. I have recently revisited a project based upon Xamarin.Forms 5 that includes the workaround stated below.

Steps to Reproduce

Link to public reproduction project repository

https://github.com/sjordanGSS/swipeview-content-gesture

Version with bug

8.0.70 SR7, 8.0.61 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

Tested and reproduced on Android 7.1, 10, 11, 14

Did you find any workaround?

Code can be added to SwipeView.SwipeEnded and SwipeViewItem.Tapped to set the Content's IsEnabled to false while the view is swiped, however this will malfunction if the SwipeView is closed with a long press.

I tried wrapping the Label in a ContentView to see if this issue was exclusive to the immediate children of the SwipeView, however it had no effect.

Relevant log output

No response

github-actions[bot] commented 3 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.

sjordanGSS commented 3 months ago

I have updated the repro to include both a Label and a Button in a VerticalStackLayout as the SwipeView's content. Tapping to close the SwipeView over either of these controls will cause their Tapped or Clicked event handlers respectively to be invoked.

sjordanGSS commented 2 months ago

I've done some digging on this and tracked the bug down to this section of code: https://github.com/dotnet/maui/blob/d6cb19d9c99514eaec28c6b21357f4e5118684ba/src/Core/src/Platform/Android/MauiSwipeView.cs#L101

            if (Math.Abs(diffX) > Math.Abs(diffY))
                swipeDirection = diffX > 0 ? SwipeDirection.Right : SwipeDirection.Left;
            else
                swipeDirection = diffY > 0 ? SwipeDirection.Down : SwipeDirection.Up;

If both diff values are zero (as they are when the swipeview is tapped), SwipeDirection.Up will always be chosen. If no UpItems are set then this code

            var items = GetSwipeItemsByDirection(swipeDirection);

            if (items == null || items?.Count == 0)
                return false;

will return false. Adding

    if(diffX == 0 && diffY == 0)
      return _isOpen;

before the first section would resolve this issue. I have already tested this in my own project and verified that it resolves this issue. I may have some time tomorrow to submit a pr here