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.
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?