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.24k stars 1.76k forks source link

TapGestureRecognizer doesn't fire Tapped event on child controls #8121

Open mfe- opened 2 years ago

mfe- commented 2 years ago

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:

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

jfversluis commented 2 years ago

Did you try it on Windows? Does it only not work on Android or also not on other platforms?

ghost commented 2 years ago

Hi @mfe-. 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.

mfe- commented 2 years ago

@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

kristinx0211 commented 2 years ago

verified repro on android, event TapGestureRecognizer_Tappedwill be hit on windows and IOS.

ghost commented 2 years ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

SunshineSpring666 commented 2 years ago

Bug: Putting Frame inside ListView's ItemTemplate blocks tap action to trigger on a ListView item.

XamlTest commented 1 year ago

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.

Manish-Pradhan-FP commented 11 months ago

Any updates on this. Its been sitting in backlog for over a year now. Thats crazy for such high usage usecase.

DDHSchmidt commented 9 months ago

Wow, this bug has been sitting here for more than 1.5 years and is still not addressed? Sure, this is not a major, crashing bug but as @Manish-Pradhan-FP said: This is far from being an uncommon use case. At least every MAUI documentation about GestureRecognizers should state: "You want to use this on Android? Our condolences."

bogdan-adesso-romania commented 8 months ago

Any update on this?

jfversluis commented 7 months ago

Still reproduces on 8.0.14

SuperCorks commented 1 month ago

+1 would love this to work