try preheat

This commit is contained in:
Max Sokolov 2016-05-25 21:47:14 +03:00
parent bc503bcb4f
commit 94925e301b
4 changed files with 46 additions and 20 deletions

View File

@ -164,6 +164,24 @@ public class TablePrototypeRowBuilder<DataType: Hashable, CellType: Configurable
public override func estimatedRowHeight() -> 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 {
@ -172,22 +190,11 @@ public class TablePrototypeRowBuilder<DataType: Hashable, CellType: Configurable
let item = items[index]
if let height = cachedHeights[item.hashValue] {
//return height
return height
}
cell.bounds = CGRectMake(0, 0, tableDirector?.tableView?.bounds.size.width ?? 0, cell.bounds.height)
let height = heightCall(item, width: tableDirector?.tableView?.bounds.size.width ?? 0)
cell.configure(item)
cell.setNeedsLayout()
cell.layoutIfNeeded()
let height = cell.contentView.systemLayoutSizeFittingSize(UILayoutFittingCompressedSize).height + 1
cachedHeights[item.hashValue] = height
print(tableDirector?.tableView?.bounds.size.width, cell.bounds.height, height)
@ -195,6 +202,25 @@ public class TablePrototypeRowBuilder<DataType: Hashable, CellType: Configurable
return height
}
public func preheat(item: DataType) {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {
let height = self.heightCall(item, width: 0)
// check if actual height exists
// calc height
//let heights = self.items.map { self.heightZ($0) }
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {
// check if table width is actual
// store height in cache
}
}
}
public override func invoke(action action: ActionType, cell: UITableViewCell?, indexPath: NSIndexPath, itemIndex: Int, userInfo: [NSObject: AnyObject]?) -> AnyObject? {
if case .configure = action {

View File

@ -30,7 +30,7 @@ class StoryboardImageTableViewCell: UITableViewCell, ConfigurableCell {
override func layoutSubviews() {
super.layoutSubviews()
//contentView.layoutIfNeeded()
contentView.layoutIfNeeded()
subtitleLabel.preferredMaxLayoutWidth = subtitleLabel.bounds.size.width
}

View File

@ -7,9 +7,9 @@
objects = {
/* Begin PBXBuildFile section */
5058386B1CF6189D00224C58 /* Tablet.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5058386A1CF6189D00224C58 /* Tablet.framework */; };
5058386C1CF6189D00224C58 /* Tablet.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 5058386A1CF6189D00224C58 /* Tablet.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
DA08A0531CF4E9B500BBF1F8 /* StoryboardImageTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA08A0521CF4E9B500BBF1F8 /* StoryboardImageTableViewCell.swift */; };
DA539C901CF50E9900368ACB /* Tablet.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DA539C8F1CF50E9900368ACB /* Tablet.framework */; };
DA539C911CF50E9900368ACB /* Tablet.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = DA539C8F1CF50E9900368ACB /* Tablet.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
DAC2D5CA1C9D303E009E9C19 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAC2D5C91C9D303E009E9C19 /* AppDelegate.swift */; };
DAC2D5CF1C9D30A7009E9C19 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = DAC2D5CD1C9D30A7009E9C19 /* Main.storyboard */; };
DAC2D5D01C9D30A7009E9C19 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = DAC2D5CE1C9D30A7009E9C19 /* LaunchScreen.storyboard */; };
@ -26,7 +26,7 @@
dstPath = "";
dstSubfolderSpec = 10;
files = (
DA539C911CF50E9900368ACB /* Tablet.framework in Embed Frameworks */,
5058386C1CF6189D00224C58 /* Tablet.framework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
@ -34,8 +34,8 @@
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
5058386A1CF6189D00224C58 /* Tablet.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; name = Tablet.framework; path = "/Users/max/Library/Developer/Xcode/DerivedData/Tablet-bomgsgklcxthxkeamvdbfmrhqnno/Build/Products/Debug-iphonesimulator/Tablet.framework"; sourceTree = "<absolute>"; };
DA08A0521CF4E9B500BBF1F8 /* StoryboardImageTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StoryboardImageTableViewCell.swift; sourceTree = "<group>"; };
DA539C8F1CF50E9900368ACB /* Tablet.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; name = Tablet.framework; path = "/Users/maxsokolov/Library/Developer/Xcode/DerivedData/Tablet-hgommdyxtgxijceamltarpblrbwc/Build/Products/Debug-iphoneos/Tablet.framework"; sourceTree = "<absolute>"; };
DAB7EB271BEF787300D2AD5E /* TabletDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TabletDemo.app; sourceTree = BUILT_PRODUCTS_DIR; };
DAC2D5C91C9D303E009E9C19 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
DAC2D5CD1C9D30A7009E9C19 /* Main.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Main.storyboard; sourceTree = "<group>"; };
@ -52,7 +52,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
DA539C901CF50E9900368ACB /* Tablet.framework in Frameworks */,
5058386B1CF6189D00224C58 /* Tablet.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -69,7 +69,7 @@
DAB7EB1E1BEF787300D2AD5E = {
isa = PBXGroup;
children = (
DA539C8F1CF50E9900368ACB /* Tablet.framework */,
5058386A1CF6189D00224C58 /* Tablet.framework */,
DAC2D5C61C9D2FE5009E9C19 /* Classes */,
DAC2D5CB1C9D3058009E9C19 /* Resources */,
DA539C871CF50B1800368ACB /* Frameworks */,