Repository navigation
fix(list-view): handle reusing wrong view - #9023
Merged
Merged
Conversation
edusperoni
marked this pull request as draft
November 11, 2020 16:34
Contributor
Author
|
I believe most of the issues will be fixed with #8904, so I converted this to a draft. That said, this can be merged in the future to always have a safeguard against these types of crashes. |
edusperoni
marked this pull request as ready for review
November 11, 2020 21:36
Contributor
Author
|
After further investigation this issue can occur on a normally functioning app that changes the dataset quickly. I haven't managed to reproduce it in tests but I believe performance is a factor (probably a race condition), which is difficult to emulate. The current test scenario should cover it, though. |
NathanWalker
approved these changes
Nov 12, 2020
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Checklist
What is the current behavior?
public getView(index: number, convertView: android.view.View, parent: android.view.ViewGroup): android.view.Viewnever checks ifconvertViewis of the right type for the template. This usually isn't an issue because android callsgetItemViewType(index: number)to check if the view is of the correct type (template). If for some reason the items have changed mid-execution, though,getItemViewType(index: number)will return a different template from what the view actually is.Scenario 1
Consider this scenario (listview where only 2 items are visible):
While rendering
red, items change toYou'll see the wrong representation because it should never change view types, but it did.
This is happening:
This mainly happens because we're first instantiating a template, then we pass this template to
itemLoadingwhich changes it, and then we're using the new data. Ideally these changes should never happen onitemLoading, but they sometimes do because #8904 isn't merged yet.Scenario 2
Like scenario 1, the dataset has changed mid-render (seems to happen randomly when a few frames are lost), so ListView correctly identifies that the index is of template X but when it checks again, it's now of template Y
What is the new behavior?
We always check if the correct template is being used. This may sometimes still show an inconsistent listview (like in the example above, we still show
redon top even though it should be green), but it will not crash anymore.I'm not sure of why this issue started happening still.
Fixes #6284.