Skip to content

Commit cc8437a

Browse files
authored
Update WardRecycler.kt
Fix Cannot call this method in a scroll callback. Scroll callbacks might be run during a measure & layout pass where you cannot change theRecyclerView data. Any method call that might change the structure of the RecyclerView or the adapter contents should be postponed to the next frame.
1 parent 12c4088 commit cc8437a

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

wrecycler/src/main/java/com/ward/wrecycler/WardRecycler.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,9 @@ open class WardRecycler @JvmOverloads constructor(context: Context, attributeSet
9393
private fun showProgressBar() {
9494

9595
progressView.visibility = View.VISIBLE
96-
recyclerView.invalidateItemDecorations()
97-
96+
recyclerView.post{
97+
recyclerView.invalidateItemDecorations()
98+
}
9899
}
99100

100101
init {
@@ -183,7 +184,9 @@ open class WardRecycler @JvmOverloads constructor(context: Context, attributeSet
183184
swipeRefreshLayout.isRefreshing = false
184185
}
185186
progressView.visibility = GONE
186-
recyclerView.invalidateItemDecorations()
187+
recyclerView.post{
188+
recyclerView.invalidateItemDecorations()
189+
}
187190
}
188191

189192
fun setAdapter(adapter: RecyclerView.Adapter<*>) {
@@ -194,4 +197,4 @@ open class WardRecycler @JvmOverloads constructor(context: Context, attributeSet
194197
swipeRefreshLayout.setColorSchemeColors(*colors)
195198
}
196199

197-
}
200+
}

0 commit comments

Comments
 (0)