This commit is contained in:
Max Sokolov 2016-06-07 02:15:37 +03:00
parent 6e4ea9caf6
commit 0c5f24a491
3 changed files with 9 additions and 14 deletions

View File

@ -30,7 +30,7 @@ public protocol ConfigurableCell {
static func reusableIdentifier() -> String
static func estimatedHeight() -> CGFloat
static func defaultHeight() -> Float?
static func defaultHeight() -> CGFloat?
func configure(_: T)
}
@ -40,11 +40,11 @@ public extension ConfigurableCell where Self: UITableViewCell {
return String(self)
}
static func defaultHeight() -> Float? {
return nil
}
static func estimatedHeight() -> CGFloat {
return UITableViewAutomaticDimension
}
static func defaultHeight() -> CGFloat? {
return nil
}
}

View File

@ -21,12 +21,10 @@
import UIKit
public protocol HeightStrategy {
var tableView: UITableView? { get set }
func height<Item, Cell: ConfigurableCell where Cell.T == Item, Cell: UITableViewCell>(item: Item, indexPath: NSIndexPath, cell: Cell.Type) -> CGFloat
func estimatedHeight() -> CGFloat
}
public class PrototypeHeightStrategy: HeightStrategy {
@ -47,8 +45,4 @@ public class PrototypeHeightStrategy: HeightStrategy {
return cell.contentView.systemLayoutSizeFittingSize(UILayoutFittingCompressedSize).height + 1
}
public func estimatedHeight() -> CGFloat {
return UITableViewAutomaticDimension
}
}

View File

@ -33,7 +33,6 @@ public class TableRowBuilder<DataType, CellType: ConfigurableCell where CellType
private var actions = [String: ActionHandler<DataType, CellType>]()
private var items = [DataType]()
public func reusableIdentifier(_: Int) -> String {
return CellType.reusableIdentifier()
}
@ -41,6 +40,8 @@ public class TableRowBuilder<DataType, CellType: ConfigurableCell where CellType
public var numberOfRows: Int {
return items.count
}
// MARK: - Initializers -
public init(item: DataType) {
items.append(item)
@ -56,7 +57,7 @@ public class TableRowBuilder<DataType, CellType: ConfigurableCell where CellType
// MARK: - RowHeightCalculatable -
public func rowHeight(index: Int, indexPath: NSIndexPath) -> CGFloat {
return heightStrategy?.height(item(index: index), indexPath: indexPath, cell: CellType.self) ?? 0
return CellType.defaultHeight() ?? heightStrategy?.height(item(index: index), indexPath: indexPath, cell: CellType.self) ?? UITableViewAutomaticDimension
}
public func estimatedRowHeight(index: Int, indexPath: NSIndexPath) -> CGFloat {