Skip to content

TapGestureRecognizer.Tapped fired multiple times on Android when GestureRecognizers were changed after rendering. #23177

@mohsenbgi

Description

@mohsenbgi

Description

On android when a view is rendered and a new GestureRecognizer is added to its GestureRecognizers by behind code, the Tapped events fire multiple times.

Steps to Reproduce

  1. Create a new MAUI App

  2. Replace content of MainPage.xaml with

<VerticalStackLayout>
     <Button x:Name="tapButton" Text="Tap button">
         <Button.GestureRecognizers>
             <TapGestureRecognizer Tapped="OnTapped" />
         </Button.GestureRecognizers>
     </Button>
     
     <Button Text="Add new Gesture" x:Name="addGestureButton" />
 </VerticalStackLayout>
  1. Replace MainPage.xaml.cs with following:
public partial class MainPage : ContentPage
{
    public MainPage()
    {
        InitializeComponent();

        addGestureButton.Clicked += (s, e) =>
        {
            var p = new TapGestureRecognizer();
            p.Tapped += (s, e) =>
            {

            };
            tapButton.GestureRecognizers.Add(p);
        };
    }

    public void OnTapped(object sender, TappedEventArgs args)
    {
        // runs multiple times by one tap
    }
}
  1. Start debugging on Android
  2. tap on "Add new Gesture"
  3. tap on "Tap button"

Link to public reproduction project repository

No response

Version with bug

8.0.10 SR3

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status

    Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions