I have a CollectionView
with CanReorderItems
set to True
in combination with SwipeItems
and a TapGestureRecognizer
to allow the following interactions:
- Tap an item to display details
- Swipe left on an item to delete it
- Swipe right to perform another action on the item
- Reorder items by dragging-and-dropping them in the list
Swiping works fine. Reordering works too. However, the TapGestureRecognizer
fails to trigger intermittently as even the slightest sideways moment while tapping instead triggers the swipe behavior.
I would expect the behavior to be:
- Quick tap opens details
- Long-press enables dragging-and-dropping to reorder
- Swiping left or right on an item invokes either of the two commands
If I remove <SwipeView.LeftItems>
and <SwipeView.RightItems>
I can tap or reorder items as expected, but obviously not swipe them.
Here's the XAML, somewhat simplified for readability:
<CollectionView CanReorderItems="True">
<CollectionView.ItemTemplate>
<DataTemplate>
<SwipeView>
<SwipeView.RightItems>
<SwipeItems Mode="Execute" SwipeBehaviorOnInvoked="RemainOpen">
<SwipeItem IconImageSource="trash.png" Text="Remove" BackgroundColor="Red" Command="{Binding DeleteCommand}" CommandParameter="{Binding .}"></SwipeItem>
</SwipeItems>
</SwipeView.RightItems>
<SwipeView.LeftItems>
<SwipeItems Mode="Execute" SwipeBehaviorOnInvoked="Close">
<SwipeItem IconImageSource="plus_circle.png" Text="Refill" BackgroundColor="{StaticResource ThemeBlue}" Command=AddCommand}" CommandParameter="{Binding .}" />
</SwipeItems>
</SwipeView.LeftItems>
<Frame>
<Frame.GestureRecognizers>
<TapGestureRecognizer Command="{Binding DetailsCommand}" CommandParameter="{Binding .}" />
</Frame.GestureRecognizers>
<Grid ColumnDefinitions="*, 120">
<Label Text="{Binding Name}" VerticalOptions="Center" />
<Image Source="{Binding TypeImage}" Grid.Column="1" />
</Grid>
</Frame>
</SwipeView>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
Edit: Clarified question as I originally thought reordering was causing the issues.
Edit 2: To make reordering work as expected, I had to disable and re-enable CanReorderItems
in the SwipeStarted
/SwipeEnded
events.