summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamantha Houts <samantha@teamredwall.com>2016-09-27 06:43:17 -0700
committerRui Marinho <me@ruimarinho.net>2016-09-27 14:43:17 +0100
commitc83c830c68bc0da08f330457dc6901f1657b86f5 (patch)
tree9c376e66dfea3e9d64cbed2ee21d9b540f8f3fae
parent6aa96a43915edaa8fa03ab9bf5abf00fd424f3f1 (diff)
downloadxamarin-forms-c83c830c68bc0da08f330457dc6901f1657b86f5.tar.gz
xamarin-forms-c83c830c68bc0da08f330457dc6901f1657b86f5.tar.bz2
xamarin-forms-c83c830c68bc0da08f330457dc6901f1657b86f5.zip
[UWP/WinRT] ListView UI virtualization works without explicit height on Cell/Row (#367)
* Add repro for 41271 * [UWP/WinRT] ListView virtualization works without explicit height on Cell/Row * Adjust repro to clear ItemsSource OnDisappearing. * Update docs
-rw-r--r--Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla41271.cs107
-rw-r--r--Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems1
-rw-r--r--Xamarin.Forms.Core/Cells/Cell.cs3
-rw-r--r--Xamarin.Forms.Platform.WinRT/CellControl.cs4
-rw-r--r--docs/Xamarin.Forms.Core/Xamarin.Forms/Cell.xml16
5 files changed, 129 insertions, 2 deletions
diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla41271.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla41271.cs
new file mode 100644
index 00000000..5c545634
--- /dev/null
+++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla41271.cs
@@ -0,0 +1,107 @@
+using System.Collections.Generic;
+using Xamarin.Forms.CustomAttributes;
+using Xamarin.Forms.Internals;
+
+namespace Xamarin.Forms.Controls
+{
+ [Preserve(AllMembers = true)]
+ [Issue(IssueTracker.Bugzilla, 41271, "[UWP] Memory Leak from ListView in TabbedPage")]
+ public class Bugzilla41271 : TestTabbedPage
+ {
+ [Preserve(AllMembers = true)]
+ class Person
+ {
+ public Person(string firstName, string lastName, string city, string state)
+ {
+ FirstName = firstName;
+ LastName = lastName;
+ City = city;
+ State = state;
+ }
+ public string FirstName { get; set; }
+ public string LastName { get; set; }
+ public string City { get; set; }
+ public string State { get; set; }
+ }
+ [Preserve(AllMembers = true)]
+ class ListViewCell : ViewCell
+ {
+ Label firstNameLabel = new Label();
+ Label lastNameLabel = new Label();
+ Label cityLabel = new Label();
+ Label stateLabel = new Label();
+
+ public ListViewCell()
+ {
+ View = new StackLayout
+ {
+ Orientation = StackOrientation.Horizontal,
+ Children =
+ {
+ firstNameLabel,
+ lastNameLabel,
+ cityLabel,
+ stateLabel
+ }
+ };
+ }
+
+ protected override void OnBindingContextChanged()
+ {
+ base.OnBindingContextChanged();
+ var item = BindingContext as Person;
+ if (item != null)
+ {
+ firstNameLabel.Text = item.FirstName;
+ lastNameLabel.Text = item.LastName;
+ cityLabel.Text = item.City;
+ stateLabel.Text = item.State;
+ }
+ }
+ }
+ [Preserve(AllMembers = true)]
+ class ListViewPage : ContentPage
+ {
+ ListView _ListView;
+ List<Person> _People = new List<Person>();
+
+ public ListViewPage(string id)
+ {
+ Title = $"List {id}";
+
+ for (var x = 0; x < 1000; x++)
+ {
+ _People.Add(new Person("Bob", "Bobson", "San Francisco", "California"));
+ }
+
+ _ListView = new ListView(ListViewCachingStrategy.RecycleElement) { ItemTemplate = new DataTemplate(typeof(ListViewCell)) };
+ Content = _ListView;
+ }
+
+ protected override void OnAppearing()
+ {
+ base.OnAppearing();
+
+ _ListView.ItemsSource = _People;
+ }
+
+ protected override void OnDisappearing()
+ {
+ base.OnDisappearing();
+
+ _ListView.ItemsSource = null;
+ }
+ }
+
+ protected override void Init()
+ {
+ var counter = 1;
+
+ for (var x = 0; x < 10; x++)
+ {
+ Children.Add(new ListViewPage(counter.ToString()));
+ counter++;
+ }
+ }
+ }
+} \ No newline at end of file
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 7a47c10f..427a3845 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
@@ -182,6 +182,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla33561.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla43214.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla43161.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)Bugzilla41271.cs" />
<Compile Include="$(MSBuildThisFileDirectory)_Template.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue1028.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue1075.cs" />
diff --git a/Xamarin.Forms.Core/Cells/Cell.cs b/Xamarin.Forms.Core/Cells/Cell.cs
index 863e0342..d434b564 100644
--- a/Xamarin.Forms.Core/Cells/Cell.cs
+++ b/Xamarin.Forms.Core/Cells/Cell.cs
@@ -9,6 +9,7 @@ namespace Xamarin.Forms
{
public abstract class Cell : Element, ICellController
{
+ public const int DefaultCellHeight = 40;
public static readonly BindableProperty IsEnabledProperty = BindableProperty.Create("IsEnabled", typeof(bool), typeof(Cell), true, propertyChanged: OnIsEnabledPropertyChanged);
ObservableCollection<MenuItem> _contextActions;
@@ -70,7 +71,7 @@ namespace Xamarin.Forms
if (list != null)
return list.HasUnevenRows && Height > 0 ? Height : list.RowHeight;
- return 40;
+ return DefaultCellHeight;
}
}
diff --git a/Xamarin.Forms.Platform.WinRT/CellControl.cs b/Xamarin.Forms.Platform.WinRT/CellControl.cs
index eb06e688..0ad7adfd 100644
--- a/Xamarin.Forms.Platform.WinRT/CellControl.cs
+++ b/Xamarin.Forms.Platform.WinRT/CellControl.cs
@@ -97,7 +97,9 @@ namespace Xamarin.Forms.Platform.WinRT
}
}
- return new Windows.Foundation.Size(0, 0);
+ // This needs to return a size with a non-zero height;
+ // otherwise, it kills virtualization.
+ return new Windows.Foundation.Size(0, Cell.DefaultCellHeight);
}
// Children still need measure called on them
diff --git a/docs/Xamarin.Forms.Core/Xamarin.Forms/Cell.xml b/docs/Xamarin.Forms.Core/Xamarin.Forms/Cell.xml
index 77456af1..1d4cdf8b 100644
--- a/docs/Xamarin.Forms.Core/Xamarin.Forms/Cell.xml
+++ b/docs/Xamarin.Forms.Core/Xamarin.Forms/Cell.xml
@@ -195,6 +195,22 @@ Content = new TableView
<remarks>The context gesture on the iOS platform is a left swipe. For Android and Windows Phone operating systems, the context gesture is a press and hold.</remarks>
</Docs>
</Member>
+ <Member MemberName="DefaultCellHeight">
+ <MemberSignature Language="C#" Value="public const int DefaultCellHeight = 40;" />
+ <MemberSignature Language="ILAsm" Value=".field public static literal int32 DefaultCellHeight = (40)" />
+ <MemberType>Field</MemberType>
+ <AssemblyInfo>
+ <AssemblyVersion>2.0.0.0</AssemblyVersion>
+ </AssemblyInfo>
+ <ReturnValue>
+ <ReturnType>System.Int32</ReturnType>
+ </ReturnValue>
+ <MemberValue>40</MemberValue>
+ <Docs>
+ <summary>To be added.</summary>
+ <remarks>To be added.</remarks>
+ </Docs>
+ </Member>
<Member MemberName="Disappearing">
<MemberSignature Language="C#" Value="public event EventHandler Disappearing;" />
<MemberSignature Language="ILAsm" Value=".event class System.EventHandler Disappearing" />