Skip to content

Commit

Permalink
Adjust index path for cell reuseid in carouselview (dotnet#15140)
Browse files Browse the repository at this point in the history
* Adjust index path for cell reuseid in carouselview

Since CarouselView uses a fake number of items for looping effect like android does, we also need to correct the index used in the base items controller to be the actual item index, not the looped one.

* Fix return

* Remove ifdef for net8, we are net8

This was also masking the public api txt warnings, but have added the unshipped api's as well.
  • Loading branch information
Redth authored and Michael Cao committed May 22, 2023
1 parent 85f8b10 commit 109e0cc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,7 @@ public override void UpdateItemsSource()

protected override UICollectionViewDelegateFlowLayout CreateDelegator() => new CarouselViewDelegator(ItemsViewLayout, this);

#if NET8_0_OR_GREATER
[Obsolete("Use DetermineCellReuseId(NSIndexPath indexPath) instead.")]
#endif
protected override string DetermineCellReuseId()
{
if (Carousel.ItemTemplate != null)
Expand All @@ -145,6 +143,12 @@ protected override string DetermineCellReuseId()
return base.DetermineCellReuseId();
}

protected override string DetermineCellReuseId(NSIndexPath indexPath)
{
var itemIndex = GetIndexFromIndexPath(indexPath);
return base.DetermineCellReuseId(NSIndexPath.FromItemSection(itemIndex, 0));
}

protected override void RegisterViewTypes()
{
CollectionView.RegisterClassForCell(typeof(CarouselTemplatedCell), CarouselTemplatedCell.ReuseId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,12 +338,7 @@ protected virtual void CacheCellAttributes(NSIndexPath indexPath, CGSize size)
}
}

#if NET8_0_OR_GREATER
protected
#else
internal
#endif
virtual string DetermineCellReuseId(NSIndexPath indexPath)
protected virtual string DetermineCellReuseId(NSIndexPath indexPath)
{
if (ItemsView.ItemTemplate != null)
{
Expand All @@ -370,9 +365,7 @@ virtual string DetermineCellReuseId(NSIndexPath indexPath)
: VerticalDefaultCell.ReuseId;
}

#if NET8_0_OR_GREATER
[Obsolete("Use DetermineCellReuseId(NSIndexPath indexPath) instead.")]
#endif
protected virtual string DetermineCellReuseId()
{
if (ItemsView.ItemTemplate != null)
Expand Down

0 comments on commit 109e0cc

Please sign in to comment.