HFCardCollectionViewLayout icon indicating copy to clipboard operation
HFCardCollectionViewLayout copied to clipboard

Background updates management

Open Alex293 opened this issue 8 years ago • 9 comments

Hi,

I'm looking to connect this to some realm db which update from background sometimes. Is there an api to update the layout without disturbing the user (no animations, same selection) ?

Alex293 avatar Mar 27 '17 19:03 Alex293

I don't understand what you mean. Can you explain your problem? ;-)

Maybe the following code helps:

UIView.performWithoutAnimation {
  // updating the layout
}

hfrahmann avatar Mar 28 '17 19:03 hfrahmann

In my app I have sometimes background update to my collection data. When this occurs I use collectionView.performBatchUpdates. I'd like to do this without calling animations.

I think this as more to to with the collection than your layout but I'm looking for pointers

Alex293 avatar Mar 29 '17 09:03 Alex293

UIView.performWithoutAnimation { // updating the layout } is a good start.

Alex293 avatar Mar 29 '17 11:03 Alex293

The main issue I have is that the selection is not kept when I do an update. I tried to go around with disabling animation the manually selecting the previous selected item but the are still small flash.

My goal is when there is no selection it add a card like in the demo but when there is a selection the selection not changed and the row is added silently

Alex293 avatar Mar 29 '17 16:03 Alex293

An easy way to see what I'm fighting in the example is to replace : if(self.colorArray.count == 1 || self.cardCollectionViewLayout!.revealedIndex >= 0) { self.cardCollectionViewLayout?.unrevealCard(completion: { self.colorArray.insert(self.getRandomColor(), at: index) self.collectionView?.insertItems(at: [IndexPath(item: index, section: 0)]) }) } else { self.colorArray.insert(self.getRandomColor(), at: index) self.collectionView?.insertItems(at: [IndexPath(item: index, section: 0)]) } with : self.colorArray.insert(self.getRandomColor(), at: index) self.collectionView?.insertItems(at: [IndexPath(item: index, section: 0)])

Alex293 avatar Mar 29 '17 17:03 Alex293

OK, now i know what you mean. :-) But it's not so simple to fix.

hfrahmann avatar Mar 29 '17 20:03 hfrahmann

To achieve the right behavior I have to create my own UICollectionView (extend) and overwrite some methods (insertItems(at indexPaths: [IndexPath])).

hfrahmann avatar Mar 29 '17 21:03 hfrahmann

Can you post what works for you I'll extend the collection in my project so you don't have to change the structure of your lib

Alex293 avatar Mar 30 '17 08:03 Alex293

If you only have the problem for inserting items, with the new version you can use the HFCardCollectionView or copy the call of the helper method to your own class.

class HFCardCollectionView: UICollectionView {

    override func insertItems(at indexPaths: [IndexPath]) {
        if let collectionViewLayout = self.collectionViewLayout as? HFCardCollectionViewLayout {
            collectionViewLayout.willInsert(indexPaths: indexPaths)
        }
        super.insertItems(at: indexPaths)
    }

}

I hope this helps. ;-)

And you don't need the UIView.performWithoutAnimation{} method if you just insert new items.

hfrahmann avatar Apr 02 '17 10:04 hfrahmann