Open james-ff opened 4 years ago
Hi @james-ff, I had the same error. It was a stupid mistake:
private var films = [Film]() {
didSet { self.cardSwiper.reloadData() }
}
...
func willSwipeCardAway(card: CardCell, index: Int, swipeDirection: SwipeDirection) {
guard index < self.films.count else { return }
self.films.remove(at: index)
}
I just removed didSet and it worked.
Do you want the card to swipe away without having to update the datasource to reflect this? Or just block the card from swiping away?
To me personally it seems weird to want your datasource out of sync with the actual displayed data, I think this is why Apple does this too? I'm just forwarding the UICollectionView
for the most part anyways.
Blocking the card from swiping away matches my intent here.
Hope that clarifies it. In the meantime I add the item back in if the confirmation is cancelled.
Hi @james-ff ,
I was able to achieve this by modifying internal func didSwipeAway
method in VerticalCardSwiper.swift class, from:
internal func didSwipeAway(cell: CardCell, swipeDirection direction: SwipeDirection) {
if let indexPathToRemove = self.verticalCardSwiperView.indexPath(for: cell) {
swipedCard = nil
self.verticalCardSwiperView.performBatchUpdates({
self.verticalCardSwiperView.deleteItems(at: [indexPathToRemove])
}, completion: { [weak self] _ in
self?.verticalCardSwiperView.collectionViewLayout.invalidateLayout()
self?.verticalCardSwiperView.isUserInteractionEnabled = true
self?.delegate?.didSwipeCardAway?(card: cell, index: indexPathToRemove.row, swipeDirection: direction)
})
}
}
to:
internal func didSwipeAway(cell: CardCell, swipeDirection direction: SwipeDirection) {
if let indexPathToRemove = self.verticalCardSwiperView.indexPath(for: cell) {
swipedCard = nil
self.verticalCardSwiperView.performBatchUpdates({
if direction == .left {
self.verticalCardSwiperView.deleteItems(at: [indexPathToRemove])
}
}, completion: { [weak self] _ in
self?.verticalCardSwiperView.collectionViewLayout.invalidateLayout()
self?.verticalCardSwiperView.isUserInteractionEnabled = true
self?.delegate?.didSwipeCardAway?(card: cell, index: indexPathToRemove.row, swipeDirection: direction)
})
}
}
Hope this helps.
New Issue Checklist
Is your feature request related to a problem? Please describe.
If I do not remove the swiped item from the datasource an error occurs
Describe the solution you'd like
I would like to configure the cardSwiper view to not remove an item when it is swiped (instead trigger an action), and later on when that action finishes I can remove the item programmatically.
Describe alternatives you've considered
I've considered re-adding the removed item immediately, but It feels like this would be a hack solution, which might cause strange animations
Additional context
none