From 288eeaf5a6a91a31fabcb0913476d1533eda515a Mon Sep 17 00:00:00 2001 From: redth Date: Thu, 18 Apr 2024 19:50:37 -0400 Subject: [PATCH] Fix scroll handler This weakref was not sticking around, so reverting back to a normal delegate. Fixes #33 --- VirtualListView/Apple/CvDelegate.ios.maccatalyst.cs | 5 ++--- .../Apple/VirtualListViewHandler.ios.maccatalyst.cs | 3 +-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/VirtualListView/Apple/CvDelegate.ios.maccatalyst.cs b/VirtualListView/Apple/CvDelegate.ios.maccatalyst.cs index 3870a0a..b1deabe 100644 --- a/VirtualListView/Apple/CvDelegate.ios.maccatalyst.cs +++ b/VirtualListView/Apple/CvDelegate.ios.maccatalyst.cs @@ -17,7 +17,7 @@ public CvDelegate(VirtualListViewHandler handler, UICollectionView collectionVie internal readonly WeakReference NativeCollectionView; internal readonly VirtualListViewHandler Handler; - public WeakReference> ScrollHandler { get; set; } + public Action ScrollHandler { get; set; } public override void ItemSelected(UICollectionView collectionView, NSIndexPath indexPath) => HandleSelection(collectionView, indexPath, true); @@ -49,8 +49,7 @@ void HandleSelection(UICollectionView collectionView, NSIndexPath indexPath, boo public override void Scrolled(UIScrollView scrollView) { - if (ScrollHandler?.TryGetTarget(out var handler) ?? false) - handler?.Invoke(scrollView.ContentOffset.X, scrollView.ContentOffset.Y); + ScrollHandler?.Invoke(scrollView.ContentOffset.X, scrollView.ContentOffset.Y); } public override bool ShouldSelectItem(UICollectionView collectionView, NSIndexPath indexPath) diff --git a/VirtualListView/Apple/VirtualListViewHandler.ios.maccatalyst.cs b/VirtualListView/Apple/VirtualListViewHandler.ios.maccatalyst.cs index 90a5579..6879f42 100644 --- a/VirtualListView/Apple/VirtualListViewHandler.ios.maccatalyst.cs +++ b/VirtualListView/Apple/VirtualListViewHandler.ios.maccatalyst.cs @@ -62,8 +62,7 @@ protected override void ConnectHandler(UICollectionView nativeView) dataSource = new CvDataSource(this); cvdelegate = new CvDelegate(this, nativeView); - cvdelegate.ScrollHandler = new WeakReference>((x, y) => - VirtualView?.Scrolled(x, y)); + cvdelegate.ScrollHandler = (x, y) => VirtualView?.Scrolled(x, y); nativeView.DataSource = dataSource; nativeView.Delegate = cvdelegate;