3

I have a CollectionView with CanReorderItems set to True in combination with SwipeItems and a TapGestureRecognizer to allow the following interactions:

  1. Tap an item to display details
  2. Swipe left on an item to delete it
  3. Swipe right to perform another action on the item
  4. 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:

  1. Quick tap opens details
  2. Long-press enables dragging-and-dropping to reorder
  3. 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.

Ted Nyberg
  • 7,001
  • 7
  • 41
  • 72
  • You have a mistake in your TapGestureRecognizer. It should be: ` ` But that's probably not the reason and rather an editing mistake – Julian Oct 11 '22 at 19:39
  • 1
    @ewerspej You're absolutely right, I fixed it to avoid confusion. Thanks. – Ted Nyberg Oct 11 '22 at 19:45
  • What I've seen a couple of times already are situations where controls compete for gesture recognition. Controls higher up in the tree usually win. Is it possible that Taps are processed elsewhere already and that that is the reason why your `TapGestureRecognizer` fails to trigger? – Julian Oct 11 '22 at 19:58
  • 1
    I think it's more about the sensitivity of the `SwipeView`. If I tap while being really careful not to have any sideward motion, the `TapGestureRecognizer` triggers just fine. However, for normal taps, moving seemingly a single pixel sideways triggers the swipe behavior instead. It seems I'm not not the only one facing this challenge: https://stackoverflow.com/questions/72635530/reduce-swipeview-sensitivity-net-maui – Ted Nyberg Oct 11 '22 at 20:19
  • Yes, if it does trigger, even if you have to be careful to not start swiping then yes, this seems to be a different issue. Although it is somewhat related. – Julian Oct 11 '22 at 20:21

0 Answers0