From 574672f016707e6381a7f42940b567662415e5d2 Mon Sep 17 00:00:00 2001 From: Stuart Breckenridge Date: Sat, 29 Jan 2022 07:51:00 +0800 Subject: [PATCH] Remove unread count code from section headers --- .../MasterFeedTableViewSectionHeader.swift | 6 ++--- ...sterFeedTableViewSectionHeaderLayout.swift | 27 +++---------------- 2 files changed, 5 insertions(+), 28 deletions(-) diff --git a/iOS/MasterFeed/Cell/MasterFeedTableViewSectionHeader.swift b/iOS/MasterFeed/Cell/MasterFeedTableViewSectionHeader.swift index a2aff10d4..e194f41d7 100644 --- a/iOS/MasterFeed/Cell/MasterFeedTableViewSectionHeader.swift +++ b/iOS/MasterFeed/Cell/MasterFeedTableViewSectionHeader.swift @@ -97,7 +97,7 @@ class MasterFeedTableViewSectionHeader: UITableViewHeaderFooterView { } override func sizeThatFits(_ size: CGSize) -> CGSize { - let layout = MasterFeedTableViewSectionHeaderLayout(cellWidth: size.width, insets: safeAreaInsets, label: titleView, unreadCountView: unreadCountView) + let layout = MasterFeedTableViewSectionHeaderLayout(cellWidth: size.width, insets: safeAreaInsets, label: titleView) return CGSize(width: bounds.width, height: layout.height) } @@ -106,8 +106,7 @@ class MasterFeedTableViewSectionHeader: UITableViewHeaderFooterView { super.layoutSubviews() let layout = MasterFeedTableViewSectionHeaderLayout(cellWidth: contentView.bounds.size.width, insets: contentView.safeAreaInsets, - label: titleView, - unreadCountView: unreadCountView) + label: titleView) layoutWith(layout) } @@ -157,7 +156,6 @@ private extension MasterFeedTableViewSectionHeader { func layoutWith(_ layout: MasterFeedTableViewSectionHeaderLayout) { titleView.setFrameIfNotEqual(layout.titleRect) - unreadCountView.setFrameIfNotEqual(layout.unreadCountRect) disclosureButton.setFrameIfNotEqual(layout.disclosureButtonRect) let top = CGRect(x: safeAreaInsets.left, y: 0, width: frame.width - safeAreaInsets.right - safeAreaInsets.left, height: 0.33) diff --git a/iOS/MasterFeed/Cell/MasterFeedTableViewSectionHeaderLayout.swift b/iOS/MasterFeed/Cell/MasterFeedTableViewSectionHeaderLayout.swift index 60748bb82..73dce3f69 100644 --- a/iOS/MasterFeed/Cell/MasterFeedTableViewSectionHeaderLayout.swift +++ b/iOS/MasterFeed/Cell/MasterFeedTableViewSectionHeaderLayout.swift @@ -12,19 +12,17 @@ import RSCore struct MasterFeedTableViewSectionHeaderLayout { private static let labelMarginRight = CGFloat(integerLiteral: 8) - private static let unreadCountMarginRight = CGFloat(integerLiteral: 0) private static let disclosureButtonSize = CGSize(width: 44, height: 44) private static let verticalPadding = CGFloat(integerLiteral: 11) private static let minRowHeight = CGFloat(integerLiteral: 44) let titleRect: CGRect - let unreadCountRect: CGRect let disclosureButtonRect: CGRect let height: CGFloat - init(cellWidth: CGFloat, insets: UIEdgeInsets, label: UILabel, unreadCountView: MasterFeedUnreadCountView) { + init(cellWidth: CGFloat, insets: UIEdgeInsets, label: UILabel) { let bounds = CGRect(x: insets.left, y: 0.0, width: floor(cellWidth - insets.right), height: 0.0) @@ -33,35 +31,20 @@ struct MasterFeedTableViewSectionHeaderLayout { rDisclosure.size = MasterFeedTableViewSectionHeaderLayout.disclosureButtonSize rDisclosure.origin.x = bounds.maxX - rDisclosure.size.width - // Unread Count - let unreadCountSize = unreadCountView.contentSize - let unreadCountIsHidden = unreadCountView.unreadCount < 1 - - var rUnread = CGRect.zero - if !unreadCountIsHidden { - rUnread.size = unreadCountSize - rUnread.origin.x = bounds.maxX - (MasterFeedTableViewSectionHeaderLayout.unreadCountMarginRight + unreadCountSize.width + rDisclosure.size.width) - } - - // Max Unread Count - // We can't reload Section Headers so we don't let the title extend into the (probably) worse case Unread Count area. - let maxUnreadCountView = MasterFeedUnreadCountView(frame: CGRect.zero) - maxUnreadCountView.unreadCount = 888 - let maxUnreadCountSize = maxUnreadCountView.contentSize // Title let rLabelx = 15.0 let rLabely = UIFontMetrics.default.scaledValue(for: MasterFeedTableViewSectionHeaderLayout.verticalPadding) var labelWidth = CGFloat.zero - labelWidth = cellWidth - (rLabelx + MasterFeedTableViewSectionHeaderLayout.labelMarginRight + maxUnreadCountSize.width + MasterFeedTableViewSectionHeaderLayout.unreadCountMarginRight) + labelWidth = cellWidth - (rLabelx + MasterFeedTableViewSectionHeaderLayout.labelMarginRight) let labelSizeInfo = MultilineUILabelSizer.size(for: label.text ?? "", font: label.font, numberOfLines: 0, width: Int(floor(labelWidth))) var rLabel = CGRect(x: rLabelx, y: rLabely, width: labelWidth, height: labelSizeInfo.size.height) // Determine cell height let paddedLabelHeight = rLabel.maxY + UIFontMetrics.default.scaledValue(for: MasterFeedTableViewSectionHeaderLayout.verticalPadding) - let maxGraphicsHeight = [rUnread, rDisclosure].maxY() + let maxGraphicsHeight = [rDisclosure].maxY() var cellHeight = max(paddedLabelHeight, maxGraphicsHeight) if cellHeight < MasterFeedTableViewSectionHeaderLayout.minRowHeight { cellHeight = MasterFeedTableViewSectionHeaderLayout.minRowHeight @@ -69,9 +52,6 @@ struct MasterFeedTableViewSectionHeaderLayout { // Center in Cell let newBounds = CGRect(x: bounds.origin.x, y: bounds.origin.y, width: bounds.width, height: cellHeight) - if !unreadCountIsHidden { - rUnread = MasterFeedTableViewCellLayout.centerVertically(rUnread, newBounds) - } rDisclosure = MasterFeedTableViewCellLayout.centerVertically(rDisclosure, newBounds) // Small fonts need centered if we hit the minimum row height @@ -81,7 +61,6 @@ struct MasterFeedTableViewSectionHeaderLayout { // Assign the properties self.height = cellHeight - self.unreadCountRect = rUnread self.disclosureButtonRect = rDisclosure self.titleRect = rLabel