From 66f318bb151477e8c2fd8a66e6f118e6eac98d37 Mon Sep 17 00:00:00 2001 From: Max Sokolov Date: Mon, 6 Jun 2016 23:37:00 +0300 Subject: [PATCH] remove prototype row builder --- Tablet/TablePrototypeRowBuilder.swift | 91 ------------------- Tablet/Tablet.xcodeproj/project.pbxproj | 4 - .../Controllers/MainController.swift | 9 -- 3 files changed, 104 deletions(-) delete mode 100644 Tablet/TablePrototypeRowBuilder.swift diff --git a/Tablet/TablePrototypeRowBuilder.swift b/Tablet/TablePrototypeRowBuilder.swift deleted file mode 100644 index 2d04836..0000000 --- a/Tablet/TablePrototypeRowBuilder.swift +++ /dev/null @@ -1,91 +0,0 @@ -// -// Copyright (c) 2015 Max Sokolov https://twitter.com/max_sokolov -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of -// this software and associated documentation files (the "Software"), to deal in -// the Software without restriction, including without limitation the rights to -// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -// the Software, and to permit persons to whom the Software is furnished to do so, -// subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -import UIKit - -public class TablePrototypeRowBuilder : TableBaseRowBuilder { - - private var cachedHeights = [Int: CGFloat]() - private var prototypeCell: CellType? - - public init(item: DataType) { - super.init(item: item, id: CellType.reusableIdentifier()) - } - - public init(items: [DataType]? = nil) { - super.init(items: items, id: CellType.reusableIdentifier()) - } - - public override func estimatedRowHeight(index: Int) -> CGFloat { - return UITableViewAutomaticDimension - } - - func heightCall(item: DataType, width: CGFloat) -> CGFloat { - - guard let cell = prototypeCell else { return 0 } - - cell.bounds = CGRectMake(0, 0, width, cell.bounds.height) - - cell.configure(item) - - cell.setNeedsLayout() - cell.layoutIfNeeded() - - return cell.contentView.systemLayoutSizeFittingSize(UILayoutFittingCompressedSize).height + 1 - } - - // прехит по мере скроллинга в бэк - // прехит не должен прехитить то что уже есть (показанное) - // по мере скроллинга уметь отменять перхит () - - public override func rowHeight(index: Int) -> CGFloat { - - guard let cell = prototypeCell else { return 0 } - - let itemz = item(index: index) - - if let height = cachedHeights[itemz.hashValue] { - return height - } - - let height = heightCall(itemz, width: tableDirector?.tableView?.bounds.size.width ?? 0) - - cachedHeights[itemz.hashValue] = height - - return height - } - - public override func invoke(action action: ActionType, cell: UITableViewCell?, indexPath: NSIndexPath, itemIndex: Int, userInfo: [NSObject: AnyObject]?) -> AnyObject? { - - if case .configure = action { - - (cell as? CellType)?.configure(item(index: itemIndex)) - } - return super.invoke(action: action, cell: cell, indexPath: indexPath, itemIndex: itemIndex, userInfo: userInfo) - } - - public override func willUpdateDirector(director: TableDirector?) { - super.willUpdateDirector(director) - - if let tableView = director?.tableView, cell = tableView.dequeueReusableCellWithIdentifier(reusableIdentifier(0)) as? CellType { - prototypeCell = cell - } - } -} \ No newline at end of file diff --git a/Tablet/Tablet.xcodeproj/project.pbxproj b/Tablet/Tablet.xcodeproj/project.pbxproj index ea1054c..e160546 100644 --- a/Tablet/Tablet.xcodeproj/project.pbxproj +++ b/Tablet/Tablet.xcodeproj/project.pbxproj @@ -8,7 +8,6 @@ /* Begin PBXBuildFile section */ 5058386E1CF62B0700224C58 /* TableRowBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5058386D1CF62B0700224C58 /* TableRowBuilder.swift */; }; - 505838701CF62B1300224C58 /* TablePrototypeRowBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5058386F1CF62B1300224C58 /* TablePrototypeRowBuilder.swift */; }; DA08A04F1CF3AB0C00BBF1F8 /* ConfigurableCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA08A04E1CF3AB0C00BBF1F8 /* ConfigurableCell.swift */; }; DA08A0511CF3AB6100BBF1F8 /* RowBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA08A0501CF3AB6100BBF1F8 /* RowBuilder.swift */; }; DA539C9F1CFB025C00368ACB /* Operators.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA539C9E1CFB025C00368ACB /* Operators.swift */; }; @@ -35,7 +34,6 @@ /* Begin PBXFileReference section */ 5058386D1CF62B0700224C58 /* TableRowBuilder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableRowBuilder.swift; sourceTree = ""; }; - 5058386F1CF62B1300224C58 /* TablePrototypeRowBuilder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TablePrototypeRowBuilder.swift; sourceTree = ""; }; DA08A04E1CF3AB0C00BBF1F8 /* ConfigurableCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConfigurableCell.swift; sourceTree = ""; }; DA08A0501CF3AB6100BBF1F8 /* RowBuilder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RowBuilder.swift; sourceTree = ""; }; DA539C9E1CFB025C00368ACB /* Operators.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Operators.swift; sourceTree = ""; }; @@ -107,7 +105,6 @@ DA08A0501CF3AB6100BBF1F8 /* RowBuilder.swift */, DAC2D68D1C9D799E009E9C19 /* TableBaseRowBuilder.swift */, 5058386D1CF62B0700224C58 /* TableRowBuilder.swift */, - 5058386F1CF62B1300224C58 /* TablePrototypeRowBuilder.swift */, DA539CC51D01D44500368ACB /* TableDynamicRowBuilder.swift */, DAC2D68E1C9D799E009E9C19 /* TableSectionBuilder.swift */, DA08A04E1CF3AB0C00BBF1F8 /* ConfigurableCell.swift */, @@ -244,7 +241,6 @@ DA08A04F1CF3AB0C00BBF1F8 /* ConfigurableCell.swift in Sources */, DAC2D6911C9D799E009E9C19 /* TableBaseRowBuilder.swift in Sources */, 5058386E1CF62B0700224C58 /* TableRowBuilder.swift in Sources */, - 505838701CF62B1300224C58 /* TablePrototypeRowBuilder.swift in Sources */, DAC2D6931C9D799E009E9C19 /* Tablet.swift in Sources */, DA539C9F1CFB025C00368ACB /* Operators.swift in Sources */, ); diff --git a/TabletDemo/Classes/Presentation/Controllers/MainController.swift b/TabletDemo/Classes/Presentation/Controllers/MainController.swift index 17d4c78..9cbe11a 100644 --- a/TabletDemo/Classes/Presentation/Controllers/MainController.swift +++ b/TabletDemo/Classes/Presentation/Controllers/MainController.swift @@ -9,15 +9,6 @@ import UIKit import Tablet - - - - - - - - - class MainController: UIViewController { @IBOutlet weak var tableView: UITableView! {