From df31f04af086b88e10a0e2b4f0012c71cc744ac7 Mon Sep 17 00:00:00 2001 From: redth Date: Sat, 20 Apr 2024 14:00:39 -0400 Subject: [PATCH] Start adding support for invalidating specific items This will help with 'resetting' an item if you change a property such that you expect it to change the size of the cell. --- Sample/VirtualListViewSample/Section.cs | 16 +++++++++++++- .../VirtualListViewSample/SectionedAdapter.cs | 18 +++++++++++++--- .../SectionedAdapterPage.xaml | 21 ++++++++++++------- .../SectionedAdapterPage.xaml.cs | 12 +++++++++++ .../Adapters/IVirtualListViewAdapter.cs | 4 ++++ .../Adapters/InvalidateItemsEventArgs.cs | 11 ++++++++++ .../Adapters/VirtualListViewAdapterBase.cs | 10 +++++++++ .../VirtualListViewHandler.ios.maccatalyst.cs | 20 ++++++++++++++++++ VirtualListView/Controls/VirtualViewCell.cs | 2 ++ .../Android/VirtualListViewHandler.android.cs | 13 ++++++++++++ VirtualListView/Platforms/Windows/IrSource.cs | 7 +++++++ .../Windows/VirtualListViewHandler.windows.cs | 6 ++++++ VirtualListView/VirtualListViewHandler.cs | 13 +++++++++++- 13 files changed, 140 insertions(+), 13 deletions(-) create mode 100644 VirtualListView/Adapters/InvalidateItemsEventArgs.cs diff --git a/Sample/VirtualListViewSample/Section.cs b/Sample/VirtualListViewSample/Section.cs index 27d550e..69b84df 100644 --- a/Sample/VirtualListViewSample/Section.cs +++ b/Sample/VirtualListViewSample/Section.cs @@ -1,6 +1,20 @@ namespace VirtualListViewSample; -public class Section : List +public class Section : List { public string Title { get; set; } } + + +public class Item : BindableObject +{ + + public static readonly BindableProperty NameProperty = + BindableProperty.Create(nameof(Name), typeof(string), typeof(Item), string.Empty); + + public string Name + { + get => (string)GetValue(NameProperty); + set => SetValue(NameProperty, value); + } +} \ No newline at end of file diff --git a/Sample/VirtualListViewSample/SectionedAdapter.cs b/Sample/VirtualListViewSample/SectionedAdapter.cs index 5d10e11..1d971e8 100644 --- a/Sample/VirtualListViewSample/SectionedAdapter.cs +++ b/Sample/VirtualListViewSample/SectionedAdapter.cs @@ -2,7 +2,7 @@ namespace VirtualListViewSample; -public class SectionedAdapter : VirtualListViewAdapterBase +public class SectionedAdapter : VirtualListViewAdapterBase { public SectionedAdapter(IList
items) : base() { @@ -20,7 +20,7 @@ public override int GetNumberOfSections() public override int GetNumberOfItemsInSection(int sectionIndex) => Items[sectionIndex].Count; - public override string GetItem(int sectionIndex, int itemIndex) + public override Item GetItem(int sectionIndex, int itemIndex) => Items[sectionIndex][itemIndex]; public void AddItem(string sectionTitle, string itemName) @@ -33,7 +33,7 @@ public void AddItem(string sectionTitle, string itemName) Items.Add(section); } - section.Add(itemName); + section.Add(new Item { Name = itemName }); InvalidateData(); } @@ -51,4 +51,16 @@ public void RemoveItem(int sectionIndex, int itemIndex) InvalidateData(); } + + public void UpdateItem(int sectionIndex, int itemIndex) + { + var section = Items.ElementAtOrDefault(sectionIndex); + + if (section is null) + return; + + section[itemIndex].Name = $"{section[itemIndex].Name} Updated"; + + InvalidateItems(new ItemPosition(sectionIndex, itemIndex)); + } } \ No newline at end of file diff --git a/Sample/VirtualListViewSample/SectionedAdapterPage.xaml b/Sample/VirtualListViewSample/SectionedAdapterPage.xaml index f448b95..2465395 100644 --- a/Sample/VirtualListViewSample/SectionedAdapterPage.xaml +++ b/Sample/VirtualListViewSample/SectionedAdapterPage.xaml @@ -29,14 +29,19 @@ - - - + + + + +