Add layout type
This commit is contained in:
parent
5982d5db3a
commit
e22ec03990
|
|
@ -31,6 +31,8 @@ public protocol ConfigurableCell {
|
|||
|
||||
static var defaultHeight: CGFloat? { get }
|
||||
|
||||
static var layoutType: LayoutType { get }
|
||||
|
||||
func configure(with _: CellData)
|
||||
func height(for _: CellData) -> CGFloat
|
||||
|
||||
|
|
@ -57,4 +59,9 @@ public extension ConfigurableCell where Self: UITableViewCell {
|
|||
static var defaultHeight: CGFloat? {
|
||||
return nil
|
||||
}
|
||||
|
||||
static var layoutType: LayoutType {
|
||||
return .auto
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ extension Expandable where Self: UITableViewCell & ConfigurableCell {
|
|||
if let indexPath = indexPath,
|
||||
let tableDirector = (tableView?.delegate as? TableDirector),
|
||||
let cellHeightCalculator = tableDirector.rowHeightCalculator as? ExpandableCellHeightCalculator {
|
||||
cellHeightCalculator.updateCached(height: height, for: indexPath)
|
||||
cellHeightCalculator.updateCached(height: height(layoutType: Self.layoutType), for: indexPath)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ public final class ExpandableCellHeightCalculator: RowHeightCalculator {
|
|||
row.configure(cell)
|
||||
cell.layoutIfNeeded()
|
||||
|
||||
let height = cell.height
|
||||
let height = cell.height(layoutType: row.layoutType)
|
||||
cachedHeights[indexPath] = height
|
||||
return height
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
public enum LayoutType {
|
||||
|
||||
case manual
|
||||
|
||||
case auto
|
||||
|
||||
}
|
||||
|
|
@ -59,7 +59,8 @@ public protocol Row: RowConfigurable, RowActionable, RowHashable {
|
|||
|
||||
var reuseIdentifier: String { get }
|
||||
var cellType: AnyClass { get }
|
||||
|
||||
|
||||
var layoutType: LayoutType { get }
|
||||
var estimatedHeight: CGFloat? { get }
|
||||
var defaultHeight: CGFloat? { get }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,6 +41,10 @@ open class TableRow<CellType: ConfigurableCell>: Row where CellType: UITableView
|
|||
open var defaultHeight: CGFloat? {
|
||||
return CellType.defaultHeight
|
||||
}
|
||||
|
||||
open var layoutType: LayoutType {
|
||||
return CellType.layoutType
|
||||
}
|
||||
|
||||
open var cellType: AnyClass {
|
||||
return CellType.self
|
||||
|
|
|
|||
|
|
@ -20,8 +20,13 @@ extension UITableViewCell {
|
|||
return indexPath
|
||||
}
|
||||
|
||||
public var height: CGFloat {
|
||||
return contentView.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize).height
|
||||
public func height(layoutType: LayoutType) -> CGFloat {
|
||||
switch layoutType {
|
||||
case .auto:
|
||||
return contentView.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize).height
|
||||
case .manual:
|
||||
return contentView.subviews.map { $0.frame.maxY }.max() ?? 0
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
3201E78821BE9EB2001DF9E7 /* Expandable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3201E78721BE9EB2001DF9E7 /* Expandable.swift */; };
|
||||
3201E78A21BE9ED4001DF9E7 /* ExpandableCellViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3201E78921BE9ED4001DF9E7 /* ExpandableCellViewModel.swift */; };
|
||||
320C5280218EB9A7004EAD1C /* AccurateCellHeightCalculator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 320C527F218EB9A7004EAD1C /* AccurateCellHeightCalculator.swift */; };
|
||||
32BDFE9F21C167F400D0BBB4 /* LayoutType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 32BDFE9E21C167F400D0BBB4 /* LayoutType.swift */; };
|
||||
50CF6E6B1D6704FE004746FF /* TableCellRegisterer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50CF6E6A1D6704FE004746FF /* TableCellRegisterer.swift */; };
|
||||
50E858581DB153F500A9AA55 /* TableKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E858571DB153F500A9AA55 /* TableKit.swift */; };
|
||||
DA9EA7AF1D0EC2C90021F650 /* ConfigurableCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA9EA7A61D0EC2C90021F650 /* ConfigurableCell.swift */; };
|
||||
|
|
@ -42,6 +43,7 @@
|
|||
3201E78721BE9EB2001DF9E7 /* Expandable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Expandable.swift; sourceTree = "<group>"; };
|
||||
3201E78921BE9ED4001DF9E7 /* ExpandableCellViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExpandableCellViewModel.swift; sourceTree = "<group>"; };
|
||||
320C527F218EB9A7004EAD1C /* AccurateCellHeightCalculator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccurateCellHeightCalculator.swift; sourceTree = "<group>"; };
|
||||
32BDFE9E21C167F400D0BBB4 /* LayoutType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LayoutType.swift; sourceTree = "<group>"; };
|
||||
50CF6E6A1D6704FE004746FF /* TableCellRegisterer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableCellRegisterer.swift; sourceTree = "<group>"; };
|
||||
50E858571DB153F500A9AA55 /* TableKit.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableKit.swift; sourceTree = "<group>"; };
|
||||
DA9EA7561D0B679A0021F650 /* TableKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = TableKit.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
|
|
@ -115,6 +117,7 @@
|
|||
3201E78521BE9E25001DF9E7 /* UITableViewCell+Extensions.swift */,
|
||||
3201E78721BE9EB2001DF9E7 /* Expandable.swift */,
|
||||
3201E78921BE9ED4001DF9E7 /* ExpandableCellViewModel.swift */,
|
||||
32BDFE9E21C167F400D0BBB4 /* LayoutType.swift */,
|
||||
);
|
||||
path = Sources;
|
||||
sourceTree = "<group>";
|
||||
|
|
@ -256,6 +259,7 @@
|
|||
3201E78421BE9DE1001DF9E7 /* ExpandableCellHeightCalculator.swift in Sources */,
|
||||
DA9EA7B51D0EC2C90021F650 /* TableRowAction.swift in Sources */,
|
||||
DA9EA7B21D0EC2C90021F650 /* TableCellAction.swift in Sources */,
|
||||
32BDFE9F21C167F400D0BBB4 /* LayoutType.swift in Sources */,
|
||||
3201E78621BE9E25001DF9E7 /* UITableViewCell+Extensions.swift in Sources */,
|
||||
DA9EA7B11D0EC2C90021F650 /* Operators.swift in Sources */,
|
||||
DA9EA7B41D0EC2C90021F650 /* TableRow.swift in Sources */,
|
||||
|
|
|
|||
Loading…
Reference in New Issue