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

Refactor IsRefreshing property to separate animation and command execution responsibilities #15732

Closed
wants to merge 7 commits into from
Closed
1 change: 0 additions & 1 deletion src/Controls/src/Core/RefreshView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ static void OnIsRefreshingPropertyChanged(BindableObject bindable, object oldVal

var refreshView = (RefreshView)bindable;
refreshView.Refreshing?.Invoke(bindable, EventArgs.Empty);
refreshView.Command?.Execute(refreshView.CommandParameter);
}

static object OnIsRefreshingPropertyCoerced(BindableObject bindable, object value)
Expand Down
13 changes: 12 additions & 1 deletion src/Core/src/Core/IRefreshView.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Maui.Graphics;
using System.Windows.Input;
using Microsoft.Maui.Graphics;

namespace Microsoft.Maui
{
Expand All @@ -21,5 +22,15 @@ public interface IRefreshView : IView
/// The scrollable content to refresh.
/// </summary>
IView Content { get; }

/// <summary>
/// Gets the command to be executed when the refresh is triggered.
/// </summary>
ICommand Command { get; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to pull ICommand into core for this. This can instead be something like void UserRefreshing and the commanding is all handled in controls.

Similar to IButton

public interface IButton : IView, IPadding, IButtonStroke


/// <summary>
/// Gets the parameter to be passed to the command when it is executed.
/// </summary>
object CommandParameter { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ protected override void ConnectHandler(MauiSwipeRefreshLayout platformView)
void OnSwipeRefresh(object? sender, System.EventArgs e)
{
VirtualView.IsRefreshing = true;
VirtualView.Command?.Execute(VirtualView.CommandParameter);
}

protected override void DisconnectHandler(MauiSwipeRefreshLayout platformView)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ protected override void ConnectHandler(MauiRefreshLayout platformView)
void OnRefreshing(object? sender, EventArgs e)
{
VirtualView.IsRefreshing = true;
VirtualView.Command?.Execute(VirtualView.CommandParameter);
}

protected override void DisconnectHandler(MauiRefreshLayout platformView)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,21 +114,18 @@ void OnRefresh(object sender, RefreshRequestedEventArgs args)
{
CompleteRefresh();
_refreshCompletionDeferral = args.GetDeferral();

if (VirtualView != null)
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;
VirtualView.Command?.Execute(VirtualView.CommandParameter);
}
}

void CompleteRefresh()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public static void MapIsEnabled(IRefreshViewHandler handler, IRefreshView refres
void OnRefresh(object? sender, EventArgs e)
{
VirtualView.IsRefreshing = true;
VirtualView.Command?.Execute(VirtualView.CommandParameter);
}

static void UpdateIsRefreshing(IRefreshViewHandler handler)
Expand Down
2 changes: 2 additions & 0 deletions src/Core/src/PublicAPI/net-android/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Microsoft.Maui.ICommandMapper<TVirtualView, TViewHandler>.Add(string! key, Syste
Microsoft.Maui.ICommandMapper<TVirtualView, TViewHandler>.Add(string! key, System.Action<TViewHandler, TVirtualView>! action) -> void
Microsoft.Maui.Handlers.IImageSourcePartSetter
Microsoft.Maui.Handlers.IImageSourcePartSetter.SetImageSource(Android.Graphics.Drawables.Drawable? obj) -> void
Microsoft.Maui.IRefreshView.Command.get -> System.Windows.Input.ICommand!
Microsoft.Maui.IRefreshView.CommandParameter.get -> object!
Microsoft.Maui.Layouts.FlexBasis.Equals(Microsoft.Maui.Layouts.FlexBasis other) -> bool
Microsoft.Maui.Platform.ImageSourcePartLoader.ImageSourcePartLoader(Microsoft.Maui.Handlers.IImageSourcePartSetter! handler) -> void
Microsoft.Maui.Platform.ShapeExtensions
Expand Down
2 changes: 2 additions & 0 deletions src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Microsoft.Maui.ICommandMapper<TVirtualView, TViewHandler>.Add(string! key, Syste
Microsoft.Maui.ICommandMapper<TVirtualView, TViewHandler>.Add(string! key, System.Action<TViewHandler, TVirtualView>! action) -> void
Microsoft.Maui.Handlers.IImageSourcePartSetter
Microsoft.Maui.Handlers.IImageSourcePartSetter.SetImageSource(UIKit.UIImage? obj) -> void
Microsoft.Maui.IRefreshView.Command.get -> System.Windows.Input.ICommand!
Microsoft.Maui.IRefreshView.CommandParameter.get -> object!
Microsoft.Maui.Layouts.FlexBasis.Equals(Microsoft.Maui.Layouts.FlexBasis other) -> bool
Microsoft.Maui.LifecycleEvents.iOSLifecycle.PerformFetch
Microsoft.Maui.Platform.ImageSourcePartLoader.ImageSourcePartLoader(Microsoft.Maui.Handlers.IImageSourcePartSetter! handler) -> void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Microsoft.Maui.ICommandMapper<TVirtualView, TViewHandler>.Add(string! key, Syste
Microsoft.Maui.ICommandMapper<TVirtualView, TViewHandler>.Add(string! key, System.Action<TViewHandler, TVirtualView>! action) -> void
Microsoft.Maui.Handlers.IImageSourcePartSetter
Microsoft.Maui.Handlers.IImageSourcePartSetter.SetImageSource(UIKit.UIImage? obj) -> void
Microsoft.Maui.IRefreshView.Command.get -> System.Windows.Input.ICommand!
Microsoft.Maui.IRefreshView.CommandParameter.get -> object!
Microsoft.Maui.Layouts.FlexBasis.Equals(Microsoft.Maui.Layouts.FlexBasis other) -> bool
Microsoft.Maui.Platform.ImageSourcePartLoader.ImageSourcePartLoader(Microsoft.Maui.Handlers.IImageSourcePartSetter! handler) -> void
Microsoft.Maui.Platform.MauiImageView.MauiImageView(Microsoft.Maui.Handlers.IImageHandler! handler) -> void
Expand Down
2 changes: 2 additions & 0 deletions src/Core/src/PublicAPI/net-tizen/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Microsoft.Maui.SizeRequest.Equals(Microsoft.Maui.SizeRequest other) -> bool
Microsoft.Maui.Handlers.IImageSourcePartSetter
Microsoft.Maui.Handlers.IImageSourcePartSetter.SetImageSource(Microsoft.Maui.Platform.MauiImageSource? obj) -> void
Microsoft.Maui.Platform.ImageSourcePartLoader.ImageSourcePartLoader(Microsoft.Maui.Handlers.IImageSourcePartSetter! handler) -> void
Microsoft.Maui.IRefreshView.Command.get -> System.Windows.Input.ICommand!
Microsoft.Maui.IRefreshView.CommandParameter.get -> object!
override Microsoft.Maui.Layouts.FlexBasis.Equals(object? obj) -> bool
override Microsoft.Maui.Layouts.FlexBasis.GetHashCode() -> int
override Microsoft.Maui.SizeRequest.Equals(object? obj) -> bool
Expand Down
2 changes: 2 additions & 0 deletions src/Core/src/PublicAPI/net-windows/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Microsoft.Maui.IApplication.UserAppTheme.get -> Microsoft.Maui.ApplicationModel.
Microsoft.Maui.Hosting.MauiApp.DisposeAsync() -> System.Threading.Tasks.ValueTask
Microsoft.Maui.Handlers.IImageSourcePartSetter
Microsoft.Maui.Handlers.IImageSourcePartSetter.SetImageSource(Microsoft.UI.Xaml.Media.ImageSource? obj) -> void
Microsoft.Maui.IRefreshView.Command.get -> System.Windows.Input.ICommand!
Microsoft.Maui.IRefreshView.CommandParameter.get -> object!
Microsoft.Maui.IWindow.TitleBarDragRectangles.get -> Microsoft.Maui.Graphics.Rect[]?
Microsoft.Maui.ICommandMapper
Microsoft.Maui.ICommandMapper.GetCommand(string! key) -> System.Action<Microsoft.Maui.IElementHandler!, Microsoft.Maui.IElement!, object?>?
Expand Down
2 changes: 2 additions & 0 deletions src/Core/src/PublicAPI/net/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Microsoft.Maui.ICommandMapper<TVirtualView, TViewHandler>.Add(string! key, Syste
Microsoft.Maui.ICommandMapper<TVirtualView, TViewHandler>.Add(string! key, System.Action<TViewHandler, TVirtualView>! action) -> void
Microsoft.Maui.Handlers.IImageSourcePartSetter
Microsoft.Maui.Handlers.IImageSourcePartSetter.SetImageSource(object? obj) -> void
Microsoft.Maui.IRefreshView.Command.get -> System.Windows.Input.ICommand!
Microsoft.Maui.IRefreshView.CommandParameter.get -> object!
Microsoft.Maui.Layouts.FlexBasis.Equals(Microsoft.Maui.Layouts.FlexBasis other) -> bool
Microsoft.Maui.Platform.ImageSourcePartLoader.ImageSourcePartLoader(Microsoft.Maui.Handlers.IImageSourcePartSetter! handler) -> void
Microsoft.Maui.SizeRequest.Equals(Microsoft.Maui.SizeRequest other) -> bool
Expand Down
2 changes: 2 additions & 0 deletions src/Core/src/PublicAPI/netstandard/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Microsoft.Maui.ICommandMapper<TVirtualView, TViewHandler>.Add(string! key, Syste
Microsoft.Maui.ICommandMapper<TVirtualView, TViewHandler>.Add(string! key, System.Action<TViewHandler, TVirtualView>! action) -> void
Microsoft.Maui.Handlers.IImageSourcePartSetter
Microsoft.Maui.Handlers.IImageSourcePartSetter.SetImageSource(object? obj) -> void
Microsoft.Maui.IRefreshView.Command.get -> System.Windows.Input.ICommand!
Microsoft.Maui.IRefreshView.CommandParameter.get -> object!
Microsoft.Maui.Layouts.FlexBasis.Equals(Microsoft.Maui.Layouts.FlexBasis other) -> bool
Microsoft.Maui.Platform.ImageSourcePartLoader.ImageSourcePartLoader(Microsoft.Maui.Handlers.IImageSourcePartSetter! handler) -> void
Microsoft.Maui.SizeRequest.Equals(Microsoft.Maui.SizeRequest other) -> bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Microsoft.Maui.ICommandMapper<TVirtualView, TViewHandler>.Add(string! key, Syste
Microsoft.Maui.ICommandMapper<TVirtualView, TViewHandler>.Add(string! key, System.Action<TViewHandler, TVirtualView>! action) -> void
Microsoft.Maui.Handlers.IImageSourcePartSetter
Microsoft.Maui.Handlers.IImageSourcePartSetter.SetImageSource(object? obj) -> void
Microsoft.Maui.IRefreshView.Command.get -> System.Windows.Input.ICommand!
Microsoft.Maui.IRefreshView.CommandParameter.get -> object!
Microsoft.Maui.Layouts.FlexBasis.Equals(Microsoft.Maui.Layouts.FlexBasis other) -> bool
Microsoft.Maui.Platform.ImageSourcePartLoader.ImageSourcePartLoader(Microsoft.Maui.Handlers.IImageSourcePartSetter! handler) -> void
Microsoft.Maui.SizeRequest.Equals(Microsoft.Maui.SizeRequest other) -> bool
Expand Down