maui
maui copied to clipboard
TapGestureRecognizer.Tapped event not triggered on certain controls
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
- Create dotnet maui default project
- Add Frame control
- ListView control as Frame control's child
- Register/add TapGestureRecognizer to Frame.
- Tap on it and check if breakpoint gets hit on Tapped event.
- Event is not fired.
The issue reproducible sample is added in the attachments.
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
.NET 8?
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.
yes, it's true, in net 8 not working and many trouble
yes, it's true, in net 8 not working and many trouble
Please add NumberOfTapsRequired="1", then it will work
@jsuarezruiz @VishalOmprasad Please add NumberOfTapsRequired="1", then it will work
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
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.
Setting to 1 does indeed fix it in above repo
I beleive this has been same even in XF, where you always had to set the number of taps
Woah, ok. That is very scary to me. But thanks for the confirmation.
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.
This is a duplicate of #19788 and NumberOfTapsRequired="1" does not fix this under Android with .net8 and maui 8.0.7
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.
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.