You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Unlike viewpager, for viewpager2, the onPageScrolled handler is called when the view is first rendered. However, the following code snippet assumes there will always be a next page. This causes an index out of range exception crash.
This is happening for v4.1.1
funonPageScrolled(position:Int, positionOffset:Float) {
var offset = (position + positionOffset)
val lastPageIndex = (pageCount -1).toFloat()
if (offset == lastPageIndex) {
offset = lastPageIndex - .0001f
}
val leftPosition = offset.toInt()
val rightPosition = leftPosition +1<-- lastPageIndex is taken into account, but right position is still assumed to be left +1 even when left and right are the same position for a 1 page viewpager
onPageScrolled(leftPosition, rightPosition, offset %1)
if (lastLeftPosition !=-1) {
if (leftPosition > lastLeftPosition) {
(lastLeftPosition until leftPosition).forEach {
resetPosition(it)
}
}
if (rightPosition < lastRightPosition) {
resetPosition(lastRightPosition)
((rightPosition +1)..lastRightPosition).forEach {
resetPosition(it)
}
}
}
lastLeftPosition = leftPosition
lastRightPosition = rightPosition
}
Specifically the crash happens on this line.
overridefunonPageScrolled(selectedPosition:Int, nextPosition:Int, positionOffset:Float) {
val x = (dots[selectedPosition].parent asViewGroup).left.toFloat()
val nextX = (dots[if (nextPosition ==-1) selectedPosition else nextPosition].parent asViewGroup).left <--- dots[nextPosition] is now left position +1 which isout of range.
.toFloat()
val xFinalPosition:Floatval widthFinalPosition:Floatwhen (positionOffset) {
in0.0f..0.1f-> {
xFinalPosition = x
widthFinalPosition = dotsSize
}
in0.1f..0.9f-> {
xFinalPosition = x
widthFinalPosition = nextX - x + dotsSize
}
else-> {
xFinalPosition = nextX
widthFinalPosition = dotsSize
}
}
dotIndicatorXSpring?.animateToFinalPosition(xFinalPosition)
dotIndicatorWidthSpring?.animateToFinalPosition(widthFinalPosition)
}
The text was updated successfully, but these errors were encountered:
Unlike viewpager, for viewpager2, the onPageScrolled handler is called when the view is first rendered. However, the following code snippet assumes there will always be a next page. This causes an index out of range exception crash.
This is happening for v4.1.1
Specifically the crash happens on this line.
The text was updated successfully, but these errors were encountered: