GestureRecognizer is not working on android using Xamarin.forms

public void EnableSubmitButton(){
LeftMenuItem.IsEnabled = true;
TapGestureRecognizer OnLeftMenuItemClicked = new TapGestureRecognizer ((s,e) => {
OnSubmitClicked (s,e);
});
LeftMenuItem.GestureRecognizers.Add (OnLeftMenuItemClicked);
}

This is the code which is used to add gesture recognizer into the Image. It's working on iOS perfectly. But In android OnLeftMenuItemClicKed is not triggered.

Thanks in Advance.

Posts

  • JohnHardmanJohnHardman GBUniversity mod

    @JayaKumar.6615 - I am having a similar problem on Android. If I don't explicitly change IsEnabled it's fine. Looks like a Xamarin bug to me. Have you reported it in Bugzilla?

  • JohnHardmanJohnHardman GBUniversity mod

    @JayaKumar.6615 - I've added it to Bugzilla at https://bugzilla.xamarin.com/show_bug.cgi?id=34760 . Please add any extra details that you think would be useful.

  • Rob.0184Rob.0184 USUniversity ✭✭

    This still appears to be broken in 1.5.1.6471.

  • JeffDalbyJeffDalby USUniversity ✭✭

    Same issue happens in reverse. In my case I'm changing IsEnabled (which is bound to a property in the viewmodel) to False which will disable normal controls, but won't disable an image with a gesturerecognizer. If I set the property to false in the code behind it'll disable it when the page displays so the page itself is built right, it just won't respond to any changes in it.

  • MommMomm USMember ✭✭✭

    Add InputTransparent="true" to all of your children in the LeftMenuItem and probably you will get it done. The problem happens because one of the LeftMenuItem's children is getting the tap gesture instead of the LeftMenuItem.

  • XnainaXnaina USMember ✭✭✭

    Facing same issue. Please help.

  • JohnHardmanJohnHardman GBUniversity mod

    Xamarin have just marked this as not producible in bugzilla. If anybody has a piece of code to hand that demonstrates this, can you attach it to the bug at https://bugzilla.xamarin.com/show_bug.cgi?id=34760 please.

  • BrandonMinnickBrandonMinnick USXamarin Team Xamurai
    edited February 2016

    There is a bug open for a similar issue:
    https://bugzilla.xamarin.com/show_bug.cgi?id=38655

  • priyakarthicpriyakarthic INMember

    GestureRecognizer is not working on IOS using Xamarin.forms

    can anyone help me to fix this issue

  • Christopher.6427Christopher.6427 USMember ✭✭

    I am having this problem when I change a Controls IsEnabled property true->false->true at which point the GestureRecognizer stops working. As a workaround I am faking IsEnabled by setting opacity of the control, as I bind a Command to my recognizer it wont fire anyway (via the commands canExecuteFunc). This is obviously not ideal.

  • DamirLisakDamirLisak USMember

    I confirm this issue. The TapGestureRecognizer doesn't fire any more after changing the IsEnabled-Property from true->false->true. I tried everything: Removing and adding a new TapGestureRecognizer or unsubscribing and subscribing the Tapped event doesn't help as well.

  • TheGreatOneTheGreatOne USMember ✭✭

    Can confirm this issues. TapGestureRecognizer does't work on Android or iOS. Followed their samples: https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/gestures/tap/

  • JPHochbaumJPHochbaum USMember ✭✭✭

    I noticed that Gesture recognizers don't work on certain elements/views.

    For example I tried setting up a gesture recognizer on a PickerView but it only allows its built in tap gesture as the only event.

  • Emixam23Emixam23 USMember ✭✭✭

    Hi guys,

    I have the issue (Pan doesn't work, but it does for UWP) and I would like to know how did you fixed it? did you find any work around?

    Tahnk !

  • ClapotiClapoti CAMember ✭✭

    I'm building a custom control, it extends AbsoluteLayout.
    In the constructor, I setup this... it works on ios, but not on android, anyone knows what could be the problem ?

    ctor
    {
    ...
    GestureRecognizers.Add(new TapGestureRecognizer
    {
    Command = TransitionCommand
    });
    }

    private ICommand TransitionCommand
    {
    get
    {
    return _command ?? (_command = new Command(() =>
    {
    if (Command != null)
    Command.Execute(CommandParameter);
    }));
    }
    }

  • ClapotiClapoti CAMember ✭✭

    Well I should have tried that before... but it doesn't work on android when setting the gesture recognizer on the absolute layout, but it works when setting it on the boxview or image inside...

  • VelocityVelocity NZMember ✭✭✭
    Attaching GestureRecognizer's to layouts can be problematic. Try attaching to a View instead.
  • dev.kramdev.kram PHMember ✭✭

    @Momm said:
    Add InputTransparent="true" to all of your children in the LeftMenuItem and probably you will get it done. The problem happens because one of the LeftMenuItem's children is getting the tap gesture instead of the LeftMenuItem.

    This solution works for me. Thank you!

  • StephenJohnGrayStephenJohnGray GBUniversity ✭✭

    @Momm thanks for this, your workaround works :)

  • yasiralijavedyasiralijaved PKUniversity ✭✭

    This is known bug in prior versions of Xamarin.Forms. Its fixed in 2.4.0-pre1. See https://bugzilla.xamarin.com/show_bug.cgi?id=36703

  • yasiralijavedyasiralijaved PKUniversity ✭✭

    Surprised to see that this bug was reported in 2015 and Xamarin took 2 years to release the fix.

  • amirasemanamiraseman Member ✭✭

    I still have this issue with android. This is my Xaml code to set it up:

        <WebView
            x:Name="HtmlView"
            Grid.Row="1" 
            Source="{Binding HTMLFile}" 
            HorizontalOptions="FillAndExpand" 
            VerticalOptions="FillAndExpand"
            GoBackRequested="Handle_GoBackRequested"
            GoForwardRequested="Handle_GoForwardRequested"
            >
            <WebView.GestureRecognizers>
            <TapGestureRecognizer
                Tapped="Handle_Tapped"
                NumberOfTapsRequired="1" />
            <SwipeGestureRecognizer Direction="Left" Swiped="Handle_SwipedLeft"/>
            <SwipeGestureRecognizer Direction="Right" Swiped="Handle_SwipedRight"/>
            </WebView.GestureRecognizers>
        </WebView>
    

    and the handlers which only work with iOS:

        void Handle_SwipedLeft(object sender, Xamarin.Forms.SwipedEventArgs e)
        {
            flashCard.HTMLFile = getHTMLFileFromDevice("FlashCard2.html");
            HtmlView.Reload();
        }
    
        void Handle_SwipedRight(object sender, Xamarin.Forms.SwipedEventArgs e)
        {
            flashCard.HTMLFile = getHTMLFileFromDevice("FlashCard3.html");
            HtmlView.Reload();
        }
    
        void Handle_Tapped(object sender, System.EventArgs e)
        {
            flashCard.HTMLFile = getHTMLFileFromDevice("FlashCard3.html");
            HtmlView.Reload();
        }
    
Sign In or Register to comment.