Skip to content

Commit

Permalink
Fix scroll handler
Browse files Browse the repository at this point in the history
This weakref was not sticking around, so reverting back to a normal delegate.

Fixes #33
  • Loading branch information
Redth committed Apr 18, 2024
1 parent 75c1bc9 commit 288eeaf
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
5 changes: 2 additions & 3 deletions VirtualListView/Apple/CvDelegate.ios.maccatalyst.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public CvDelegate(VirtualListViewHandler handler, UICollectionView collectionVie
internal readonly WeakReference<UICollectionView> NativeCollectionView;
internal readonly VirtualListViewHandler Handler;

public WeakReference<Action<NFloat, NFloat>> ScrollHandler { get; set; }
public Action<NFloat, NFloat> ScrollHandler { get; set; }

Check warning on line 20 in VirtualListView/Apple/CvDelegate.ios.maccatalyst.cs

View workflow job for this annotation

GitHub Actions / Build

Member 'ScrollHandler' could cause memory leaks in an NSObject subclass. Remove the member, store the value as a WeakReference, or add the

Check warning on line 20 in VirtualListView/Apple/CvDelegate.ios.maccatalyst.cs

View workflow job for this annotation

GitHub Actions / Build

Member 'ScrollHandler' could cause memory leaks in an NSObject subclass. Remove the member, store the value as a WeakReference, or add the

Check warning on line 20 in VirtualListView/Apple/CvDelegate.ios.maccatalyst.cs

View workflow job for this annotation

GitHub Actions / Build

Member 'ScrollHandler' could cause memory leaks in an NSObject subclass. Remove the member, store the value as a WeakReference, or add the

Check warning on line 20 in VirtualListView/Apple/CvDelegate.ios.maccatalyst.cs

View workflow job for this annotation

GitHub Actions / Build

Member 'ScrollHandler' could cause memory leaks in an NSObject subclass. Remove the member, store the value as a WeakReference, or add the

Check warning on line 20 in VirtualListView/Apple/CvDelegate.ios.maccatalyst.cs

View workflow job for this annotation

GitHub Actions / Build

Member 'ScrollHandler' could cause memory leaks in an NSObject subclass. Remove the member, store the value as a WeakReference, or add the

Check warning on line 20 in VirtualListView/Apple/CvDelegate.ios.maccatalyst.cs

View workflow job for this annotation

GitHub Actions / Build

Member 'ScrollHandler' could cause memory leaks in an NSObject subclass. Remove the member, store the value as a WeakReference, or add the

Check warning on line 20 in VirtualListView/Apple/CvDelegate.ios.maccatalyst.cs

View workflow job for this annotation

GitHub Actions / Build

Member 'ScrollHandler' could cause memory leaks in an NSObject subclass. Remove the member, store the value as a WeakReference, or add the

Check warning on line 20 in VirtualListView/Apple/CvDelegate.ios.maccatalyst.cs

View workflow job for this annotation

GitHub Actions / Build

Member 'ScrollHandler' could cause memory leaks in an NSObject subclass. Remove the member, store the value as a WeakReference, or add the

Check warning on line 20 in VirtualListView/Apple/CvDelegate.ios.maccatalyst.cs

View workflow job for this annotation

GitHub Actions / Build

Member 'ScrollHandler' could cause memory leaks in an NSObject subclass. Remove the member, store the value as a WeakReference, or add the

Check warning on line 20 in VirtualListView/Apple/CvDelegate.ios.maccatalyst.cs

View workflow job for this annotation

GitHub Actions / Build

Member 'ScrollHandler' could cause memory leaks in an NSObject subclass. Remove the member, store the value as a WeakReference, or add the

public override void ItemSelected(UICollectionView collectionView, NSIndexPath indexPath)
=> HandleSelection(collectionView, indexPath, true);
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ protected override void ConnectHandler(UICollectionView nativeView)
dataSource = new CvDataSource(this);

cvdelegate = new CvDelegate(this, nativeView);
cvdelegate.ScrollHandler = new WeakReference<Action<System.Runtime.InteropServices.NFloat, System.Runtime.InteropServices.NFloat>>((x, y) =>
VirtualView?.Scrolled(x, y));
cvdelegate.ScrollHandler = (x, y) => VirtualView?.Scrolled(x, y);

nativeView.DataSource = dataSource;
nativeView.Delegate = cvdelegate;
Expand Down

0 comments on commit 288eeaf

Please sign in to comment.