Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ internal partial class SfHorizontalContent
double _moveX;
double _moveY;

// Flag set to true when horizontal movement exceeds threshold and is greater than vertical movement,
// indicating this should be processed as a swipe gesture rather than a tap
bool _shouldProcessTouchForSwipe;

// Constants for touch movement thresholds
const double VerticalScrollThreshold = 5;
const double HorizontalScrollThreshold = 15;
Expand Down Expand Up @@ -47,32 +51,44 @@ internal override bool OnInterceptTouchEvent(MotionEvent? motionEvent)
_downX = motionEvent.GetX();
_downY = motionEvent.GetY();
_initialPoint = currenTouchPoint;
_shouldProcessTouchForSwipe = false;
return false;
}
case MotionEventActions.Up:
{
_initialPoint = new Point(0, 0);
_shouldProcessTouchForSwipe = false;
break;
}
case MotionEventActions.Move:
{
_moveX = motionEvent.GetX();
_moveY = motionEvent.GetY();

// Check for vertical scrolling threshold
if (Math.Abs(_downY - _moveY) > VerticalScrollThreshold && Math.Abs(_downX - _moveX) < HorizontalScrollThreshold)
double horizontalDelta = Math.Abs(_downX - _moveX);
double verticalDelta = Math.Abs(_downY - _moveY);

// Check for vertical scrolling threshold - don't intercept vertical scrolls
if (verticalDelta > VerticalScrollThreshold && horizontalDelta < HorizontalScrollThreshold)
{
return false;
}

// Handle initial touch interaction
if (!_isPressed && Math.Abs(_downY - _moveY) != 0 && Math.Abs(_downX - _moveX) != 0)
// Only intercept if horizontal movement exceeds threshold and is greater than vertical movement
// This ensures taps with slight finger movement are not treated as swipes
if (!_isPressed && horizontalDelta > HorizontalScrollThreshold && horizontalDelta > verticalDelta)
{
_shouldProcessTouchForSwipe = true;
OnHandleTouchInteraction(PointerActions.Pressed, _initialPoint);
return true;
}
break;
}
case MotionEventActions.Cancel:
{
_shouldProcessTouchForSwipe = false;
break;
}
}
}

Expand All @@ -85,6 +101,11 @@ internal override bool OnInterceptTouchEvent(MotionEvent? motionEvent)
/// <param name="e">Pointer event arguments containing touch action and point.</param>
void ITouchListener.OnTouch(PointerEventArgs e)
{
if (!_shouldProcessTouchForSwipe)
{
return;
}

switch (e.Action)
{
case PointerActions.Pressed:
Expand All @@ -105,10 +126,11 @@ void ITouchListener.OnTouch(PointerEventArgs e)
{
// Handle the release action
OnHandleTouchInteraction(PointerActions.Released, e.TouchPoint);
_shouldProcessTouchForSwipe = false;
break;
}
}
}
#endregion
}
}
}