Skip to content

Commit

Permalink
[RefreshView] Fire RefreshCommand setting IsRefreshing (xamarin#7398)
Browse files Browse the repository at this point in the history
* refresh view ui tests

* Fixed issue notifying changes in IsRefreshing property

* Fire RefreshCommand setting IsRefreshing to true

* Update Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems

* Update Xamarin.Forms.Core.UITests.Shared/UITestCategories.cs

* Added RefreshView UITests

* - ui test with swipe

* - change to drag

* - fix ui test

* - remove extra property changed event
  • Loading branch information
jsuarezruiz authored and felipebaltazar committed Oct 16, 2019
1 parent b55cb31 commit 2760db0
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ protected override void Init()
{
Title = "Refresh View Tests";
var scrollViewContent =
new StackLayout();
new StackLayout()
{
};

Enumerable.Range(0, 1000).Select(_ => new Label() { Text = "Pull me down to refresh me" })
Enumerable.Range(0, 10).Select(_ => new Label() { HeightRequest = 200, Text = "Pull me down to refresh me" })
.ForEach(x => scrollViewContent.Children.Add(x));

_refreshView = new RefreshView()
Expand All @@ -38,7 +40,8 @@ protected override void Init()
{
HeightRequest = 2000,
BackgroundColor = Color.Green,
Content = scrollViewContent
Content = scrollViewContent,
AutomationId = "LayoutContainer"
},
Command = new Command(async () =>
{
Expand Down Expand Up @@ -69,5 +72,31 @@ protected override void Init()
}
};
}
#if UITEST
[Test]
public void IsRefreshingAndCommandTest()
{
RunningApp.Tap(q => q.Button("Toggle Refresh"));
RunningApp.WaitForElement(q => q.Marked("IsRefreshing: True"));
RunningApp.Screenshot("Refreshing");
RunningApp.WaitForElement(q => q.Marked("IsRefreshing: False"));
RunningApp.Screenshot("Refreshed");
}

[Test]
public void IsRefreshingAndCommandTest_SwipeDown()
{
RunningApp.WaitForElement(q => q.Marked("IsRefreshing: False"));

var container = RunningApp.WaitForElement("LayoutContainer")[0];

RunningApp.Pan(new Drag(container.Rect, Drag.Direction.TopToBottom, Drag.DragLength.Medium));

RunningApp.WaitForElement(q => q.Marked("IsRefreshing: True"));
RunningApp.Screenshot("Refreshing");
RunningApp.WaitForElement(q => q.Marked("IsRefreshing: False"));
RunningApp.Screenshot("Refreshed");
}
#endif
}
}
2 changes: 1 addition & 1 deletion Xamarin.Forms.Core.UITests.Shared/UITestCategories.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ internal static class UITestCategories
public const string RefreshView = "RefreshView";
public const string TitleView = "TitleView";
}
}
}
2 changes: 1 addition & 1 deletion Xamarin.Forms.Core/RefreshView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public RefreshView()
}

public static readonly BindableProperty IsRefreshingProperty =
BindableProperty.Create(nameof(IsRefreshing), typeof(bool), typeof(RefreshView), false);
BindableProperty.Create(nameof(IsRefreshing), typeof(bool), typeof(RefreshView), false, BindingMode.TwoWay);

public bool IsRefreshing
{
Expand Down
11 changes: 4 additions & 7 deletions Xamarin.Forms.Platform.Android/Renderers/RefreshViewRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ public override bool Refreshing
if (RefreshView != null && RefreshView.IsRefreshing != _refreshing)
RefreshView.IsRefreshing = _refreshing;

if (base.Refreshing == _refreshing)
return;

base.Refreshing = _refreshing;

if (base.Refreshing && Element is RefreshView refreshView && refreshView.Command != null && refreshView.Command.CanExecute(refreshView?.CommandParameter))
refreshView.Command.Execute(refreshView?.CommandParameter);
}
}

Expand Down Expand Up @@ -186,10 +186,7 @@ bool CanScrollUpViewByType(AView view)

public void OnRefresh()
{
if (RefreshView?.Command?.CanExecute(RefreshView?.CommandParameter) ?? false)
{
RefreshView.Command.Execute(RefreshView?.CommandParameter);
}
Refreshing = true;
}

void HandlePropertyChanged(object sender, PropertyChangedEventArgs e)
Expand Down
13 changes: 9 additions & 4 deletions Xamarin.Forms.Platform.iOS/Renderers/RefreshViewRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,16 @@ public bool IsRefreshing
{
_isRefreshing = value;

if (Element != null && Element.IsRefreshing != _isRefreshing)
Element.IsRefreshing = _isRefreshing;

if (_isRefreshing)
{
_refreshControl.BeginRefreshing();

if (Element is RefreshView refreshView && refreshView.Command != null && refreshView.Command.CanExecute(refreshView?.CommandParameter))
refreshView.Command.Execute(refreshView?.CommandParameter);
}
else
_refreshControl.EndRefreshing();

Expand Down Expand Up @@ -201,10 +209,7 @@ bool CanUseRefreshControlProperty()

void OnRefresh(object sender, EventArgs e)
{
if (Element?.Command?.CanExecute(Element?.CommandParameter) ?? false)
{
Element.Command.Execute(Element?.CommandParameter);
}
IsRefreshing = true;
}

void IEffectControlProvider.RegisterEffect(Effect effect)
Expand Down

0 comments on commit 2760db0

Please sign in to comment.