Skip to content

Commit 6281032

Browse files
committed
Fixed logic after reoder.
1 parent 8d8fd79 commit 6281032

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

SPDiffable.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |s|
22

33
s.name = 'SPDiffable'
4-
s.version = '1.3.6'
4+
s.version = '1.3.7'
55
s.summary = 'Extenshion of Diffable API which allow not duplicate code and use less models.'
66
s.homepage = 'https://github.com/ivanvorobei/SPDiffable'
77
s.source = { :git => 'https://github.com/ivanvorobei/SPDiffable.git', :tag => s.version }

Sources/SPDiffable/DataSource/SPDiffableCollectionDataSource.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,17 @@ open class SPDiffableCollectionDataSource: UICollectionViewDiffableDataSource<SP
9494
apply(snapshot, animated: true)
9595
}
9696

97+
// Reoder sections
98+
99+
for (sectionIndex, section) in sections.enumerated() {
100+
let previousSectionIndex = sectionIndex - 1
101+
guard (sections.count > previousSectionIndex) && (previousSectionIndex >= 0) else { continue }
102+
let previousSection = sections[previousSectionIndex]
103+
guard let _ = snapshot.sectionIdentifiers.first(where: { $0.identifier == section.identifier }) else { continue }
104+
guard let _ = snapshot.sectionIdentifiers.first(where: { $0.identifier == previousSection.identifier }) else { continue }
105+
snapshot.moveSection(section, afterSection: previousSection)
106+
}
107+
97108
// Add new sections and update current sections
98109

99110
for section in sections {
@@ -113,17 +124,6 @@ open class SPDiffableCollectionDataSource: UICollectionViewDiffableDataSource<SP
113124
apply(sectionSnapshot, to: section, animatingDifferences: animated)
114125
}
115126

116-
// Reoder sections
117-
118-
for (sectionIndex, section) in sections.enumerated() {
119-
let previousSectionIndex = sectionIndex - 1
120-
guard (sections.count > previousSectionIndex) && (previousSectionIndex >= 0) else { continue }
121-
let previousSection = sections[previousSectionIndex]
122-
guard let _ = snapshot.sectionIdentifiers.first(where: { $0.identifier == section.identifier }) else { continue }
123-
guard let _ = snapshot.sectionIdentifiers.first(where: { $0.identifier == previousSection.identifier }) else { continue }
124-
snapshot.moveSection(section, afterSection: previousSection)
125-
}
126-
127127
// Apply changes
128128

129129
apply(snapshot, animated: true)

0 commit comments

Comments
 (0)