@@ -85,13 +85,34 @@ open class SPDiffableCollectionDataSource: UICollectionViewDiffableDataSource<SP
85
85
86
86
// Update current sections.
87
87
88
+ // If you don't use composition layout, no way say to collection system
89
+ // about header elements. Its using random, sometimes its
90
+ // cell provider call, sometimes it call supplementary.
91
+ // In this case we shoudn't set header to section snapshot.
92
+ // For this case it condition only.
93
+ let headerAsFirstElement : Bool = {
94
+ if collectionView? . collectionViewLayout is UICollectionViewFlowLayout {
95
+ return false
96
+ }
97
+ if collectionView? . collectionViewLayout is UICollectionViewCompositionalLayout {
98
+ return true
99
+ }
100
+ return true
101
+ } ( )
102
+
88
103
for section in sections {
89
104
var sectionSnapshot = SPDiffableSectionSnapshot ( )
90
- let header = section. header
91
- if let header = header {
92
- sectionSnapshot. append ( [ header] )
105
+
106
+ if headerAsFirstElement {
107
+ let header = section. header
108
+ if let header = header {
109
+ sectionSnapshot. append ( [ header] )
110
+ }
111
+ sectionSnapshot. append ( section. items, to: header)
112
+ } else {
113
+ sectionSnapshot. append ( section. items)
93
114
}
94
- sectionSnapshot . append ( section . items , to : header )
115
+
95
116
sectionSnapshot. expand ( sectionSnapshot. items)
96
117
apply ( sectionSnapshot, to: section, animatingDifferences: animated)
97
118
}
0 commit comments