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?
Reduce Swipeview Sensitivity .Net Maui
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();
}
}
© 2022 - 2024 — McMap. All rights reserved.
Threshold
property to set the swiped distance size which can make the swipeview show the items. – Abyssinia