@@ -110,32 +110,35 @@ class RecyclerSectionItemDecoration(context: Context,
110110 val topChild = parent.getChildAt(0 ) ? : return
111111 val topChildPosition = parent.getChildAdapterPosition(topChild)
112112 headerView?.let {
113- val sectionInfo = sectionCallback.getSectionHeader(topChildPosition)
114- previousHeader = sectionInfo
115- setHeaderView(sectionInfo)
116- val offset =
117- if (topChildPosition == 0
118- && childInContact.top - (headerOffset * 2 ) == (- 1 * headerOffset)) 0f
119- else
120- (childInContact.top - (headerOffset * 2 )).toFloat()
121-
122- moveHeader(c, it, offset)
113+ sectionCallback.getSectionHeader(topChildPosition)?.let { sectionInfo ->
114+ previousHeader = sectionInfo
115+ setHeaderView(sectionInfo)
116+ val offset =
117+ if (topChildPosition == 0
118+ && childInContact.top - (headerOffset * 2 ) == (- 1 * headerOffset)) 0f
119+ else
120+ (childInContact.top - (headerOffset * 2 )).toFloat()
121+
122+ moveHeader(c, it, offset)
123+ }
123124 }
124125 }
125126 }
126127
127128 for (i in 0 until parent.childCount) {
128129 val child = parent.getChildAt(i)
129130 val position = parent.getChildAdapterPosition(child)
130- val sectionInfo = sectionCallback.getSectionHeader(position)
131- setHeaderView(sectionInfo)
132- if (previousHeader != sectionInfo) {
133- headerView?.let {
134- drawHeader(c, child, it)
135- previousHeader = sectionInfo
136- }
131+ sectionCallback.getSectionHeader(position)?. let { sectionInfo ->
132+ setHeaderView(sectionInfo)
133+ if (previousHeader != sectionInfo) {
134+ headerView?.let {
135+ drawHeader(c, child, it)
136+ previousHeader = sectionInfo
137+ }
137138
139+ }
138140 }
141+
139142 }
140143 }
141144
@@ -245,7 +248,7 @@ class RecyclerSectionItemDecoration(context: Context,
245248
246249 fun isSection (position : Int ): Boolean
247250
248- fun getSectionHeader (position : Int ): SectionInfo
251+ fun getSectionHeader (position : Int ): SectionInfo ?
249252 }
250253}
251254
0 commit comments