maui icon indicating copy to clipboard operation
maui copied to clipboard

TapGestureRecognizer.Tapped event not triggered on certain controls

Open VishalOmprasad opened this issue 1 year ago • 13 comments

Description

I added TapGestureRecognizer to Frame which has ListView as its child control. When tapping on the ListView items and area covered by the ListView control the Tapped event was not triggered on Android. In other platforms (Windows, iOS, and macCatalyst) it worked fine.

Steps to Reproduce

  1. Create dotnet maui default project
  2. Add Frame control
  3. ListView control as Frame control's child
  4. Register/add TapGestureRecognizer to Frame.
  5. Tap on it and check if breakpoint gets hit on Tapped event.
  6. Event is not fired.

The issue reproducible sample is added in the attachments.

TapGestureRecognizerIssue.zip

Link to public reproduction project repository

No response

Version with bug

Unknown/Other

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

No response

Did you find any workaround?

No response

Relevant log output

No response

VishalOmprasad avatar Nov 27 '23 13:11 VishalOmprasad

.NET 8?

jsuarezruiz avatar Nov 27 '23 15:11 jsuarezruiz

Hi @VishalOmprasad. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

ghost avatar Nov 27 '23 15:11 ghost

yes, it's true, in net 8 not working and many trouble

tjiakwokyung28 avatar Nov 27 '23 23:11 tjiakwokyung28

yes, it's true, in net 8 not working and many trouble

Please add NumberOfTapsRequired="1", then it will work

crs2m5smith avatar Nov 28 '23 02:11 crs2m5smith

@jsuarezruiz @VishalOmprasad Please add NumberOfTapsRequired="1", then it will work

crs2m5smith avatar Nov 28 '23 02:11 crs2m5smith

1 is the default so this would be surprising if this fixed it: https://github.com/dotnet/maui/blob/9b6a251265af86c356d6ea9949422f80eeab0db3/src/Controls/src/Core/TapGestureRecognizer.cs#L17

mattleibow avatar Nov 28 '23 19:11 mattleibow

We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.

ghost avatar Nov 28 '23 19:11 ghost

Setting to 1 does indeed fix it in above repo

crs2m5smith avatar Nov 28 '23 20:11 crs2m5smith

I beleive this has been same even in XF, where you always had to set the number of taps

crs2m5smith avatar Nov 28 '23 20:11 crs2m5smith

Woah, ok. That is very scary to me. But thanks for the confirmation.

mattleibow avatar Nov 28 '23 22:11 mattleibow

Hi, I am trying to use TapGestureRecognizer on a grid control but it does not work on Android (it does on other platforms). Adding NumberOfTapsRequired="1" did not do anything.

BeepBeepBopBop avatar Feb 02 '24 22:02 BeepBeepBopBop

This is a duplicate of #19788 and NumberOfTapsRequired="1" does not fix this under Android with .net8 and maui 8.0.7

UkeHa avatar Feb 16 '24 10:02 UkeHa

Confirmed this is a problem on Android (not on iOS). We have a child control using a stacklayout with a tapgesture recognizer on 8.0.14 and also using nightly 8.0.40-nightly.10491. We always have had NumberOfTapsRequired="1".

This problem was an issue on iOS on .Net 7 but when we moved to .Net 8 it solved the issue but we hadn't started working on our Android app to convert it from Xamarin.Forms to MAUI.

This isn't the first time I see Microsoft closing issues just to have someone reopen the very same issue Microsoft closed.

mnxamdev avatar Apr 15 '24 22:04 mnxamdev

I'll also add that on Windows (haven't tested anywhere else yet), adding a TapGestureRecognizer to a Border does not work quite right.

Clicking directly on a child within the border does trigger it, but anywhere else on the border or it's padding does not. Adding NumberOfTaps doesn't resolve it.

For example, whith this XAML:

<Border Margin="0" Padding="20">

    <Border.GestureRecognizers>
        <TapGestureRecognizer Command="{Binding MyCommand}" />
    </Border.GestureRecognizers>

    <Label 
        HorizontalOptions="Center"
        Text="Tap Me" TextColor="Black">
    </Label>

</Border>

Clicking directly on the "Tap Me" text is the only thing that will trigger the recognizer. I realize this is a poor example (it could just be a button), but wanted to illustrate the behavior as easily as possible.

You can work around this issue by adding a different wrapper View (StackLayout) around the border and assign the gesture recognizer to that wrapper instead. Wrapping the border with a border doesn't work for what it's worth.

kiddailey avatar Aug 02 '24 19:08 kiddailey