Reduce Swipeview Sensitivity .Net Maui
Asked Answered
C

1

6

I didn't want to necro an old post so I am creating a new one on this. I have a collectionview that has two buttons on either side to increment or decrement a count, the buttons work however they are a lot harder to trigger since my swipeview left and right items keep triggering while trying to tap the buttons. This happens every 3-5 times attempting to hit the buttons, is there a way to adjust how far you have to swipe horizontally before swipeview activates?

Countershaft answered 15/6, 2022 at 17:28 Comment(5)
Do you mean when you click the button, the swipeview will be swiped? According to the link you provided and the official cocument, there is no such a property. But there is a Threshold property to set the swiped distance size which can make the swipeview show the items.Abyssinia
Yes, when i attempt to tap on my buttons within the collectionview it triggers my swipeview instead of button event handler. Isn't a big deal on emulator when I'm clicking straight down on mouse but on my actual phone its a big hard to do a precise direct down and up tap.Countershaft
The problem is a shortcoming of the swipeview, if we want resolve it, we may need to judge which event should be hit when the user taps the screen. It's a hard work.Abyssinia
This is a big problem for me as well. I'm developing my first .NET MAUI application, and I immediately ran into this. As a basis of comparison, I tried the Email application that came with my Android phone. I can easily swipe left, swipe right, and tap in that application. However, tapping is difficult to achieve on a physical device with the SwipeView, and a double-tap is practically impossible.Bruell
Yeah it definitely sucks, defintely reduces the quality of my app. Still no fix that I've seen. I'm afraid to release my app with issues like this.Countershaft
E
1

I also faced a similar problem like you and have a workaround for the issues. Since that the swipeview is too sensitive and device easily count as swipe not tap if the thumb move a little bit.

It can use the OnSwipeChanging event and OnSwipeEnded event with a public property Offset on measuring the moving distance of the swipe. The value of Offset is keep updating whenever the OnSwipeChanging event is invoked. When the user has stopped swiping, the OnSwipeEnded take the value of Offset and invoke tap action if Offset is less than a specific value.

XAML

<SwipeView SwipeChanging="OnSwipeChanging" SwipeEnded="OnSwipeEnded">
    <SwipeView.LeftItems>
        <SwipeItemView>
            <Grid WidthRequest="100" />
        </SwipeItemView>
    </SwipeView.LeftItems>
    <SwipeView.RightItems>
        <SwipeItemView>
            <Grid WidthRequest="100" />
        </SwipeItemView>
    </SwipeView.RightItems>
          
    <Frame HeightRequest="50">
         <Frame.GestureRecognizers>
             <TapGestureRecognizer NumberOfTapsRequired="1" Tapped="OnTapped" />
         </Frame.GestureRecognizers>
    </Frame>                               
</SwipeView>

C#

public partial class TestView : ContentPage
{
    public double OffSet { get; set; } = 0
   
    public TestView()
    {
        InitializeComponent();
    }


    public void OnSwipeChanging(object sender, SwipeChangingEventArgs args)
    {
        OffSet = args.Offset;
        var swipeView = (Microsoft.Maui.Controls.SwipeView)sender;

        if (args.SwipeDirection == SwipeDirection.Left && offSet < -50)
        {
            //swipe left action here
        }
        else if (args.SwipeDirection == SwipeDirection.Right && offSet > 50)
        {
            //swipe right action here
        }
    }


    public void OnSwipeEnded(object sender, SwipeEndedEventArgs args)
    {
        var swipeView = (SwipeView)sender;

        if (offSet < 5 && offSet > -5)
        {
            //click button action
            OnTapped();
        }
        swipeView.Close();
    }
}
Effervescent answered 23/12, 2023 at 5:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.