Skip to content
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

[Windows] Allow to refresh the RefreshView using the mouse #14261

Merged
merged 2 commits into from
Mar 30, 2023
Merged
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 @@ -14,16 +14,20 @@ public partial class RefreshViewHandler : ViewHandler<IRefreshView, RefreshConta

protected override RefreshContainer CreatePlatformView()
{
return new RefreshContainer
var refreshContainer = new RefreshContainer
{
ManipulationMode = UI.Xaml.Input.ManipulationModes.All,
PullDirection = RefreshPullDirection.TopToBottom
};

return refreshContainer;
}

protected override void ConnectHandler(RefreshContainer nativeView)
{
nativeView.Loaded += OnLoaded;
nativeView.RefreshRequested += OnRefresh;
nativeView.ManipulationDelta += OnManipulationDelta;

base.ConnectHandler(nativeView);
}
Expand All @@ -32,6 +36,7 @@ protected override void DisconnectHandler(RefreshContainer nativeView)
{
nativeView.Loaded -= OnLoaded;
nativeView.RefreshRequested -= OnRefresh;
nativeView.ManipulationDelta += OnManipulationDelta;

CompleteRefresh();

Expand Down Expand Up @@ -114,6 +119,18 @@ void OnRefresh(object sender, RefreshRequestedEventArgs args)
VirtualView.IsRefreshing = true;
}

void OnManipulationDelta(object sender, UI.Xaml.Input.ManipulationDeltaRoutedEventArgs e)
{
if (e.PointerDeviceType is UI.Input.PointerDeviceType.Touch)
return; // Already managed by the RefreshContainer control itself

const double minimumCumulativeY = 20;
double cumulativeY = e.Cumulative.Translation.Y;

if (cumulativeY > minimumCumulativeY && VirtualView is not null && !VirtualView.IsRefreshing)
VirtualView.IsRefreshing = true;
}

void CompleteRefresh()
{
if (_refreshCompletionDeferral != null)
Expand Down