Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

inamiy
Copy link
Contributor

@inamiy inamiy commented Mar 7, 2021

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 of N elements, and there's ViewModel that owns N + 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]> to Binding<[CollectionView.Item]> by using the above Binding.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?

…g.dataBinding` only once per drag-drop reorder
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant