Why is my tap events not firing at all on iOS and firing after many taps on android ?

Kelve17Kelve17 Member ✭✭

Hi guys.
I am new here, so if im doing anything wrong, im sorry.

My issue is: I have a view with 2 grids and inside the grids there are some controls. I've added gewsture recognizer to the grids but on android it fires after many tries, sometimes(very rarely) with 1 tap and on iOS it does not fire at all ...
What am i doing wrong ?

xaml code:

...
<StackLayout AbsoluteLayout.LayoutBounds="1,0,1,0.07" AbsoluteLayout.LayoutFlags="All">
                <StackLayout.Padding>
                    <OnPlatform Android="20,10,20,0" iOS="20,60,20,0"/>
                </StackLayout.Padding>
                <StackLayout Orientation="Horizontal">
                    <ImageButton Source="{local:ImageResource project.Images.menu_pontos.png}" BackgroundColor="Transparent" 
                             HorizontalOptions="StartAndExpand" VerticalOptions="Center"/>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                        <Grid Grid.Row="0" Grid.Column="0" RowSpacing="0" x:Name="premioSemana">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                            </Grid.RowDefinitions>

                            <Image Grid.Row="0" Grid.Column="0" x:Name="img1_1" Source="{local:ImageResource 
                                     project.Images.PREMIO_SEMANA_EL1.png}"/>
                            <Label Grid.Row="1" Grid.Column="0" x:Name="lbl1_1" Text="{Binding PremioSemana}" IsVisible="{Binding 
                                     SemPremioSemanaVisivel}"
                                   FontFamily="{StaticResource LightFont}" FontSize="8" TextColor="White" HorizontalTextAlignment="Center"
                                   VerticalTextAlignment="Center"/>
                            <Image Grid.Row="2" Grid.Column="0" x:Name="img1_2" Source="{local:ImageResource project.Images.PREMIO_SEMANA_EL2.png}"/>
                            <Label Grid.Row="3" Grid.Column="0" x:Name="lbl1_2" Text="{Static res:AppResource.prmSmn}" FontFamily="{StaticResource 
                                LightFont}" FontSize="8" TextColor="White" HorizontalTextAlignment="Center" 
                                VerticalTextAlignment="Center"/>

                            <Grid.GestureRecognizers>
                                <TapGestureRecognizer NumberOfTapsRequired="1" Command="{Binding AnimarPremioSemana}" CommandParameter="{x:Reference 
                                             premioSemana}"/>
                            </Grid.GestureRecognizers>
                        </Grid>
                        <Grid Grid.Row="0" Grid.Column="1" RowSpacing="0" x:Name="premioDia">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                            </Grid.RowDefinitions>

                            <Image Grid.Row="0" Grid.Column="0" Source="{local:ImageResource project.Images.PREMIO_DIA_EL1.png}"/>
                            <Label Grid.Row="1" Grid.Column="0" Text="{Binding PremioDia}" IsVisible="{Binding SemPremioDiaVisivel}"
                                   FontFamily="{StaticResource LightFont}" FontSize="8" TextColor="White"
                                   HorizontalTextAlignment="Center" VerticalTextAlignment="Center"/>
                            <Image Grid.Row="2" Grid.Column="0" Source="{local:ImageResource project.Images.PREMIO_DIA_EL2.png}"/>
                            <Label Grid.Row="3" Grid.Column="0" Text="{Static res:AppResource.prmDia}" FontFamily="{StaticResource LightFont}"
                                   FontSize="8" TextColor="White" HorizontalTextAlignment="Center" 
                                   VerticalTextAlignment="Center"/>

                            <Grid.GestureRecognizers>
                                <TapGestureRecognizer NumberOfTapsRequired="1" Command="{Binding AnimarPremioSemana}" CommandParameter="{x:Reference premioDia}"/>
                            </Grid.GestureRecognizers>
                        </Grid>
                    </Grid>
...

C# view model commands:

...
      public ICommand AnimarPremioDia
        {
            get => new Command<Grid>(async (premio) => {
                if (PremioDia == AppResource.semPremio)
                {
                    if (PopupNavigation.Instance.PopupStack.Count == 0)
                    {
                        var page = new NovoPremioDia();
                        await PopupNavigation.Instance.PushAsync(page);
                        page.Disappearing += NovoPremioDiaFechando;
                    }
                }
                else
                {
                    if (!TudoCumpridoNoDia())
                    {
                        uint timeout = 50;
                        await premio.TranslateTo(-15, 0, timeout);
                        await premio.TranslateTo(15, 0, timeout);
                        await premio.TranslateTo(-9, 0, timeout);
                        await premio.TranslateTo(9, 0, timeout);
                        await premio.TranslateTo(-5, 0, timeout);
                        await premio.TranslateTo(5, 0, timeout);
                        await premio.TranslateTo(-2, 0, timeout);
                        await premio.TranslateTo(2, 0, timeout);
                        premio.TranslationX = 0;
                    }
                    else
                    {
                        if (PopupNavigation.Instance.PopupStack.Count == 0)
                        {
                            await PopupNavigation.Instance.PushAsync(new AnimacaoPremioDia(PremioDia));
                        }
                    }
                }
            });
        }


        public ICommand AnimarPremioSemana
        {
            get => new Command<Grid>(async (premio) =>
            {
                if (PremioSemana == AppResource.semPremio)
                {
                    if(PopupNavigation.Instance.PopupStack.Count == 0)
                    {
                        var page = new NovoPremioSemana();
                        await PopupNavigation.Instance.PushAsync(page);
                        page.Disappearing += NovoPremioSemanaFechando;
                    }
                }
                else
                {
                    var val = await TudoCumpridoNaSemana();
                    if (/*DateTime.Today.DayOfWeek!=DayOfWeek.Sunday||*/ !val)
                    {
                        uint timeout = 50;
                        await premio.TranslateTo(-15, 0, timeout);
                        await premio.TranslateTo(15, 0, timeout);
                        await premio.TranslateTo(-9, 0, timeout);
                        await premio.TranslateTo(9, 0, timeout);
                        await premio.TranslateTo(-5, 0, timeout);
                        await premio.TranslateTo(5, 0, timeout);
                        await premio.TranslateTo(-2, 0, timeout);
                        await premio.TranslateTo(2, 0, timeout);
                        premio.TranslationX = 0;
                    }
                    else
                    {
                        if (PopupNavigation.Instance.PopupStack.Count == 0)
                        {
                            await PopupNavigation.Instance.PushAsync(new AnimacaoPremioSemana(PremioSemana));
                        }
                    }
                }
            });
        }
...

Best Answer

  • Kelve17Kelve17 ✭✭
    Accepted Answer

    Hi, I have already solved the issue. The problem was that i was using too many layouts. Once i simplified to having just 1 grid and 1 stacklayout, it worked.

Answers

  • jezhjezh Member, Xamarin Team Xamurai
    edited July 11

    I have created a demo using your axml, and tested it with my code , there is no problem.
    Could you please post the full code of the ViewModel or a basic demo so that we can test with it?

  • Kelve17Kelve17 Member ✭✭
    Accepted Answer

    Hi, I have already solved the issue. The problem was that i was using too many layouts. Once i simplified to having just 1 grid and 1 stacklayout, it worked.

Sign In or Register to comment.