From 9d14db5366089a05d35a3922c8d70430c3074f40 Mon Sep 17 00:00:00 2001 From: heoblitz Date: Sat, 8 Aug 2026 19:20:42 +0900 Subject: [PATCH 1/4] Remove unused table cell template --- .../UI/Examples/TableViewExample/TableViewExampleView.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/Example/FlexLayoutSample/UI/Examples/TableViewExample/TableViewExampleView.swift b/Example/FlexLayoutSample/UI/Examples/TableViewExample/TableViewExampleView.swift index 7beac501..560c9ec0 100644 --- a/Example/FlexLayoutSample/UI/Examples/TableViewExample/TableViewExampleView.swift +++ b/Example/FlexLayoutSample/UI/Examples/TableViewExample/TableViewExampleView.swift @@ -17,7 +17,6 @@ import UIKit class TableViewExampleView: UIView { fileprivate let tableView = UITableView() - fileprivate let methodCellTemplate = MethodCell() fileprivate var methods: [Method] = [] From 636b946063f92ee45435129c51a09a301a400f1d Mon Sep 17 00:00:00 2001 From: heoblitz Date: Sat, 8 Aug 2026 19:20:51 +0900 Subject: [PATCH 2/4] Remove unused collection navigation snippet --- Example/FlexLayoutSample/UI/Menu/MenuViewController.swift | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Example/FlexLayoutSample/UI/Menu/MenuViewController.swift b/Example/FlexLayoutSample/UI/Menu/MenuViewController.swift index 9141edae..e68e0ec6 100644 --- a/Example/FlexLayoutSample/UI/Menu/MenuViewController.swift +++ b/Example/FlexLayoutSample/UI/Menu/MenuViewController.swift @@ -84,10 +84,6 @@ class MenuViewController: BaseViewController { mainView.delegate = self } -// override func viewDidAppear(_ animated: Bool) { -// super.viewDidAppear(true) -// didSelect(pageType: .collectionView) -// } } // MARK: MenuViewDelegate From 51714c3f2bbe1d22d14464d990ac36bf0584ad2b Mon Sep 17 00:00:00 2001 From: heoblitz Date: Sat, 8 Aug 2026 19:21:02 +0900 Subject: [PATCH 3/4] Use self-sizing collection view cells --- .../CollectionViewExampleView.swift | 8 ++++---- .../UI/Examples/CollectionViewExample/HouseCell.swift | 11 ++++++++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/Example/FlexLayoutSample/UI/Examples/CollectionViewExample/CollectionViewExampleView.swift b/Example/FlexLayoutSample/UI/Examples/CollectionViewExample/CollectionViewExampleView.swift index 6589811a..fc5c01c3 100644 --- a/Example/FlexLayoutSample/UI/Examples/CollectionViewExample/CollectionViewExampleView.swift +++ b/Example/FlexLayoutSample/UI/Examples/CollectionViewExample/CollectionViewExampleView.swift @@ -18,7 +18,6 @@ class CollectionViewExampleView: UIView { fileprivate let collectionView: UICollectionView fileprivate let flowLayout = UICollectionViewFlowLayout() - fileprivate let cellTemplate = HouseCell() fileprivate var houses: [House] = [] @@ -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 @@ -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) } } diff --git a/Example/FlexLayoutSample/UI/Examples/CollectionViewExample/HouseCell.swift b/Example/FlexLayoutSample/UI/Examples/CollectionViewExample/HouseCell.swift index 741e8c7e..cad388cf 100644 --- a/Example/FlexLayoutSample/UI/Examples/CollectionViewExample/HouseCell.swift +++ b/Example/FlexLayoutSample/UI/Examples/CollectionViewExample/HouseCell.swift @@ -78,11 +78,16 @@ class HouseCell: UICollectionViewCell { layout() } + override func preferredLayoutAttributesFitting(_ layoutAttributes: UICollectionViewLayoutAttributes) -> UICollectionViewLayoutAttributes { + let size = sizeThatFits(bounds.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) } From f290d06f4cdd225fec01121d3d2a14719af8a5ca Mon Sep 17 00:00:00 2001 From: heoblitz Date: Sat, 8 Aug 2026 19:24:16 +0900 Subject: [PATCH 4/4] Fit collection cells using layout attributes --- .../UI/Examples/CollectionViewExample/HouseCell.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Example/FlexLayoutSample/UI/Examples/CollectionViewExample/HouseCell.swift b/Example/FlexLayoutSample/UI/Examples/CollectionViewExample/HouseCell.swift index cad388cf..8d7c7fec 100644 --- a/Example/FlexLayoutSample/UI/Examples/CollectionViewExample/HouseCell.swift +++ b/Example/FlexLayoutSample/UI/Examples/CollectionViewExample/HouseCell.swift @@ -79,7 +79,7 @@ class HouseCell: UICollectionViewCell { } override func preferredLayoutAttributesFitting(_ layoutAttributes: UICollectionViewLayoutAttributes) -> UICollectionViewLayoutAttributes { - let size = sizeThatFits(bounds.size) + let size = sizeThatFits(layoutAttributes.size) layoutAttributes.size = size return layoutAttributes }