@@ -82,9 +82,9 @@ open class SPDiffableCollectionDataSource: UICollectionViewDiffableDataSource<SP
82
82
public func apply( _ sections: [ SPDiffableSection ] , animated: Bool ) {
83
83
if #available( iOS 14 , * ) {
84
84
85
- var snapshot = self . snapshot ( )
85
+ // Remove section if it deleted from content.
86
86
87
- // Remove section if it deleted from content
87
+ var snapshot = self . snapshot ( )
88
88
89
89
let deletedSections = snapshot. sectionIdentifiers. filter ( { ( checkSection) -> Bool in
90
90
return !sections. contains ( where: { $0. identifier == checkSection. identifier } )
@@ -94,7 +94,7 @@ open class SPDiffableCollectionDataSource: UICollectionViewDiffableDataSource<SP
94
94
apply ( snapshot, animated: true )
95
95
}
96
96
97
- // Reoder sections
97
+ // Reoder
98
98
99
99
for (sectionIndex, section) in sections. enumerated ( ) {
100
100
let previousSectionIndex = sectionIndex - 1
@@ -105,7 +105,11 @@ open class SPDiffableCollectionDataSource: UICollectionViewDiffableDataSource<SP
105
105
snapshot. moveSection ( section, afterSection: previousSection)
106
106
}
107
107
108
- // Add new sections and update current sections
108
+ // Apply Sections Changes
109
+
110
+ apply ( snapshot, animated: true )
111
+
112
+ // Update current sections.
109
113
110
114
for section in sections {
111
115
var sectionSnapshot = SPDiffableSectionSnapshot ( )
@@ -123,11 +127,6 @@ open class SPDiffableCollectionDataSource: UICollectionViewDiffableDataSource<SP
123
127
sectionSnapshot. expand ( sectionSnapshot. items)
124
128
apply ( sectionSnapshot, to: section, animatingDifferences: animated)
125
129
}
126
-
127
- // Apply changes
128
-
129
- apply ( snapshot, animated: true )
130
-
131
130
} else {
132
131
var snapshot = SPDiffableSnapshot ( )
133
132
snapshot. appendSections ( sections)
0 commit comments