Background updates management
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) ?
I don't understand what you mean. Can you explain your problem? ;-)
Maybe the following code helps:
UIView.performWithoutAnimation {
// updating the layout
}
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
UIView.performWithoutAnimation { // updating the layout } is a good start.
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
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)])
OK, now i know what you mean. :-) But it's not so simple to fix.
To achieve the right behavior I have to create my own UICollectionView (extend) and overwrite some methods (insertItems(at indexPaths: [IndexPath])).
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
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.