Skip to content

Commit

Permalink
recommendations-iPad-fix (#1369)
Browse files Browse the repository at this point in the history
* wip

* fix

---------

Co-authored-by: Adrian Sergheev <[email protected]>
  • Loading branch information
adriansergheev and Adrian Sergheev authored Aug 13, 2024
1 parent 88372b8 commit ee7f6c7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
//
// Copyright © FINN.no AS, Inc. All rights reserved.
//

import UIKit

public protocol AdRecommendationsGridViewDelegate: AnyObject {
Expand Down Expand Up @@ -51,15 +47,14 @@ public class AdRecommendationsGridView: UIView {

private let imageCache = ImageMemoryCache()

private lazy var collectionViewLayout: AdRecommendationsGridViewLayout = {
private func collectionViewLayout() -> AdRecommendationsGridViewLayout {
let layout = AdRecommendationsGridViewLayout()
layout.delegate = self
return layout
}()
}

// Have the collection view be private so nobody messes with it.
public private(set) lazy var collectionView: UICollectionView = {
let collectionView = UICollectionView(frame: .zero, collectionViewLayout: collectionViewLayout)
let collectionView = UICollectionView(frame: .zero, collectionViewLayout: collectionViewLayout())
collectionView.translatesAutoresizingMaskIntoConstraints = false
collectionView.delegate = self
collectionView.dataSource = self
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
//
// Copyright © FINN.no AS, Inc. All rights reserved.
//

import UIKit

protocol AdRecommendationsGridViewLayoutDelegate: AnyObject {
Expand Down Expand Up @@ -75,7 +71,7 @@ class AdRecommendationsGridViewLayout: UICollectionViewLayout {
override func prepare() {
super.prepare()

itemAttributes = [UICollectionViewLayoutAttributes]()
itemAttributes.removeAll()

guard let collectionView = collectionView else {
return
Expand Down Expand Up @@ -122,7 +118,13 @@ class AdRecommendationsGridViewLayout: UICollectionViewLayout {
}

override func layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes? {
return itemAttributes[indexPath.row]
guard itemAttributes.indices.contains(indexPath.row)
else { return nil }
if itemAttributes[indexPath.row].representedElementCategory == .cell {
return itemAttributes[indexPath.row]
} else {
return nil
}
}

override var collectionViewContentSize: CGSize {
Expand Down

0 comments on commit ee7f6c7

Please sign in to comment.