diff --git a/Lib/SwiftUI/PagingCollectionViewController.swift b/Lib/SwiftUI/PagingCollectionViewController.swift index 3969f1e..df15aa0 100644 --- a/Lib/SwiftUI/PagingCollectionViewController.swift +++ b/Lib/SwiftUI/PagingCollectionViewController.swift @@ -56,16 +56,28 @@ public class PagingCollectionViewController 0 { + collectionView?.reloadItems(at: needsUpdateList.map({ IndexPath(item: $0, section: 0) })) + } else { + collectionView?.reloadData() + } layout.invalidateLayoutInBatchUpdate(invalidateOffset: true) } let index = currentIndex ?? layout.currentPage @@ -149,12 +161,18 @@ public class PagingCollectionViewController(as list: [T]) -> Bool + func listDiff(as list: [T]) -> [Int]? } extension PagingCollectionViewController: PagingCollectionViewControllerEquatableList where ValueType: Equatable { func isListSame(as list: [T]) -> Bool { self.list == (list as? [ValueType]) } + + func listDiff(as list: [T]) -> [Int]? { + guard let list = list as? [ValueType] else { return nil } + return self.list.listDiffIndex(otherList: list) + } } private extension UICollectionView { @@ -173,3 +191,18 @@ private extension UICollectionViewCell { String(describing: self) } } + +private extension Array where Element: Equatable { + func listDiffIndex(otherList: [T]) -> [Int]? { + if self.count != otherList.count { + return nil + } + var diff: [Int] = [] + for index in 0..