From bf45cb89e926ecfabb4c68e7d5179299d8250f4f Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Mon, 29 Apr 2019 16:29:53 -0500 Subject: [PATCH] Set table estimated row height to improve scrolling performance --- .../MasterTimelineViewController.swift | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/iOS/MasterTimeline/MasterTimelineViewController.swift b/iOS/MasterTimeline/MasterTimelineViewController.swift index 5ba6add63..ff6cfb012 100644 --- a/iOS/MasterTimeline/MasterTimelineViewController.swift +++ b/iOS/MasterTimeline/MasterTimelineViewController.swift @@ -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