Skip to content
This repository was archived by the owner on Jun 17, 2023. It is now read-only.

Commit 9270421

Browse files
committed
Call reloadData from collection view when the list changes
1 parent d0a64c0 commit 9270421

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

Lib/SwiftUI/PagingCollectionViewController.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ public class PagingCollectionViewController<ValueType: Identifiable, PageContent
5757
// MARK: Internal functions
5858

5959
func update(list: [ValueType], currentIndex: Int?) {
60+
if needsToReloadData(list: list) {
61+
collectionView.performBatchUpdates({
62+
collectionView.reloadData()
63+
layout.invalidateLayoutInBatchUpdate()
64+
})
65+
}
6066
self.list = list
6167
let index = currentIndex ?? layout.currentPage
6268
if index < list.count {
@@ -82,7 +88,11 @@ public class PagingCollectionViewController<ValueType: Identifiable, PageContent
8288

8389

8490
// MARK: Private functions
85-
91+
92+
private func needsToReloadData(list: [ValueType]) -> Bool {
93+
self.list.map(\.id) != list.map(\.id)
94+
}
95+
8696
private func setupCollectionView() {
8797
collectionView = UICollectionView(
8898
frame: view.frame,

0 commit comments

Comments
 (0)