diff --git a/Sources/FunctionalTableData/TableSectionHeaderFooter.swift b/Sources/FunctionalTableData/TableSectionHeaderFooter.swift index 8b73f57..6f187ff 100644 --- a/Sources/FunctionalTableData/TableSectionHeaderFooter.swift +++ b/Sources/FunctionalTableData/TableSectionHeaderFooter.swift @@ -17,6 +17,13 @@ public protocol TableHeaderFooterConfigType: TableItemConfigType { func dequeueHeaderFooter(from tableView: UITableView) -> UITableViewHeaderFooterView? func isEqual(_ other: TableHeaderFooterConfigType?) -> Bool var height: CGFloat { get } + func height(given width: CGFloat) -> CGFloat? +} + +extension TableHeaderFooterConfigType { + public func height(given width: CGFloat) -> CGFloat? { + nil + } } public protocol TableHeaderFooterStateType: Equatable { @@ -24,6 +31,14 @@ public protocol TableHeaderFooterStateType: Equatable { var height: CGFloat { get } var topSeparatorHidden: Bool { get } var bottomSeparatorHidden: Bool { get } + + func height(given width: CGFloat) -> CGFloat? +} + +extension TableHeaderFooterStateType { + public func height(given width: CGFloat) -> CGFloat? { + nil + } } public struct TableSectionHeaderFooter: TableHeaderFooterConfigType { @@ -53,7 +68,11 @@ public struct TableSectionHeaderFooter CGFloat? { + return state?.height(given: width) ?? height } // MARK: - TableHeaderFooterConfigType diff --git a/Sources/FunctionalTableData/TableView/FunctionalTableData+UITableViewDelegate.swift b/Sources/FunctionalTableData/TableView/FunctionalTableData+UITableViewDelegate.swift index 04648c5..0d41885 100644 --- a/Sources/FunctionalTableData/TableView/FunctionalTableData+UITableViewDelegate.swift +++ b/Sources/FunctionalTableData/TableView/FunctionalTableData+UITableViewDelegate.swift @@ -49,7 +49,7 @@ extension FunctionalTableData { // When given a height of zero grouped style UITableView's use their default value instead of zero. By returning CGFloat.min we get around this behavior and force UITableView to end up using a height of zero after all. return tableView.style == .grouped ? CGFloat.leastNormalMagnitude : 0 } - return header.height + return header.height(given: tableView.frame.width) ?? header.height } public func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat { @@ -57,7 +57,7 @@ extension FunctionalTableData { // When given a height of zero grouped style UITableView's use their default value instead of zero. By returning CGFloat.min we get around this behavior and force UITableView to end up using a height of zero after all. return tableView.style == .grouped ? CGFloat.leastNormalMagnitude : 0 } - return footer.height + return footer.height(given: tableView.frame.width) ?? footer.height } public func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat { diff --git a/Tests/FunctionalTableDataTests/CollectionSectionChangeSetTests.swift b/Tests/FunctionalTableDataTests/CollectionSectionChangeSetTests.swift index b714e93..7bb794d 100644 --- a/Tests/FunctionalTableDataTests/CollectionSectionChangeSetTests.swift +++ b/Tests/FunctionalTableDataTests/CollectionSectionChangeSetTests.swift @@ -654,7 +654,7 @@ fileprivate struct TestHeaderFooter: TableHeaderFooterConfigType, CollectionSupp guard let other = other as? TestHeaderFooter else { return false } return state == other.state } - + var height: CGFloat { return state?.height ?? 0 }