TapGestureRecognizer often does not register a click in the Android Emulator

Peter Vesti Frendrup 21 Reputation points
2021-04-02T19:21:43.363+00:00

Hi there!

I am using the TapGestureRecognizer and I have pretty terrible "hit ratio" on the Android Emulator. A lot of times I need to click 4-5 times before it registers an event properly. It seems to work especially bad just when I have started the App.

Is this a known issue or am I doing something wrong? The Buttons I use seem to work much more consistently.

Thank you,
Peter

Below is the XAML of an example (The Command CollectionTapped is what this question is about - I click and it doesn't execute that command consistently)

<RefreshView x:DataType="local:Browse_ViewModel" Command="{Binding LoadCollectionsCommand}" IsRefreshing="{Binding IsBusy, Mode=TwoWay}" BackgroundColor="{StaticResource BackgroundColorPrimary}" Margin="5, 5, 5, 5">
<CollectionView x:Name="CollectionsListView"
ItemsSource="{Binding Collections}"
SelectionMode="None"
BackgroundColor="{StaticResource BackgroundColorTertiary}">
<CollectionView.ItemTemplate>
<DataTemplate x:DataType="model:Collection">
<SwipeView Padding="3">
<SwipeView.RightItems>
<SwipeItem Text="Edit" BackgroundColor="Green" Command="{Binding Source={x:Reference page}, Path=BindingContext.EditCollectionCommand}" CommandParameter="{Binding .}"></SwipeItem>
<SwipeItem Text="Delete" BackgroundColor="Red" Command="{Binding Source={x:Reference page}, Path=BindingContext.RemoveCollectionCommand}" CommandParameter="{Binding .}"></SwipeItem>
</SwipeView.RightItems>
<Frame CornerRadius="0" HasShadow="True" Padding="0" BackgroundColor="{StaticResource BackgroundColorSecondary}" HeightRequest="75">
<Grid HeightRequest="75" Padding="0">
<StackLayout Padding="0" Orientation="Horizontal" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Spacing="20" BackgroundColor="Transparent">
<Label Text="{Binding IconString}" TextColor="{StaticResource TextColorPrimary}" FontSize="45" Padding="0" WidthRequest="60" VerticalTextAlignment="Center" Margin="5,0,0,0" HorizontalTextAlignment="Center">
<Label.FontFamily>
<OnPlatform x:TypeArguments="x:String" Android="FASolid.otf#Font Awesome 5 Free Regular" iOS="Font Awesome 5 Free" />
</Label.FontFamily>
</Label>

                                <Label Text="{Binding Name}" 
                                        LineBreakMode="NoWrap" 
                                        Style="{DynamicResource ListItemTextStyle}" 
                                        TextColor="{StaticResource TextColorPrimary}"
                                        FontSize="25"
                                        VerticalTextAlignment="Center"/>

                                <StackLayout.GestureRecognizers>
                                    <TapGestureRecognizer 
                                            Command="{Binding Source={RelativeSource AncestorType={x:Type local:Browse_ViewModel}}, Path=CollectionTapped}"     
                                            CommandParameter="{Binding .}">
                                    </TapGestureRecognizer>
                                </StackLayout.GestureRecognizers>
                            </StackLayout>
                    </Grid>
                    </Frame>
                </SwipeView>
            </DataTemplate>
        </CollectionView.ItemTemplate>
    </CollectionView>
</RefreshView>
Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,288 questions
0 comments No comments
{count} votes

Accepted answer
  1. JarvanZhang 23,936 Reputation points
    2021-04-05T02:51:06.7+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    Is this a known issue or am I doing something wrong? The Buttons I use seem to work much more consistently.

    Hi, I tested your code in my project and faced the similar issue as you described. However, if removing the swipeView, the gesture will work fine. This may be a potentials issue within gesture and swipeView, you could report the problem to the product team on github for a solution.

    Or using the SelectionChanged of the CollectionView for the tap function.

       <RefreshView Margin="5, 5, 5, 5">  
           <CollectionView x:Name="CollectionsListView" SelectionChanged="CollectionsListView_SelectionChanged"  
                           SelectionMode="Single">  
               <CollectionView.ItemTemplate>  
                   <DataTemplate>  
                       <SwipeView Padding="3">  
                           <SwipeView.RightItems>  
                               <SwipeItem Text="Edit" BackgroundColor="Green" />  
                               <SwipeItem Text="Delete" BackgroundColor="Red" />  
                           </SwipeView.RightItems>  
                           <Frame CornerRadius="0" HasShadow="True" Padding="0" HeightRequest="75">  
                               <StackLayout ...>  
                                   ...  
                               </StackLayout>  
                           </Frame>  
                       </SwipeView>  
                   </DataTemplate>  
               </CollectionView.ItemTemplate>  
           </CollectionView>  
       </RefreshView>  
    

    Best Regards,

    Jarvan Zhang


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Peter Vesti Frendrup 21 Reputation points
    2021-04-06T14:51:13.163+00:00

    Thank you Jarvan! :)

    0 comments No comments