Set table estimated row height to improve scrolling performance

This commit is contained in:
Maurice Parker 2019-04-29 16:29:53 -05:00
parent 351f195b30
commit bf45cb89e9
1 changed files with 19 additions and 0 deletions

View File

@ -48,6 +48,7 @@ class MasterTimelineViewController: ProgressTableViewController, UndoableCommand
refreshControl!.addTarget(self, action: #selector(refreshAccounts(_:)), for: .valueChanged)
numberOfTextLines = AppDefaults.timelineNumberOfLines
resetEstimatedRowHeight()
resetUI()
@ -250,6 +251,7 @@ class MasterTimelineViewController: ProgressTableViewController, UndoableCommand
@objc func userDefaultsDidChange(_ note: Notification) {
if numberOfTextLines != AppDefaults.timelineNumberOfLines {
numberOfTextLines = AppDefaults.timelineNumberOfLines
resetEstimatedRowHeight()
tableView.reloadData()
}
}
@ -321,6 +323,23 @@ class MasterTimelineViewController: ProgressTableViewController, UndoableCommand
}
}
// MARK: Cell Configuring
private func resetEstimatedRowHeight() {
let longTitle = "But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?"
let prototypeID = "prototype"
let status = ArticleStatus(articleID: prototypeID, read: false, starred: false, userDeleted: false, dateArrived: Date())
let prototypeArticle = Article(accountID: prototypeID, articleID: prototypeID, feedID: prototypeID, uniqueID: prototypeID, title: longTitle, contentHTML: nil, contentText: nil, url: nil, externalURL: nil, summary: nil, imageURL: nil, bannerImageURL: nil, datePublished: nil, dateModified: nil, authors: nil, attachments: nil, status: status)
let prototypeCellData = MasterTimelineCellData(article: prototypeArticle, showFeedName: true, feedName: "Prototype Feed Name", avatar: nil, showAvatar: false, featuredImage: nil, numberOfLines: numberOfTextLines)
let layout = MasterTimelineCellLayout(width: tableView.bounds.width, insets: tableView.safeAreaInsets, cellData: prototypeCellData, showAvatar: false)
tableView.estimatedRowHeight = layout.height
}
}
// MARK: Private