Skip to content

Commit 740dcb2

Browse files
committed
Fixed movement unvalilable sections.
1 parent 8a356cc commit 740dcb2

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

Sources/SPDiffable/DataSource/SPDiffableCollectionDataSource.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,12 @@ open class SPDiffableCollectionDataSource: UICollectionViewDiffableDataSource<SP
9797
// Reoder
9898

9999
for (sectionIndex, section) in sections.enumerated() {
100-
let beforeSectionIndex = sectionIndex - 1
101-
guard (sections.count > beforeSectionIndex) && (beforeSectionIndex >= 0) else { continue }
102-
let afterSection = sections[beforeSectionIndex]
103-
snapshot.moveSection(section, afterSection: afterSection)
100+
let previousSectionIndex = sectionIndex - 1
101+
guard (sections.count > previousSectionIndex) && (previousSectionIndex >= 0) else { continue }
102+
let previousSection = sections[previousSectionIndex]
103+
guard snapshot.sectionIdentifiers.first(where: { $0.identifier == section.identifier }) else { continue }
104+
guard snapshot.sectionIdentifiers.first(where: { $0.identifier == previousSection.identifier }) else { continue }
105+
snapshot.moveSection(section, afterSection: previousSection)
104106
}
105107

106108
// Apply Sections Changes

0 commit comments

Comments
 (0)