Fix double refresh issue with RefreshView #7840
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good!
What are your thoughts on moving the CanExecute up to the top and setting the value with it?
if(value && RefreshView?.Command != null)
value = RefreshView.Command.CanExecute(RefreshView?.CommandParameter);
// Allow RefreshView.IsRefreshing to sync up with Refreshing
if (RefreshView != null && RefreshView.IsRefreshing != value)
{
RefreshView.SetValueFromRenderer(RefreshView.IsRefreshingProperty, value);
return;
}
_refreshing = value;
base.Refreshing = _refreshing;
if (base.Refreshing && RefreshView != null && RefreshView.Command != null)
RefreshView.Command.Execute(RefreshView?.CommandParameter);
On a side note there is also a bug with RefreshView where the Command bound to it isn't correctly propagating to IsEnabled when the control is created (I'm creating a PR for this now)
So in theory IsRefresh should never be set to true if in fact the Commands can execute is false but it still feels odd to let the Refresh trigger if CanExecute is false.
// Allow refreshView.IsRefreshing to sync up with Refreshing | ||
if (refreshView != null && refreshView.IsRefreshing != value) | ||
{ | ||
refreshView.IsRefreshing = value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
refreshView.IsRefreshing = value; | |
refreshView.SetValueFromRenderer(RefreshView.IsRefreshingProperty, value); |
// Allow RefreshView.IsRefreshing to sync up with Refreshing | ||
if (RefreshView != null && RefreshView.IsRefreshing != value) | ||
{ | ||
RefreshView.IsRefreshing = value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RefreshView.IsRefreshing = value; | |
RefreshView.SetValueFromRenderer(RefreshView.IsRefreshingProperty, value); |
@PureWeen Can you review again? I made some changes to the property setter since it was bloated with several lines of code.
I'd agree with you, but the user can manually set
|
Description of Change
If you refresh a RefreshView and add a time delay beforehand (through Task.Delay or network latency), then previously we ended up calling the refresh command twice. This PR fixes the issue. Also added a UI test.
Issues Resolved
Testing Procedure
Pull to refresh and make sure that the count shows 20 instead of 30.
PR Checklist