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.
Details
This fixes #76 - a bug where
MagazineLayout
was assuming that it would only receive "valid" index paths when requesting layout attributes. The crash would occur if a developer passedIndexPath()
intolayoutAttributesForItemAt
. Flow layout avoids this crash by defaulting toIndexPath(item: 0, section: 0)
.Part of me feels like this is just flow layout working around some weird behavior / maybe trying to mirror a workaround table view had from the beginning. The documentation for IndexPath looks like this:
It specifically calls out that you should use the
init(item: Int, section: Int)
initializer when usingUICollectionView
. To me, this makes it seem like usingIndexPath()
is wrong / a programmer error.====
Why does collection view / table view even use index paths? Seems like the wrong abstraction to me.
IndexPath
s allow indexing into arbitrarily deep tree structures, which seems completely overboard for a UI component that only has 2 layers (section and item).Fun reminder than initializing
IndexPath
s is 35x slower than initializing a simpleElementLocation
struct. See https://github.com/airbnb/MagazineLayout/blob/master/MagazineLayout/LayoutCore/Types/ElementLocation.swift#L23Related Issue
#76
Motivation and Context
It matches
UICollectionViewFlowLayout
behavior, so I guess we should implement this workaround.How Has This Been Tested
Types of changes
Checklist