mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-11-27 20:15:29 +00:00
Fixed fast scroll button crashing while scrolling to undefined position
This commit is contained in:
parent
70cb52b2c7
commit
dd76a74e1c
@ -186,9 +186,17 @@ fun setHidden(view: FloatingActionButton, hide: Boolean) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@BindingAdapter("scrollPosition", "scrollPositionSmooth", requireAll = false)
|
@BindingAdapter("scrollPosition", "scrollPositionSmooth", requireAll = false)
|
||||||
fun setScrollPosition(view: RecyclerView, position: Int, smoothScroll: Boolean) = when {
|
fun setScrollPosition(view: RecyclerView, position: Int, smoothScroll: Boolean) {
|
||||||
smoothScroll -> view.smoothScrollToPosition(position)
|
val adapterItemCount = view.adapter?.itemCount ?: -1
|
||||||
else -> view.scrollToPosition(position)
|
if (position !in 0 until adapterItemCount) {
|
||||||
|
// the position is not in adapter bounds, adapter will throw exception for invalid positions
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
when {
|
||||||
|
smoothScroll -> view.smoothScrollToPosition(position)
|
||||||
|
else -> view.scrollToPosition(position)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@BindingAdapter("recyclerScrollEvent")
|
@BindingAdapter("recyclerScrollEvent")
|
||||||
|
Loading…
Reference in New Issue
Block a user