Shopify / FunctionalTableData

Declarative UITableViewDataSource implementation
MIT License
365 stars 30 forks source link

Switch `height` to a function and not a variable #212

Open adam-felix-shopify opened 2 years ago

adam-felix-shopify commented 2 years ago

These changes allow for header and footer width to be passed to the functional table data. More specifically, FunctionalTableData.Delegate's UITableViewDelegate implemenation now uses tableView's width in tableView(_:heightForHeaderInSection:) and tableView(_:heightForFooterInSection).

We achieved this functionality while maintaining backwards compatibility by adding a protocol method to both TableHeaderFooterConfigType and TableHeaderFooterStateType called func height(given width: CGFloat) -> CGFloat?. If this method returns nil, then the table view delegate methods will use the current height property already defined, otherwise it will use the provided by the new methods.

Each protocol provides a public default implemenation so that library consumers need not implement this method unnecessarily.