question

PeterVestiFrendrup-0700 avatar image
0 Votes"
PeterVestiFrendrup-0700 asked PeterVestiFrendrup-0700 answered

TapGestureRecognizer often does not register a click in the Android Emulator

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>
dotnet-xamarin
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

JarvanZhang-MSFT avatar image
1 Vote"
JarvanZhang-MSFT answered

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.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

PeterVestiFrendrup-0700 avatar image
0 Votes"
PeterVestiFrendrup-0700 answered

Thank you Jarvan! :)

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.