Forum Xamarin Xamarin.Forms

Disable second tap on Label

ManojReddy.8431ManojReddy.8431 USMember ✭✭
edited November 2015 in Xamarin.Forms

Hi All,

I have a label where i am handling the click event using guestures. code below.

XAML CODE

        <Label Text="Click Here" FontSize="Micro">
            <Label.GestureRecognizers>
                <TapGestureRecognizer Tapped="OnTap"></TapGestureRecognizer>
            </Label.GestureRecognizers>
        </Label>

CODE

                    private void OnTap(object sender, EventArgs e)
                            {
                                Navigation.PushModalAsync(new Notice());
                            }

This works. But if user clicks on the label multiple times, then the tap event is called multiple times. I want it to be called only once.

How do i fix this?

I have tried the below solution.

                    private async void OnTap(object sender, EventArgs e)
                            {
                                if (userTapped)
                                    return;
                                userTapped = true;
                                await Navigation.PushModalAsync(new Notice());
                                userTapped = false;
                            }

This works sometimes and sometimes it doesn't. My assumption is that the Notice ( Content Page) is taking too much time.

Thank you.

Regards,
Manoj

Posts

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    You colud try using a global usertapped variable that you set to false on Notice page OnDisapperaring method

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    Or adding a delay before userTapped = false (but I am not sure about how this...)

  • kotetotemkotetotem Member ✭✭

    @ManojReddy.8431 said:
    Hi All,

    I have a label where i am handling the click event using guestures. code below.

    XAML CODE

            <Label Text="Click Here" FontSize="Micro">
              <Label.GestureRecognizers>
                  <TapGestureRecognizer Tapped="OnTap"></TapGestureRecognizer>
              </Label.GestureRecognizers>
            </Label>
    

    CODE

                        private void OnTap(object sender, EventArgs e)
                                {
                                    Navigation.PushModalAsync(new Notice());
                                }
    

    This works. But if user clicks on the label multiple times, then the tap event is called multiple times. I want it to be called only once.

    How do i fix this?

    I have tried the below solution.

                        private async void OnTap(object sender, EventArgs e)
                                {
                                    if (userTapped)
                                        return;
                                    userTapped = true;
                                    await Navigation.PushModalAsync(new Notice());
                                    userTapped = false;
                                }
    

    This works sometimes and sometimes it doesn't. My assumption is that the Notice ( Content Page) is taking too much time.

    Thank you.

    Regards,
    Manoj

    Any news regarding this?

Sign In or Register to comment.