This repository has been archived by the owner on May 1, 2024. It is now read-only.
[iOS] Fix hard crash when horizontal GridViewLayout is refreshed #7612
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.
Description of Change
Not sure if this is the right fix. When horizontal GridViewLayout is refreshed via a pull gesture, the application crashes. Previously, the code was trying to calculate missing cell count based on layout span. If you run the attached test, you'll see that
base.LayoutAttributesForElementsInRect(rect)
returns 9 items even though there are 8 visible items on the screen. The code calculated missing cell count to be 2 even though it should be 1. Consequently, we ended up with an index out of bounds error.The fix allocates
UICollectionViewLayoutAttributes[]
based on the number of items in section 0, copies existing attributes from base, and appends new ones.@hartez Do we need to change the Wikipedia image URLs?
@hartez @jfversluis @samhouts @jsuarezruiz Also, when the loading spinner is shown, the CollectionView seems to be resized, which forces it to show 3 rows of items instead of 4 before the next batch of items is added to the items source. Can you confirm if this is a bug or expected behavior? (Tested on XS)
Issues Resolved
Testing Procedure
PR Checklist