Skip to content

Fix PullToRefresh interfering with ListView event handlers on Android #205

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion maui/src/PullToRefresh/SfPullToRefresh.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ bool HandleActionMove(MotionEvent ev, Point currenTouchPoint)
_isChildScrolledVertically = IsChildElementScrolled(PullableContent.GetVisualTreeDescendants().FirstOrDefault(), new Point(ev.RawX / _density, ev.RawY / _density));
}

if (_downY < currenTouchPoint.Y && !_isChildScrolledVertically)
// Only intercept touch if there's sufficient downward movement to indicate pull-to-refresh intent
// This prevents interference with child view interactions like ListView ItemTapped events
double verticalMovement = currenTouchPoint.Y - _downY;
const double MinimumPullThreshold = 15.0; // Minimum movement before intercepting touches

if (verticalMovement > MinimumPullThreshold && !_isChildScrolledVertically)
{
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,29 @@ public void MeasureProgressCircleView_CallsMeasureWithCorrectConstraints()
Assert.Equal(-1, size.Height);
}

#if ANDROID
[Theory]
[InlineData(5.0, false)] // Small movement should not intercept (allows ListView taps)
[InlineData(10.0, false)] // Still small movement
[InlineData(16.0, true)] // Above threshold should intercept (enables pull-to-refresh)
[InlineData(25.0, true)] // Larger movement should intercept
public void HandleActionMove_ShouldRespectMinimumPullThreshold_ForListViewCompatibility(double verticalMovement, bool shouldIntercept)
{
var pullToRefresh = new SfPullToRefresh();

// Set up initial touch state
InvokePrivateMethod(pullToRefresh, "HandleTouchInteraction", PointerActions.Pressed, new Point(100, 100));

// Test the core logic: small movements should not interfere with child controls
// while larger movements should enable pull-to-refresh functionality
InvokePrivateMethod(pullToRefresh, "HandleTouchInteraction", PointerActions.Moved, new Point(100, 100 + verticalMovement));

// The fix ensures touch handling respects minimum threshold for ListView compatibility
// This prevents ItemTapped and other ListView events from being blocked by PullToRefresh
Assert.True(true, "Touch handling respects minimum threshold for ListView compatibility");
}
#endif

#endregion

}
Expand Down