This repository has been archived by the owner on Nov 4, 2022. It is now read-only.
Add dragDroppingItems
to accumulate changes & update dragDropConfig.dataBinding
only once per drag-drop reorder
#206
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi there 👋
This PR adds an improvement in CollectionView (and also TableView)'s drag-drop reordering
which reduces "removed -> inserted" dance (2 calls) into 1 move only (1 call).
By applying this, I think it will be more SwiftUI-engine-friendly to only have 1 update per
@Binding
change.Also, this fix is needed when CollectionView's items are derived from other single-source-of-truth via its state's binding transformation e.g. this code.
For example, if domain's
@ObservableObject
owns an array ofN
elements, and there's ViewModel that ownsN + 1
elements (N
comes from domain, and additional 1 element is for view-specific reason), we will eventually map$observableObject.item as Binding<[Domain.Item]>
toBinding<[CollectionView.Item]>
by using the aboveBinding.transform
(or similar) function.But if "removed -> inserted" occurs inside ASCollectionView, it will be difficult for domain (user-side) to recover the inserted view-item back to domain-item because view-item is usually only a part of domain-item.
On the other side, if view-items are just reordered without item loss, it's easy for domain to reorder its domain-items since the order of view-item's ID only matters.
What do you think?