Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class CollectionViewExampleView: UIView {

fileprivate let collectionView: UICollectionView
fileprivate let flowLayout = UICollectionViewFlowLayout()
fileprivate let cellTemplate = HouseCell()

fileprivate var houses: [House] = []

Expand All @@ -29,6 +28,7 @@ class CollectionViewExampleView: UIView {

flowLayout.minimumLineSpacing = 8
flowLayout.minimumInteritemSpacing = 0
flowLayout.estimatedItemSize = UICollectionViewFlowLayout.automaticSize

if #available(iOS 11.0, *) {
flowLayout.sectionInsetReference = .fromSafeArea
Expand Down Expand Up @@ -71,9 +71,9 @@ extension CollectionViewExampleView: UICollectionViewDelegateFlowLayout, UIColle
cell.configure(house: houses[indexPath.row])
return cell
}

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
cellTemplate.configure(house: houses[indexPath.row])
return cellTemplate.sizeThatFits(CGSize(width: collectionView.bounds.width, height: .greatestFiniteMagnitude))
// The height is only an estimate. HouseCell computes its actual height in preferredLayoutAttributesFitting(_:).
return CGSize(width: collectionView.bounds.width, height: 120)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,16 @@ class HouseCell: UICollectionViewCell {
layout()
}

override func preferredLayoutAttributesFitting(_ layoutAttributes: UICollectionViewLayoutAttributes) -> UICollectionViewLayoutAttributes {
let size = sizeThatFits(layoutAttributes.size)
layoutAttributes.size = size
return layoutAttributes
}

override func sizeThatFits(_ size: CGSize) -> CGSize {
contentView.pin.width(size.width)
layout()
return contentView.frame.size
return contentView.flex.sizeThatFits(size: CGSize(width: size.width, height: .nan))
}

private func layout() {
contentView.flex.layout(mode: .adjustHeight)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import UIKit
class TableViewExampleView: UIView {

fileprivate let tableView = UITableView()
fileprivate let methodCellTemplate = MethodCell()

fileprivate var methods: [Method] = []

Expand Down
4 changes: 0 additions & 4 deletions Example/FlexLayoutSample/UI/Menu/MenuViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,6 @@ class MenuViewController: BaseViewController {
mainView.delegate = self
}

// override func viewDidAppear(_ animated: Bool) {
// super.viewDidAppear(true)
// didSelect(pageType: .collectionView)
// }
}

// MARK: MenuViewDelegate
Expand Down
Loading