-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix crash on scroll position restoration #1606
Conversation
@@ -107,7 +107,7 @@ internal open class ViewLazyList private constructor( | |||
val viewsOnScreen = recyclerView.children.map { recyclerView.getChildViewHolder(it).bindingAdapterPosition } | |||
userHasScrolled = true // Prevent guest code from hijacking the scrollbar. | |||
onViewportChanged?.invoke( | |||
viewsOnScreen.min(), | |||
viewsOnScreen.min().coerceAtLeast(0), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.min()
sometimes returns -1 (which had been observed / is expected)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-1 is NO_POSITION
which is what is returned for all positions between adapter invalidations and the next layout pass.
Also min
and max
throw if the sequence is empty, are we assuming the scroll callback will never be invoked on an empty list?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also min and max throw if the sequence is empty, are we assuming the scroll callback will never be invoked on an empty list?
ahhh 🤔, that's the case (not invoked on empty list) so far (this has only only been applied to emoji search). But it's not guaranteed the invocation wouldn't happen on an empty list (someone else might use it, or other teams might use it).
-1 is NO_POSITION which is what is returned for all positions between adapter invalidations and the next layout pass.
👍
I need another round of internal release when this is in. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Fixes: #1604