-
Notifications
You must be signed in to change notification settings - Fork 29
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
recommendations-iPad-fix #1369
recommendations-iPad-fix #1369
Conversation
@@ -51,15 +47,14 @@ public class AdRecommendationsGridView: UIView { | |||
|
|||
private let imageCache = ImageMemoryCache() | |||
|
|||
private lazy var collectionViewLayout: AdRecommendationsGridViewLayout = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since collectionView is a mutable var, it's best to re-create the layout
return itemAttributes[indexPath.row] | ||
guard itemAttributes.indices.contains(indexPath.row) | ||
else { return nil } | ||
if itemAttributes[indexPath.row].representedElementCategory == .cell { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix:
the method layoutAttributesForItem
retrieves layout info at the indexPath and it works for cells only
we have above a UICollectionViewLayoutAttributes
for the header which is stored in the same array
for some reason, on iPads when launching the app from background this method is called with indexPath.row == 0 which would cause a crash, since at index 0 in the array we have a layout attribute for a header and not for a cell
on iPhones, the call is missing 🤷♂️
guard itemAttributes.indices.contains(indexPath.row) | ||
else { return nil } | ||
if itemAttributes[indexPath.row].representedElementCategory == .cell { | ||
return itemAttributes[indexPath.row] | ||
} else { | ||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
guard itemAttributes.indices.contains(indexPath.row) | |
else { return nil } | |
if itemAttributes[indexPath.row].representedElementCategory == .cell { | |
return itemAttributes[indexPath.row] | |
} else { | |
return nil | |
} | |
if let itemAttribute = itemAttributes[safe: indexPath.row], itemAttribute.representedElementCategory == .cell { | |
return itemAttribute | |
} else { | |
return nil | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤞
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work 🙌
Why?
What?
AdRecommendationsGridViewLayout
Version Change
patch
UI Changes