From 9d10bc18bf727d11bdae6448150d90068d203fd9 Mon Sep 17 00:00:00 2001 From: Ivan Zinovyev Date: Wed, 9 Jan 2019 16:05:07 +0300 Subject: [PATCH] Remove manual height calculation functionality --- Sources/AccurateCellHeightCalculator.swift | 45 ---------------------- Sources/ConfigurableCell.swift | 9 ----- Sources/TableKit.swift | 1 - Sources/TableRow.swift | 7 +--- TableKit.xcodeproj/project.pbxproj | 4 -- 5 files changed, 1 insertion(+), 65 deletions(-) delete mode 100644 Sources/AccurateCellHeightCalculator.swift diff --git a/Sources/AccurateCellHeightCalculator.swift b/Sources/AccurateCellHeightCalculator.swift deleted file mode 100644 index d4190fb..0000000 --- a/Sources/AccurateCellHeightCalculator.swift +++ /dev/null @@ -1,45 +0,0 @@ -import UIKit - -public class AccurateCellHeightCalculator: RowHeightCalculator { - - private(set) weak var tableView: UITableView? - private var prototypes = [String: UITableViewCell]() - private var cachedHeights = [Int: CGFloat]() - - public init(tableView: UITableView?) { - self.tableView = tableView - } - - open func height(forRow row: Row, at indexPath: IndexPath) -> CGFloat { - - guard let tableView = tableView else { return 0 } - - let hash = row.hashValue ^ Int(tableView.bounds.size.width).hashValue - - if let height = cachedHeights[hash] { - return height - } - - var prototypeCell = prototypes[row.reuseIdentifier] - if prototypeCell == nil { - - prototypeCell = tableView.dequeueReusableCell(withIdentifier: row.reuseIdentifier) - prototypes[row.reuseIdentifier] = prototypeCell - } - - guard let cell = prototypeCell else { return 0 } - let height = row.height(for: cell) - - cachedHeights[hash] = height - - return height - } - - open func estimatedHeight(forRow row: Row, at indexPath: IndexPath) -> CGFloat { - return height(forRow: row, at: indexPath) - } - - open func invalidate() { - cachedHeights.removeAll() - } -} diff --git a/Sources/ConfigurableCell.swift b/Sources/ConfigurableCell.swift index 2c1fb4e..b7d9464 100644 --- a/Sources/ConfigurableCell.swift +++ b/Sources/ConfigurableCell.swift @@ -34,18 +34,9 @@ public protocol ConfigurableCell { static var layoutType: LayoutType { get } func configure(with _: CellData) - func height(for _: CellData) -> CGFloat } -public extension ConfigurableCell { - - func height(for _: CellData) -> CGFloat { - return UITableView.automaticDimension - } - -} - public extension ConfigurableCell where Self: UITableViewCell { static var reuseIdentifier: String { diff --git a/Sources/TableKit.swift b/Sources/TableKit.swift index fed5e9c..8206baf 100644 --- a/Sources/TableKit.swift +++ b/Sources/TableKit.swift @@ -32,7 +32,6 @@ public struct TableKitUserInfoKeys { public protocol RowConfigurable { func configure(_ cell: UITableViewCell) - func height(for _: UITableViewCell) -> CGFloat } diff --git a/Sources/TableRow.swift b/Sources/TableRow.swift index 491015e..8a697fd 100644 --- a/Sources/TableRow.swift +++ b/Sources/TableRow.swift @@ -63,12 +63,7 @@ open class TableRow: Row where CellType: UITableView (cell as? CellType)?.configure(with: item) } - - open func height(for cell: UITableViewCell) -> CGFloat { - - return (cell as? CellType)?.height(for: item) ?? UITableView.automaticDimension - } - + // MARK: - RowActionable - open func invoke(action: TableRowActionType, cell: UITableViewCell?, path: IndexPath, userInfo: [AnyHashable: Any]? = nil) -> Any? { diff --git a/TableKit.xcodeproj/project.pbxproj b/TableKit.xcodeproj/project.pbxproj index 068fb5f..ff64415 100644 --- a/TableKit.xcodeproj/project.pbxproj +++ b/TableKit.xcodeproj/project.pbxproj @@ -11,7 +11,6 @@ 3201E78621BE9E25001DF9E7 /* UITableViewCell+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3201E78521BE9E25001DF9E7 /* UITableViewCell+Extensions.swift */; }; 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 */; }; @@ -42,7 +41,6 @@ 3201E78521BE9E25001DF9E7 /* UITableViewCell+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UITableViewCell+Extensions.swift"; sourceTree = ""; }; 3201E78721BE9EB2001DF9E7 /* Expandable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Expandable.swift; sourceTree = ""; }; 3201E78921BE9ED4001DF9E7 /* ExpandableCellViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExpandableCellViewModel.swift; sourceTree = ""; }; - 320C527F218EB9A7004EAD1C /* AccurateCellHeightCalculator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccurateCellHeightCalculator.swift; sourceTree = ""; }; 32BDFE9E21C167F400D0BBB4 /* LayoutType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LayoutType.swift; sourceTree = ""; }; 50CF6E6A1D6704FE004746FF /* TableCellRegisterer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableCellRegisterer.swift; sourceTree = ""; }; 50E858571DB153F500A9AA55 /* TableKit.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableKit.swift; sourceTree = ""; }; @@ -102,7 +100,6 @@ DA9EA7A51D0EC2B90021F650 /* Sources */ = { isa = PBXGroup; children = ( - 320C527F218EB9A7004EAD1C /* AccurateCellHeightCalculator.swift */, DA9EA7A61D0EC2C90021F650 /* ConfigurableCell.swift */, 3201E78321BE9DE1001DF9E7 /* ExpandableCellHeightCalculator.swift */, DA9EA7A81D0EC2C90021F650 /* Operators.swift */, @@ -253,7 +250,6 @@ DA9EA7AF1D0EC2C90021F650 /* ConfigurableCell.swift in Sources */, DA9EA7B31D0EC2C90021F650 /* TableDirector.swift in Sources */, 3201E78821BE9EB2001DF9E7 /* Expandable.swift in Sources */, - 320C5280218EB9A7004EAD1C /* AccurateCellHeightCalculator.swift in Sources */, DA9EA7B71D0EC2C90021F650 /* TableSection.swift in Sources */, DA9EA7B01D0EC2C90021F650 /* TablePrototypeCellHeightCalculator.swift in Sources */, 3201E78421BE9DE1001DF9E7 /* ExpandableCellHeightCalculator.swift in Sources */,