Skip to content
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

Merged
merged 1 commit into from
Oct 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Copy link
Author

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)

Copy link
Collaborator

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?

Copy link
Author

@jingwei99 jingwei99 Oct 18, 2023

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.

👍

viewsOnScreen.max(),
)
}
Expand Down