TaLinh / JellyGif

Lightweight, performant, and memory efficient Gif framework
MIT License
34 stars 10 forks source link

Delet Item in CollectionView or TableView #7

Open zizlak opened 3 years ago

zizlak commented 3 years ago

Hello, there is an issue when function .deleteItems(at: [IndexPath]) called - it is necessary to call .reloadData() to update gifs correctly; but in that case we lost this smooth animation of deleting the item or row. Is it possible to move cells and update their content without calling reloadData()?

TaLinh commented 3 years ago

Hi @zizlak Just want to be sure that I understand the problem, you tried to delete the data and then call .deleteItems(at: [IndexPath]) and the gifs are not updated correctly?

zizlak commented 3 years ago

Hi @TaLinh Yes, exactly.

zizlak commented 3 years ago

Here is an example:

https://user-images.githubusercontent.com/50722317/121798103-adb2d780-cc24-11eb-8da2-32f3a7ac427a.mov

TaLinh commented 3 years ago

It looks like the animator array is not in sync with the tableView/collectionView data. Can you share the code you're using to update the array?

zizlak commented 3 years ago

That is the problem: I just delete the item in collectionView:

            Persistancy.context.delete(item)
            Persistancy.saveContext()

            self.collectionView.filteredItems = FilterTags.shared.filteredItems
            self.collectionView.deleteItems(at: [indexPath])

And the array is not being updated because the function collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) is not being called.

I tried to update the array mannualy:

            for index in self.collectionView.animators.keys.sorted() {
                if index.item >= indexPath.item {
                    let next = IndexPath(index: index.item + 1)
                    self.collectionView.animators[index] = self.collectionView.animators[next]
                    self.collectionView.animators[index]?.startAnimation()
                }
            }

But in that case, animation doesn't start automatically, only after scrolling. I thought there is some other default solution.