mirror of
https://github.com/leaf-wai/StackLayoutManager.git
synced 2026-07-13 03:11:19 +08:00
Fix on items not being removed and crash on scroll
This commit is contained in:
@@ -264,6 +264,9 @@ class StackLayoutManager(scrollOrientation: ScrollOrientation,
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun canScrollHorizontally(): Boolean {
|
override fun canScrollHorizontally(): Boolean {
|
||||||
|
if (itemCount == 0) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
return when (mScrollOrientation) {
|
return when (mScrollOrientation) {
|
||||||
ScrollOrientation.LEFT_TO_RIGHT, ScrollOrientation.RIGHT_TO_LEFT -> true
|
ScrollOrientation.LEFT_TO_RIGHT, ScrollOrientation.RIGHT_TO_LEFT -> true
|
||||||
else -> false
|
else -> false
|
||||||
@@ -271,6 +274,9 @@ class StackLayoutManager(scrollOrientation: ScrollOrientation,
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun canScrollVertically(): Boolean {
|
override fun canScrollVertically(): Boolean {
|
||||||
|
if (itemCount == 0) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
return when (mScrollOrientation) {
|
return when (mScrollOrientation) {
|
||||||
ScrollOrientation.TOP_TO_BOTTOM, ScrollOrientation.BOTTOM_TO_TOP -> true
|
ScrollOrientation.TOP_TO_BOTTOM, ScrollOrientation.BOTTOM_TO_TOP -> true
|
||||||
else -> false
|
else -> false
|
||||||
@@ -278,18 +284,16 @@ class StackLayoutManager(scrollOrientation: ScrollOrientation,
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onLayoutChildren(recycler: RecyclerView.Recycler, state: RecyclerView.State) {
|
override fun onLayoutChildren(recycler: RecyclerView.Recycler, state: RecyclerView.State) {
|
||||||
if (itemCount == 0) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
mLayout?.requestLayout()
|
mLayout?.requestLayout()
|
||||||
|
|
||||||
removeAndRecycleAllViews(recycler)
|
removeAndRecycleAllViews(recycler)
|
||||||
|
|
||||||
|
if (itemCount > 0) {
|
||||||
mScrollOffset = getValidOffset(mScrollOffset)
|
mScrollOffset = getValidOffset(mScrollOffset)
|
||||||
|
|
||||||
loadItemView(recycler)
|
loadItemView(recycler)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun scrollHorizontallyBy(dx: Int, recycler: RecyclerView.Recycler, state: RecyclerView.State): Int {
|
override fun scrollHorizontallyBy(dx: Int, recycler: RecyclerView.Recycler, state: RecyclerView.State): Int {
|
||||||
return handleScrollBy(dx, recycler)
|
return handleScrollBy(dx, recycler)
|
||||||
|
|||||||
Reference in New Issue
Block a user