Ramotion/expanding-collection

Strange card deletion animation

achirkof opened this issue · 2 comments

Hi!
Thanks for this amazing extension!

My question is how I can override card deletion animation which behaviour is strange.

remove_animation

As you can see on GIF when I tap green button it executes collectionView.deleteItems(at: indexPath) and animation is very strange.
First card climb to very top and then go down and disappearing.

I would like to card starting go down to the bottom from current position without rising up. How I can override CollectionViewFlowLayout attributes?

I made an extension to override deletion animation. But it didn't solve problem when card jumps top before deletion.

extension PageCollectionLayout {
    
    override func prepare(forCollectionViewUpdates updateItems: [UICollectionViewUpdateItem]) {
        super.prepare(forCollectionViewUpdates: updateItems)
        removingIndexPaths.removeAll()
        
        for update in updateItems {
            if let indexPath = update.indexPathBeforeUpdate, update.updateAction == .delete {
                removingIndexPaths.append(indexPath)
            }
        }
    }
    
    override func finalizeCollectionViewUpdates() {
        super.finalizeCollectionViewUpdates()
        removingIndexPaths.removeAll()
    }
    
    override func finalLayoutAttributesForDisappearingItem(at itemIndexPath: IndexPath) -> UICollectionViewLayoutAttributes? {
        let attributes = super.finalLayoutAttributesForDisappearingItem(at: itemIndexPath)
        
        if removingIndexPaths.contains(itemIndexPath) {
            attributes?.transform = CGAffineTransform(scaleX: 0.1, y: 0.1)
        }
        print(attributes)
        return attributes
    }
}

@aleksei1000000 could you please help me to understand why it happening?
Thanks

@ober01 great! Thank you very much! 🤝