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 data source index OOB crash #110

Merged
merged 1 commit into from
Aug 4, 2022

Conversation

bryankeller
Copy link
Contributor

Details

This is an alternative fix / approach to fixing the data source count / internal model state mismatch that occurs when UICollectionView requests layout attributes before the layout has been notified about incoming batch updates.

This bug became an issue after the layout loop fix PR was merged last week. That PR changed how we create layout attributes (no longer done in prepareLayout, and instead done lazily as layout attributes are requested for specific index paths). This behavior change assumed that UICollectionView would never try to request layout attributes for out-of-bounds index paths. Unfortunately, this is not a safe assumption.

This PR changes our layout attributes creation code so that it returns nil if we detect an out-of-bounds index path. This is effectively how MagazineLayout behaved prior to the layout loop fix PR. Reverting this behavior has no impact on the layout loop fix, which will continue to work.

Also note that I'm not bumping the version / pushing a new release. I'll verify this works properly in the Airbnb iOS app, and if all looks good, then I'll push a new tag / make a new release.

Related Issue

N/A

Motivation and Context

Fix a crash.

How Has This Been Tested

Example app

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.

@bryankeller bryankeller added the bug Something isn't working label Aug 4, 2022
Copy link

@brynbodayle brynbodayle left a comment

Choose a reason for hiding this comment

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

🤞

@bryankeller bryankeller merged commit d2eb5c5 into master Aug 4, 2022
@bryankeller bryankeller deleted the bk/fix-data-source-index-oob-crash branch August 4, 2022 22:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants