Skip to content

Commit

Permalink
fix(listview): [WASM] Support removing item while dragging
Browse files Browse the repository at this point in the history
Fixes error that could occur when removing an item from collection while it was being dragged.
  • Loading branch information
jeromelaban committed Nov 2, 2021
1 parent d3cc1d4 commit 3c6e6e4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ partial class ItemsStackPanelLayout

protected override Line CreateLine(GeneratorDirection fillDirection, double extentOffset, double availableBreadth, Uno.UI.IndexPath nextVisibleItem)
{
if (ShouldInsertReorderingView(extentOffset))
if (ShouldInsertReorderingView(extentOffset) && GetAndUpdateReorderingIndex() is { } reorderingIndex)
{
nextVisibleItem = GetAndUpdateReorderingIndex().Value;
nextVisibleItem = reorderingIndex;
}

var item = GetFlatItemIndex(nextVisibleItem);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1094,8 +1094,12 @@ protected bool ShouldInsertReorderingView(double extentOffset)
{
if (reorder.index is null)
{
reorder.index = XamlParent!.GetIndexPathFromItem(reorder.item);
_pendingReorder = reorder; // _pendingReorder is a struct!
var itemIndex = XamlParent!.GetIndexPathFromItem(reorder.item);
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.
{
reorder.index = itemIndex;
_pendingReorder = reorder; // _pendingReorder is a struct!
}
}

return reorder.index;
Expand Down

0 comments on commit 3c6e6e4

Please sign in to comment.