question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CollectionView Drag & Drop Item Reordering Spec

See original GitHub issue

Description

Support drag-and-drop item reordering in the CollectionView.

The CollectionView handlers should use the built-in item reordering functionality provided by the platforms:

Reordering should require the CollectionView.ItemsSource be bound to an IList. The platform handlers will use the Remove & Insert methods on the IList to complete the reorder operation.

Example https://github.com/billvenhaus/ReorderableCollectionView.Maui

reorderablecollectionview_ios

(Public) API Changes

Place the new reorder functionality in a separate class that the CollectionView can inherit.

CollectionView

public class CollectionView : ReorderableItemsView
{
}

ReorderableItemsView

public class ReorderableItemsView : GroupableItemsView
{
	public static readonly BindableProperty CanMixGroupsProperty;
	public bool CanMixGroups { get; set; }

	public static readonly BindableProperty CanReorderItemsProperty;
	public bool CanReorderItems { get; set; }

	public event EventHandler ReorderCompleted;
}

Properties

API Description
CanReorderItems Gets or sets a value that indicates whether items in the view can be reordered through user interaction.
CanMixGroups Gets or sets a value that indicates whether items from different groups can be mixed during reordering.

Events

API Description
ReorderCompleted Raised whenever reordering user interaction completes.

Usage Scenarios

Basic Item Reordering

The developer has an app which manages the playlist for a media player. The user needs to be able to make changes to the track order by rearranging the songs with drag-and-drop. How can the developer achieve this UI with the proposed API?

In order to achieve this behavior, the developer should set the CollectionView.CanReorderItems property to true. They can be notified of changes to the song order by subscribing to the ReorderCompleted event. At that point the developer can save the changes to the playlist storage location.

Reordering with Grouped Sources (Mixing Items)

The developer has a grouped data source & wishes to mix items. Items in group A can be placed in group B, and items in group B can be placed in group A. How can the developer achieve this with the proposed API?

In order to achieve this behavior, the developer should set both CollectionView.CanReorderItems & CollectionView.CanMixGroups to true.

Detailed Events

The ReorderCompleted is a basic EventHandler that doesn’t provide any information about the item that moved. How can the developer determine which item moved & where it moved to?

The developer should bind the CollectionView.ItemsSource to an ObservableCollection if they need to know specific details about the item that moved. The CollectionChanged event of the ObservableCollection can provide that information.

Backward Compatibility

Minimum API Levels:

  • Available on all API levels.

Breaking Changes:

  • No breaking changes.

Unsupported Platforms:

  • Windows reordering only works with ObservableCollections
  • Windows reordering does not support grouped sources (see here)

Difficulty

Medium

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:5
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

5reactions
jfversluiscommented, Dec 16, 2021

Just came here to say that this spec is amazing, exactly as I would love to see them, thank you for this @billvenhaus !

1reaction
AmrAlSayed0commented, Dec 15, 2021

Reordering should require the CollectionView.ItemsSource be bound to an IList.

Weird, one would think that ObservableCollection is the obvious choice here. Any reason for not having it be a INCC instead? Nevermind, you already subscribe to INCC in your pull request!

Good job on the PR! 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

CollectionView Drag & Drop Item Reordering with Gesture ...
The Drag and Drop gesture recognizers can help you to trigger the reordering logic, defined by a view model, that holds the collection....
Read more >
UICollectionView Drag and Drop Reorder Items
When dropping the item "9" in the new position you delete the item from the position it was and insert it in a...
Read more >
Drag-and-Drop Operations in Collection View for .NET MAUI
The DXCollectionView supports drag-and-drop operations and allows users to reorder items. A user should touch and hold a data item, and then drag...
Read more >
Catalyst by Tutorials, Chapter 3: Drag & Drop
Once you have the photos, you prepend them to the entry and add a number of items at the start of the collection...
Read more >
Drag, Drop & Reorder Collection View Cells into One or ...
Drag, Drop & Reorder Collection View Cells into One or More UICollectionView ... The last step is to implement the reorder items method....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found