Skip to content

Commit 3c6e6e4

Browse files
committed
fix(listview): [WASM] Support removing item while dragging
Fixes error that could occur when removing an item from collection while it was being dragged.
1 parent d3cc1d4 commit 3c6e6e4

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/Uno.UI/UI/Xaml/Controls/ItemsStackPanel/ItemsStackPanelLayout.managed.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ partial class ItemsStackPanelLayout
2121

2222
protected override Line CreateLine(GeneratorDirection fillDirection, double extentOffset, double availableBreadth, Uno.UI.IndexPath nextVisibleItem)
2323
{
24-
if (ShouldInsertReorderingView(extentOffset))
24+
if (ShouldInsertReorderingView(extentOffset) && GetAndUpdateReorderingIndex() is { } reorderingIndex)
2525
{
26-
nextVisibleItem = GetAndUpdateReorderingIndex().Value;
26+
nextVisibleItem = reorderingIndex;
2727
}
2828

2929
var item = GetFlatItemIndex(nextVisibleItem);

src/Uno.UI/UI/Xaml/Controls/ListViewBase/VirtualizingPanelLayout.managed.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,8 +1094,12 @@ protected bool ShouldInsertReorderingView(double extentOffset)
10941094
{
10951095
if (reorder.index is null)
10961096
{
1097-
reorder.index = XamlParent!.GetIndexPathFromItem(reorder.item);
1098-
_pendingReorder = reorder; // _pendingReorder is a struct!
1097+
var itemIndex = XamlParent!.GetIndexPathFromItem(reorder.item);
1098+
if (itemIndex.Row >= 0) // GetIndexPathFromItem() will return Row=-1 if item is not found, which may happen eg if it's been removed from the collection during dragging. Prefer to leave index null in this case.
1099+
{
1100+
reorder.index = itemIndex;
1101+
_pendingReorder = reorder; // _pendingReorder is a struct!
1102+
}
10991103
}
11001104

11011105
return reorder.index;

0 commit comments

Comments
 (0)