remove prototype row builder

This commit is contained in:
Max Sokolov 2016-06-06 23:37:00 +03:00
parent 7faee8f24e
commit 66f318bb15
3 changed files with 0 additions and 104 deletions

View File

@ -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<DataType: Hashable, CellType: ConfigurableCell where CellType.T == DataType, CellType: UITableViewCell> : TableBaseRowBuilder<DataType, CellType> {
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
}
}
}

View File

@ -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 = "<group>"; };
5058386F1CF62B1300224C58 /* TablePrototypeRowBuilder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TablePrototypeRowBuilder.swift; sourceTree = "<group>"; };
DA08A04E1CF3AB0C00BBF1F8 /* ConfigurableCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConfigurableCell.swift; sourceTree = "<group>"; };
DA08A0501CF3AB6100BBF1F8 /* RowBuilder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RowBuilder.swift; sourceTree = "<group>"; };
DA539C9E1CFB025C00368ACB /* Operators.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Operators.swift; sourceTree = "<group>"; };
@ -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 */,
);

View File

@ -9,15 +9,6 @@
import UIKit
import Tablet
class MainController: UIViewController {
@IBOutlet weak var tableView: UITableView! {