Skip to content

Commit

Permalink
Remove extra layer of caching from iOS datasource
Browse files Browse the repository at this point in the history
  • Loading branch information
Redth committed Jul 26, 2023
1 parent 06d1e8d commit 8730ff6
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 59 deletions.
3 changes: 3 additions & 0 deletions Sample/VirtualListViewSample/SectionedAdapterPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
x:Name="vlv"
SelectedItemsChanged="vlv_SelectedItemsChanged"
SelectionMode="Single">
<vlv:VirtualListView.EmptyView>
<Label Text="Empty!" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" />
</vlv:VirtualListView.EmptyView>
<vlv:VirtualListView.SectionHeaderTemplate>
<DataTemplate>
<Border
Expand Down
53 changes: 2 additions & 51 deletions VirtualListView/Apple/CvDataSource.ios.maccatalyst.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,8 @@ public CvDataSource(VirtualListViewHandler handler)
readonly ReusableIdManager sectionHeaderIdManager = new ReusableIdManager("SectionHeader", new NSString("SectionHeader"));
readonly ReusableIdManager sectionFooterIdManager = new ReusableIdManager("SectionFooter", new NSString("SectionFooter"));

int? cachedNumberOfSections;
internal int CachedNumberOfSections
{
get
{
if (!cachedNumberOfSections.HasValue)
{
var n = Handler?.PositionalViewSelector?.Adapter?.Sections ?? -1;
if (n >= 0)
cachedNumberOfSections = n;
}

return cachedNumberOfSections ?? 0;
}
}

public override nint NumberOfSections(UICollectionView collectionView)
=> CachedNumberOfSections;
=> Handler?.PositionalViewSelector?.GetNumberOfSections() ?? 0;

public override UICollectionViewCell GetCell(UICollectionView collectionView, NSIndexPath indexPath)
{
Expand Down Expand Up @@ -105,39 +89,6 @@ void TapCellHandler(CvCell cell)

public override nint GetItemsCount(UICollectionView collectionView, nint section)
{
var realSection = section;

if (Handler?.PositionalViewSelector?.HasGlobalHeader ?? false)
{
if (section == 0)
return 1;

realSection--;
}

if (Handler?.PositionalViewSelector?.HasGlobalFooter ?? false)
{
if (section >= CachedNumberOfSections - 1)
return 1;
}

var itemsCount = Handler?.PositionalViewSelector?.Adapter?.ItemsForSection((int)realSection) ?? 0;

if (Handler?.PositionalViewSelector?.ViewSelector?.SectionHasHeader((int)realSection) ?? false)
itemsCount++;

if (Handler?.PositionalViewSelector?.ViewSelector?.SectionHasFooter((int)realSection) ?? false)
itemsCount++;

return (nint)itemsCount;
}

public void Reset(UICollectionView collectionView)
{
//itemIdManager.ResetTemplates(collectionView);
//sectionHeaderIdManager.ResetTemplates(collectionView);
//sectionFooterIdManager.ResetTemplates(collectionView);

cachedNumberOfSections = null;
return Handler?.PositionalViewSelector?.GetNumberOfItemsForSection(section.ToInt32()) ?? 0;
}
}
8 changes: 0 additions & 8 deletions VirtualListView/Apple/CvDelegate.ios.maccatalyst.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,6 @@ void HandleSelection(UICollectionView collectionView, NSIndexPath indexPath, boo
else
Handler?.VirtualView?.DeselectItems(itemPos);
}

//var updatedVisibleRect = collectionView.ConvertRectToView(collectionView.Bounds, selectedCell);

//var contentOffset = collectionView.ContentOffset;
//contentOffset.X = contentOffset.X + (visibleRect.X - updatedVisibleRect.X);
//collectionView.ContentOffset = contentOffset;

//UIView.AnimationsEnabled = true;
}

public override void Scrolled(UIScrollView scrollView)
Expand Down

0 comments on commit 8730ff6

Please sign in to comment.