-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Closed
Labels
area-controls-collectionviewCollectionView, CarouselView, IndicatorViewCollectionView, CarouselView, IndicatorViewdelighter-schighIt doesn't work at all, crashes or has a big impact.It doesn't work at all, crashes or has a big impact.platform/androidt/bugSomething isn't workingSomething isn't working
Milestone
Description
Description
If you add a Header to the CollectionView, then when you drag an element to the end of the list, a crash will occur.
System.ArgumentOutOfRangeException: 'Index was out of range. Must be non-negative and less than or equal to the size of the collection. (Parameter 'index')'
Steps to Reproduce
- Create CollectionView with Header
- Drag item to the end of the collection
Link to public reproduction project repository
No response
Version with bug
7.0.92
Is this a regression from previous behavior?
No, this is something new
Last version that worked well
Unknown/Other
Affected platforms
Android
Affected platform versions
No response
Did you find any workaround?
You need to make a change to the code of the class Microsoft.Maui.Controls.Handlers.Items.ReorderableItemsViewAdapter
private readonly bool _hasHeader; // <- add this
public ReorderableItemsViewAdapter(TItemsView reorderableItemsView,
Func<View, Context, ItemContentView> createView = null) : base(reorderableItemsView, createView)
{
_hasHeader = reorderableItemsView.Header is not null; // <- add this
}Change it
else if (itemsView.ItemsSource is IList list)
{
var fromItem = list[fromPosition];
SetObserveChanges(itemsSource, false);
list.RemoveAt(fromPosition);
list.Insert(toPosition, fromItem);
NotifyItemMoved(fromPosition, toPosition);
SetObserveChanges(itemsSource, true);
itemsView.SendReorderCompleted();
return true;
}to something like that
else if (itemsView.ItemsSource is IList list)
{
var sourceFromPosition = _hasHeader ? fromPosition - 1 : fromPosition;
var sourceToPosition = _hasHeader ? toPosition - 1 : toPosition;
var fromItem = list[sourceFromPosition];
SetObserveChanges(itemsSource, false);
list.RemoveAt(sourceFromPosition);
list.Insert(sourceToPosition, fromItem);
NotifyItemMoved(fromPosition, toPosition);
SetObserveChanges(itemsSource, true);
itemsView.SendReorderCompleted();
return true;
}Relevant log output
> 0x1ED in Microsoft.Maui.Controls.Handlers.Items.ReorderableItemsViewAdapter<Microsoft.Maui.Controls.ReorderableItemsView,Microsoft.Maui.Controls.Handlers.Items.IGroupableItemsViewSource>.OnItemMove at D:\Downloads\maui-main\src\Controls\src\Core\Handlers\Items\Android\Adapters\ReorderableItemsViewAdapter.cs:69,5 C#
0x2D in Microsoft.Maui.Controls.Handlers.Items.SimpleItemTouchHelperCallback.OnMove at D:\Downloads\maui-main\src\Controls\src\Core\Handlers\Items\Android\SimpleItemTouchHelperCallback.cs:36,4 C#Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area-controls-collectionviewCollectionView, CarouselView, IndicatorViewCollectionView, CarouselView, IndicatorViewdelighter-schighIt doesn't work at all, crashes or has a big impact.It doesn't work at all, crashes or has a big impact.platform/androidt/bugSomething isn't workingSomething isn't working