From 96a4c2471fd001672a2efabd7c461db59b554fc5 Mon Sep 17 00:00:00 2001 From: Alan Grgic Date: Fri, 19 Jul 2019 05:58:59 -0500 Subject: [PATCH] [iOS] Fix initial color of RefreshControl in ListViews (#6473) fixes #5728 * add reproduction * make beginrefreshing occur after offset animation and ensure color is set before beginning refresh --- .../Issue5728.cs | 39 ++++++++++++++++++++++ .../Xamarin.Forms.Controls.Issues.Shared.projitems | 1 + .../Renderers/ListViewRenderer.cs | 21 +++++------- 3 files changed, 49 insertions(+), 12 deletions(-) create mode 100644 Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue5728.cs diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue5728.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue5728.cs new file mode 100644 index 0000000..1cfbdbf --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue5728.cs @@ -0,0 +1,39 @@ +using System; +using System.Threading.Tasks; +using Xamarin.Forms; +using Xamarin.Forms.CustomAttributes; +using Xamarin.Forms.Internals; + +namespace Xamarin.Forms.Controls.Issues +{ + [Preserve(AllMembers = true)] + [Issue(IssueTracker.Github, 5728, "ListView RefreshControlColor initial", PlatformAffected.iOS)] + public class Issue5728 : ContentPage + { + readonly ListView _listView; + public Issue5728() + { + _listView = new ListView + { + BackgroundColor = Color.Transparent, + IsPullToRefreshEnabled = true, + RefreshControlColor = Color.Cyan + }; + _listView.Refreshing += HandleListViewRefreshing; + Content = _listView; + } + + protected override void OnAppearing() + { + base.OnAppearing(); + + _listView.BeginRefresh(); + } + + async void HandleListViewRefreshing(object sender, EventArgs e) + { + await Task.Delay(1500); + _listView.EndRefresh(); + } + } +} diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems index 06ffbe5..3d85fef 100644 --- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems @@ -988,6 +988,7 @@ + diff --git a/Xamarin.Forms.Platform.iOS/Renderers/ListViewRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/ListViewRenderer.cs index f46d3bf..69c2239 100644 --- a/Xamarin.Forms.Platform.iOS/Renderers/ListViewRenderer.cs +++ b/Xamarin.Forms.Platform.iOS/Renderers/ListViewRenderer.cs @@ -243,11 +243,11 @@ namespace Xamarin.Forms.Platform.iOS UpdateHeader(); UpdateFooter(); UpdatePullToRefreshEnabled(); + UpdateSpinnerColor(); UpdateIsRefreshing(); UpdateSeparatorColor(); UpdateSeparatorVisibility(); UpdateSelectionMode(); - UpdateSpinnerColor(); UpdateVerticalScrollBarVisibility(); UpdateHorizontalScrollBarVisibility(); @@ -1467,16 +1467,16 @@ namespace Xamarin.Forms.Platform.iOS if (!_refresh.Refreshing) { - _refresh.BeginRefreshing(); - //hack: On iOS11 with large titles we need to adjust the scroll offset manually //since our UITableView is not the first child of the UINavigationController - UpdateContentOffset(TableView.ContentOffset.Y - _refresh.Frame.Height); - - //hack: when we don't have cells in our UITableView the spinner fails to appear - CheckContentSize(); - - TableView.ScrollRectToVisible(new RectangleF(0, 0, _refresh.Bounds.Width, _refresh.Bounds.Height), true); + //This also forces the spinner color to be correct if we started refreshing immediately after changing it. + UpdateContentOffset(TableView.ContentOffset.Y - _refresh.Frame.Height, () => + { + _refresh.BeginRefreshing(); + //hack: when we don't have cells in our UITableView the spinner fails to appear + CheckContentSize(); + TableView.ScrollRectToVisible(new RectangleF(0, 0, _refresh.Bounds.Width, _refresh.Bounds.Height), true); + }); } } else @@ -1615,9 +1615,6 @@ namespace Xamarin.Forms.Platform.iOS void UpdateContentOffset(nfloat offset, Action completed = null) { - if (!_usingLargeTitles) - return; - UIView.Animate(0.2, () => TableView.ContentOffset = new CoreGraphics.CGPoint(TableView.ContentOffset.X, offset), completed); } } -- 2.7.4