diff --git a/VirtualListView/Apple/CvCell.ios.maccatalyst.cs b/VirtualListView/Apple/CvCell.ios.maccatalyst.cs index 0fdc3d8..53c0877 100644 --- a/VirtualListView/Apple/CvCell.ios.maccatalyst.cs +++ b/VirtualListView/Apple/CvCell.ios.maccatalyst.cs @@ -1,6 +1,7 @@ using CoreGraphics; using Foundation; using Microsoft.Maui.Platform; +using Microsoft.VisualBasic; using System.Diagnostics.CodeAnalysis; using UIKit; @@ -12,7 +13,7 @@ internal class CvCell : UICollectionViewCell public WeakReference IndexPath { get; set; } - public PositionInfo PositionInfo { get; set; } + public PositionInfo PositionInfo { get; private set; } public WeakReference> ReuseCallback { get; set; } @@ -109,31 +110,32 @@ public override void PrepareForReuse() } } - public void SwapView(IView newView) + public void SetupView(IView view) { // Create a new platform native view if we don't have one yet if (!(NativeView?.TryGetTarget(out var nativeView) ?? false)) { - nativeView = newView.ToPlatform(this.Handler.MauiContext); + nativeView = view.ToPlatform(this.Handler.MauiContext); nativeView.Frame = this.ContentView.Frame; nativeView.AutoresizingMask = UIViewAutoresizing.FlexibleHeight | UIViewAutoresizing.FlexibleWidth; this.ContentView.AddSubview(nativeView); NativeView = new WeakReference(nativeView); } - // Create a new virtual view if we don't have one yet - if (!(VirtualView?.TryGetTarget(out var virtualView) ?? false) || (virtualView?.Handler is null)) - { - virtualView = newView; - VirtualView = new WeakReference(virtualView); - } - else + if (!(VirtualView?.TryGetTarget(out var virtualView) ?? false) || (virtualView?.Handler is null)) + { + virtualView = view; + VirtualView = new WeakReference(virtualView); + } + } + + public void UpdatePosition(PositionInfo positionInfo) + { + PositionInfo = positionInfo; + if (VirtualView?.TryGetTarget(out var virtualView) ?? false) { - var handler = virtualView.Handler; - virtualView.Handler = null; - newView.Handler = handler; - handler.SetVirtualView(newView); - VirtualView.SetTarget(newView); - } + if (virtualView is IPositionInfo viewPositionInfo) + viewPositionInfo.Update(positionInfo); + } } } \ No newline at end of file diff --git a/VirtualListView/Apple/CvDataSource.ios.maccatalyst.cs b/VirtualListView/Apple/CvDataSource.ios.maccatalyst.cs index 96119e4..cf0873c 100644 --- a/VirtualListView/Apple/CvDataSource.ios.maccatalyst.cs +++ b/VirtualListView/Apple/CvDataSource.ios.maccatalyst.cs @@ -58,16 +58,13 @@ public override UICollectionViewCell GetCell(UICollectionView collectionView, NS if (cell.NeedsView) { var view = Handler?.PositionalViewSelector?.ViewSelector?.CreateView(info, data); - cell.SwapView(view); + cell.SetupView(view); } - cell.PositionInfo = info; + cell.UpdatePosition(info); if (cell.VirtualView.TryGetTarget(out var cellVirtualView)) { - if (cellVirtualView is IPositionInfo viewPositionInfo) - viewPositionInfo.IsSelected = info.IsSelected; - Handler?.PositionalViewSelector?.ViewSelector?.RecycleView(info, data, cellVirtualView); Handler.VirtualView.ViewSelector.ViewAttached(info, cellVirtualView);