Skip to content

Commit 3fb3bd8

Browse files
committed
Remove proxy class, use weakref
1 parent 515ae01 commit 3fb3bd8

File tree

2 files changed

+6
-17
lines changed

2 files changed

+6
-17
lines changed

VirtualListView/Apple/CvCell.ios.maccatalyst.cs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public CvCell(CGRect frame) : base(frame)
2222
this.ContentView.AddGestureRecognizer(new UITapGestureRecognizer(() => InvokeTap()));
2323
}
2424

25-
public TapHandlerProxy TapHandler { get; set; }
25+
public WeakReference<Action<CvCell>> TapHandler { get; set; }
2626

2727
WeakReference<UIKeyCommand[]> keyCommands;
2828

@@ -55,7 +55,10 @@ public void KeyCommandSelect()
5555
void InvokeTap()
5656
{
5757
if (PositionInfo.Kind == PositionKind.Item)
58-
TapHandler?.Invoke(this);
58+
{
59+
if (TapHandler?.TryGetTarget(out var handler) ?? false)
60+
handler?.Invoke(this);
61+
}
5962
}
6063

6164
public void UpdateSelected(bool selected)
@@ -133,18 +136,4 @@ public void SwapView(IView newView)
133136
VirtualView.SetTarget(newView);
134137
}
135138
}
136-
137-
public class TapHandlerProxy
138-
{
139-
public TapHandlerProxy(Action<CvCell> tapHandler)
140-
{
141-
TapHandler = tapHandler;
142-
}
143-
144-
public Action<CvCell> TapHandler { get; set; }
145-
146-
public void Invoke(CvCell cell)
147-
=> TapHandler?.Invoke(cell);
148-
149-
}
150139
}

VirtualListView/Apple/CvDataSource.ios.maccatalyst.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public override UICollectionViewCell GetCell(UICollectionView collectionView, NS
4040
};
4141

4242
var cell = collectionView.DequeueReusableCell(nativeReuseId, indexPath) as CvCell;
43-
cell.TapHandler = new CvCell.TapHandlerProxy(TapCellHandler);
43+
cell.TapHandler = new WeakReference<Action<CvCell>>(TapCellHandler);
4444
cell.Handler = Handler;
4545
cell.IndexPath = new WeakReference<NSIndexPath>(indexPath);
4646

0 commit comments

Comments
 (0)