TapGestureRecognizer in Xamarin.Forms for Android

Just a very quick and dirty post for other people who might be looking for this. TL;DR the TapGestureRecognizer doesn’t work for more than two taps in Xamarin.Forms.

The problem with TapGestureRecognizer

Yesterday I spent a too big amount of time looking for the cause of my TapGestureRecognizer not working for Android. Observe the code underneath:

I wanted to create an image which triggered a Command when it is tapped ten times. OK, given, there are probably not many use cases which require this kind of behavior. But on the other hand even Google themselves use it to enable developer-mode these days.

Anyways, this code works just fine on iOS, but on Android it wouldn’t trigger my Command code. Instantly I started debugging, checked for any layout elements overlapping my image, applying InputTransparent everywhere just to rule it out. I even removed everything else, just keeping the image and still it wouldn’t work. I was about to give up, when I did one final attempt: does it work when I set it to require just one tap.. And guess what, it worked!

So, ten taps seems to be too much for Android. Or, at least, for Xamarin.Forms on Android. I’m still not sure why. I haven’t been able to find much on this on Google, part of the reason why I decided to do a small post on this. After I determined that you cannot do more than two taps on Android I decided to investigate some more. As it turns out there is already a bug for this on Bugzilla.

The ‘solution’

The solution I decided to do for the time being is to just set the NumberOfTapsRequired property to one and in the Command behind it I keep a simple integer counter which adds up until the number I want it to reach, and only then trigger the logic I want, i.e. enable the developer mode.

Maybe, just maybe, if I happen to find some spare time I might look into the Xamarin.Forms code and see what is going on. Would be awesome to contribute (even a little bit) to Forms at some point..

I hope that this information finds someone that needs it and saves some precious time!

5 thoughts on “TapGestureRecognizer in Xamarin.Forms for Android

  1. Happened to me too and I ended up using with a counter too…

    Kind of sad Xamarin Forms can’t do this right either …

    • Hi Mike! Thank you for reading!

      I’m sorry this happened to you as well. I hope I can people prevent wasting time on this from now on, so spread the word 😉

      I wouldn’t want to call it sad, while Forms is around for some time now, it has grown explosively so I can only imagine how hard they are working to keep everything on track. But with these kind of bugs my hands do start itching, like: this probably costs a few seconds to fix but it’s been in here for quite some time.

      Anyhow, they still do a lot of great work! So don’t give up hope!

  2. I think you made a mistake in line 2 its not supposed to be “Grid.GestureRecognizers” its supposed to be “Image.GestureRecognizers”

Leave a Comment