[iOS] ActivityIndicator should not disappear when used in a ViewCell (#495)

* preserve activity indicator state

* changed to using listviewrenderer

* remove whitespace

* moved message to constructor

* add sample code

* remove message sending

* changes

* remove curly braces
This commit is contained in:
adrianknight89 2017-04-06 13:25:47 -05:00 коммит произвёл Rui Marinho
Родитель 3d9d1d3d22
Коммит 6966dd6cc7
4 изменённых файлов: 76 добавлений и 6 удалений

Просмотреть файл

@ -0,0 +1,44 @@
using System.Collections.Generic;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
#if UITEST
using Xamarin.UITest;
using NUnit.Framework;
#endif
namespace Xamarin.Forms.Controls
{
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Bugzilla, 44980, "ActivityIndicator disappears when scrolling", PlatformAffected.iOS)]
public class Bugzilla44980 : TestContentPage
{
protected override void Init()
{
var list = new List<string>();
for (var i = 0; i < 100; i++)
list.Add(i.ToString());
Content = new CListView
{
ItemsSource = list,
ItemTemplate = new DataTemplate(() =>
{
var activityIndicator = new ActivityIndicator
{
IsRunning = true,
IsVisible = true
};
return new ViewCell { View = activityIndicator };
})
};
}
}
public class CListView : ListView
{
public CListView() : base(ListViewCachingStrategy.RecycleElement)
{
}
}
}

Просмотреть файл

@ -169,6 +169,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla42832.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla44044.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla44338.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla44980.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla45067.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla45027.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla45330.cs" />

Просмотреть файл

@ -44,5 +44,11 @@ namespace Xamarin.Forms.Platform.iOS
else
Control.StopAnimating();
}
internal void PreserveState()
{
if (Control != null && !Control.IsAnimating && Element != null && Element.IsRunning)
Control.StartAnimating();
}
}
}

Просмотреть файл

@ -780,12 +780,13 @@ namespace Xamarin.Forms.Platform.iOS
public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
{
UITableViewCell nativeCell = null;
Cell cell;
UITableViewCell nativeCell;
var cachingStrategy = Controller.CachingStrategy;
if (cachingStrategy == ListViewCachingStrategy.RetainElement)
{
var cell = GetCellForPath(indexPath);
cell = GetCellForPath(indexPath);
nativeCell = CellTableViewCell.GetNativeCell(tableView, cell);
}
else if (cachingStrategy == ListViewCachingStrategy.RecycleElement)
@ -794,13 +795,13 @@ namespace Xamarin.Forms.Platform.iOS
nativeCell = tableView.DequeueReusableCell(ContextActionsCell.Key + id);
if (nativeCell == null)
{
var cell = GetCellForPath(indexPath);
cell = GetCellForPath(indexPath);
nativeCell = CellTableViewCell.GetNativeCell(tableView, cell, true, id.ToString());
}
else
{
var templatedList = TemplatedItemsView.TemplatedItems.GetGroup(indexPath.Section);
var cell = (Cell)((INativeElementView)nativeCell).Element;
cell = (Cell)((INativeElementView)nativeCell).Element;
ICellController controller = cell;
controller.SendDisappearing();
templatedList.UpdateContent(cell, indexPath.Row);
@ -813,10 +814,10 @@ namespace Xamarin.Forms.Platform.iOS
var bgColor = tableView.IndexPathForSelectedRow != null && tableView.IndexPathForSelectedRow.Equals(indexPath) ? UIColor.Clear : DefaultBackgroundColor;
SetCellBackgroundColor(nativeCell, bgColor);
PreserveActivityIndicatorState(cell);
return nativeCell;
}
public override nfloat GetHeightForHeader(UITableView tableView, nint section)
{
if (List.IsGroupingEnabled)
@ -1079,6 +1080,24 @@ namespace Xamarin.Forms.Platform.iOS
base.Dispose(disposing);
}
void PreserveActivityIndicatorState(Element element)
{
if (element == null)
return;
var activityIndicator = element as ActivityIndicator;
if (activityIndicator != null)
{
var renderer = Platform.GetRenderer(activityIndicator) as ActivityIndicatorRenderer;
renderer?.PreserveState();
}
else
{
foreach (Element childElement in (element as IElementController).LogicalChildren)
PreserveActivityIndicatorState(childElement);
}
}
}
}