apptekstudios / ASCollectionView

A SwiftUI collection view with support for custom layouts, preloading, and more.
MIT License
1.35k stars 160 forks source link

Add `ASDragDropConfig.canDropItem` #207

Closed inamiy closed 3 years ago

inamiy commented 3 years ago

This PR adds ASDragDropConfig.canDropItem to prevent from dropping item "without cell-shifting animation".

Please note that this behavior is different from ASDragDropConfig.canMoveItem where item can't also be dropped by this configuration but still allows cell-shifting animation to make the current dragging place an empty space until dragging is finished.

Screencast

https://user-images.githubusercontent.com/138476/110242398-3b818580-7f99-11eb-9161-b07b4cf53e1c.mp4

First item is not droppable by following configuration:

    var dragDropConfig: ASDragDropConfig<Item> {
        ASDragDropConfig<Item>(dataBinding: $items)
            .canDragItem { $0.row != 0 }
            .canDropItem { $0.row != 0 } // First item is not droppable or move to make empty space
    }