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
21 changes: 20 additions & 1 deletion Sources/FunctionalTableData/TableSectionHeaderFooter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,28 @@ 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 {
var insets: UIEdgeInsets { get }
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<ViewType: UIView, Layout: TableItemLayout, S: TableHeaderFooterStateType>: TableHeaderFooterConfigType {
Expand Down Expand Up @@ -53,7 +68,11 @@ public struct TableSectionHeaderFooter<ViewType: UIView, Layout: TableItemLayout
}

public var height: CGFloat {
return state?.height ?? 0
state?.height ?? 0
}

public func height(given width: CGFloat) -> CGFloat? {
return state?.height(given: width) ?? height
}

// MARK: - TableHeaderFooterConfigType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ 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 {
guard let footer = data.sections[section].footer else {
// 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down