question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TapGestureRecognizer doesn't fire Tapped event on child controls

See original GitHub issue

Description

I added a TapGestureRecognizer to a custom ContentView which contains several other controls. I wondered why the Tapped event is not getting fired on Android when I tap on the ContentView. The same code is working on Windows.

I figured out, that when I add the TapGestureRecognizer to a child control which occupies alot of sapce the Tapped event gets fired. From my observation it looks like that the Tapped Event / TapGestureRecognizer will not be forwarded to its child controls.

This bug may be related to #6644 , #7466, #8004

Steps to Reproduce

  1. Create dotnet maui default project
  2. Add ContentView
  3. Add to the ContentView serveral controls
  4. register/add TapGestureRecognizer to ContentView.
  5. Tap on it and check if breakpoint gets hit on Tapped event
  6. Event is not fired

In the attached project TapGestureRecognizer_doesnt_fire_Tapped_event_on_child_controls.zip the ContentView contains the following control hierarchy:

  • ContentView
    • Grid
      • Frame (occupies quite a lot of sapce)

Adding the tapGestureRecognizer directly to the content (which is of type ContentView) will not fire the Tapped event. If you comment line control = ((content as ContentView).Children[0] as Grid).Children[0] as View in the tapGestureRecognizer gets added directly on the Frame. Tapping now on the ContentView will fire the Tapped event.

    private void MainPage_Loaded(object sender, EventArgs e)
    {
        View control = content; //content = ContentView
        //control = ((content as ContentView).Children[0] as Grid).Children[0] as View;  //Frame
        var tapGestureRecognizer = new TapGestureRecognizer();
        tapGestureRecognizer.Parent = control;
        tapGestureRecognizer.Tapped += TapGestureRecognizer_Tapped;
        control.GestureRecognizers.Add(tapGestureRecognizer);
    }

Version with bug

6.0.312

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

android

Did you find any workaround?

Register the TapGestureRecognizer on all sub controls of the ContentView.

Relevant log output

No response

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
mfe-commented, Jun 16, 2022

@jfversluis The TapGestureRecognizer sample works on windows. The event TapGestureRecognizer_Tapped will be hit if you touch the provided area: image

I noticed that I forgot to remove some StaticResources. I removed them from the sample, and updated the example.

MauiApp1.zip

In addition I added for android an screenshot. Hope it helps

image

For the android platform you would need to comment in: control = ((content as ContentView).Children[0] as Grid).Children[0] as View; //Frame

Edit: As I dont own an Iphone I don’t know the status of the issue on ios

0reactions
XamlTestcommented, May 16, 2023

Verified this on Visual Studio Enterprise 17.6.0 Preview 7.0. Repro on Android 13.0 with below Project: 8121.zip

Event TapGestureRecognizer_Tapped will be hit on Windows, but not on Android.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Xamarin - Frame.GestureRecognizers doesn't work when ...
The issue is that the lblQuantity isn't updating itself. I had previously another view with a stacklayout and the gesture recognizers worked ...
Read more >
TapGestureRecognizer Not working on iOS - Microsoft Q&A
The control is just a ContentView with a Shape as it's only child. I added a TapGestureRecognizer to the ContentView , set the...
Read more >
UIButton not receiving touches in iOS 13
Removing the TapGestureRecognizer doesn't change the behaviour. ... For some reason, the child controls were still visible; but not receiving events.
Read more >
Working with Tap Gesture Recognizers in Swift
In this post, I show you how to use a tap gesture recognizer in Swift using the UITapGestureRecognizer class. We create a simple...
Read more >
How to use gestures in SwiftUI
Learn Swift coding for iOS with these free tutorials.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found