зеркало из https://github.com/DeGsoft/maui-linux.git
[iOS] Clear prototype cell on UnevenRows (#1569)
* [Controls]Add repo for github 1567 * [iOS] Make sure to clear the prototype cell because renderers were disposed. * [Controls] Add IssueTestNumber * [UITest] Add Preserve to fix android test * [iOS] Better fix for invalidate prototype cell
This commit is contained in:
Родитель
1f631f477e
Коммит
19cb5dc08f
|
@ -0,0 +1,106 @@
|
|||
using Xamarin.Forms.CustomAttributes;
|
||||
using Xamarin.Forms.Internals;
|
||||
using System.Windows.Input;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System;
|
||||
|
||||
#if UITEST
|
||||
using Xamarin.UITest;
|
||||
using NUnit.Framework;
|
||||
#endif
|
||||
|
||||
namespace Xamarin.Forms.Controls.Issues
|
||||
{
|
||||
[Preserve(AllMembers = true)]
|
||||
[Issue(IssueTracker.Github, 1567, "NRE using TapGestureRecognizer on cell with HasUnevenRows", PlatformAffected.iOS, issueTestNumber: 1)]
|
||||
public class GitHub1567 : TestContentPage // or TestMasterDetailPage, etc ...
|
||||
{
|
||||
ICommand SomeCommand;
|
||||
ObservableCollection<LocalIem> LocalList { get; set; } = new ObservableCollection<LocalIem>();
|
||||
|
||||
protected override async void Init()
|
||||
{
|
||||
// Initialize ui here instead of ctor
|
||||
var btn = new Button
|
||||
{
|
||||
AutomationId = "btnFillData",
|
||||
Text = "FILL DATA",
|
||||
Command = new Command(async () => { await FillData(); })
|
||||
};
|
||||
var lst = new ListView(ListViewCachingStrategy.RecycleElement)
|
||||
{
|
||||
Header = btn,
|
||||
HasUnevenRows = true,
|
||||
RowHeight = -1,
|
||||
SeparatorVisibility = SeparatorVisibility.None,
|
||||
ItemsSource = LocalList,
|
||||
ItemTemplate = new DataTemplate(typeof(CustomCell))
|
||||
};
|
||||
|
||||
Content = lst;
|
||||
this.BindingContext = this;
|
||||
SomeCommand = new Command(SomeCommandAction);
|
||||
await FillData();
|
||||
}
|
||||
|
||||
[Preserve(AllMembers = true)]
|
||||
class CustomCell : ViewCell
|
||||
{
|
||||
public CustomCell()
|
||||
{
|
||||
var lbl = new Label { FontSize = 14 };
|
||||
lbl.SetBinding(Label.TextProperty, "Value1");
|
||||
var grd = new Grid();
|
||||
var boxView = new BoxView
|
||||
{
|
||||
BackgroundColor = Color.Transparent,
|
||||
HorizontalOptions = LayoutOptions.FillAndExpand,
|
||||
VerticalOptions = LayoutOptions.FillAndExpand
|
||||
};
|
||||
var gesture = new TapGestureRecognizer();
|
||||
gesture.SetBinding(TapGestureRecognizer.CommandProperty, "SomeCommand");
|
||||
boxView.GestureRecognizers.Add(gesture);
|
||||
grd.Children.Add(lbl);
|
||||
grd.Children.Add(boxView);
|
||||
View = grd;
|
||||
}
|
||||
}
|
||||
|
||||
void SomeCommandAction(object obj)
|
||||
{
|
||||
}
|
||||
|
||||
async Task FillData()
|
||||
{
|
||||
await Task.Factory.StartNew(async () =>
|
||||
{
|
||||
await Task.Delay(100);
|
||||
LocalList.Clear();
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
LocalList.Add(new LocalIem()
|
||||
{
|
||||
Value1 = DateTime.UtcNow.Ticks.ToString(),
|
||||
});
|
||||
}
|
||||
}, CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Default);
|
||||
}
|
||||
|
||||
[Preserve(AllMembers = true)]
|
||||
class LocalIem
|
||||
{
|
||||
public string Value1 { get; set; }
|
||||
}
|
||||
|
||||
#if UITEST
|
||||
[Test]
|
||||
public void GitHub1567Test()
|
||||
{
|
||||
RunningApp.WaitForElement(q => q.Marked("btnFillData"));
|
||||
RunningApp.Tap(q => q.Marked("btnFillData"));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
|
@ -341,6 +341,7 @@
|
|||
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla60524.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla59925.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Issue1436.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)GitHub1567.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Issue1909.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)_Template.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla42620.cs" />
|
||||
|
|
|
@ -552,7 +552,8 @@ namespace Xamarin.Forms.Platform.iOS
|
|||
Control.EndUpdates();
|
||||
|
||||
if (_estimatedRowHeight && TemplatedItemsView.TemplatedItems.Count == 0)
|
||||
_estimatedRowHeight = false;
|
||||
InvalidateCellCache();
|
||||
|
||||
|
||||
break;
|
||||
|
||||
|
@ -576,7 +577,7 @@ namespace Xamarin.Forms.Platform.iOS
|
|||
Control.EndUpdates();
|
||||
|
||||
if (_estimatedRowHeight && e.OldStartingIndex == 0)
|
||||
_estimatedRowHeight = false;
|
||||
InvalidateCellCache();
|
||||
|
||||
break;
|
||||
|
||||
|
@ -588,17 +589,24 @@ namespace Xamarin.Forms.Platform.iOS
|
|||
Control.EndUpdates();
|
||||
|
||||
if (_estimatedRowHeight && e.OldStartingIndex == 0)
|
||||
_estimatedRowHeight = false;
|
||||
InvalidateCellCache();
|
||||
|
||||
|
||||
break;
|
||||
|
||||
case NotifyCollectionChangedAction.Reset:
|
||||
_estimatedRowHeight = false;
|
||||
InvalidateCellCache();
|
||||
Control.ReloadData();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void InvalidateCellCache()
|
||||
{
|
||||
_estimatedRowHeight = false;
|
||||
_dataSource.InvalidatePrototypicalCellCache();
|
||||
}
|
||||
|
||||
void UpdatePullToRefreshEnabled()
|
||||
{
|
||||
if (_tableViewController != null)
|
||||
|
@ -703,6 +711,7 @@ namespace Xamarin.Forms.Platform.iOS
|
|||
|
||||
internal override void InvalidatePrototypicalCellCache()
|
||||
{
|
||||
ClearPrototype();
|
||||
_prototypicalCellByTypeOrDataTemplate.Clear();
|
||||
}
|
||||
|
||||
|
@ -792,15 +801,22 @@ namespace Xamarin.Forms.Platform.iOS
|
|||
|
||||
if (disposing)
|
||||
{
|
||||
if (_prototype != null)
|
||||
{
|
||||
_prototype.Dispose();
|
||||
_prototype = null;
|
||||
}
|
||||
ClearPrototype();
|
||||
}
|
||||
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
void ClearPrototype()
|
||||
{
|
||||
if (_prototype != null)
|
||||
{
|
||||
var element = _prototype.Element;
|
||||
element?.ClearValue(Platform.RendererProperty);
|
||||
_prototype?.Dispose();
|
||||
_prototype = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal class ListViewDataSource : UITableViewSource
|
||||
|
|
Загрузка…
Ссылка в новой задаче