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

Conversation

jingwei99
Copy link

Fixes: #1604

@@ -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.

👍

@jingwei99
Copy link
Author

I need another round of internal release when this is in.

@jingwei99 jingwei99 merged commit 1353523 into trunk Oct 17, 2023
8 checks passed
@jingwei99 jingwei99 deleted the jingwei.fix_crash branch October 17, 2023 19:38
Copy link
Collaborator

@swankjesse swankjesse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Crash in emoji-search after scroll position preservation commit
3 participants