Fix dynamic type bug in account section header layouts where the account name needed to wrap

This commit is contained in:
Maurice Parker 2019-04-28 11:25:21 -05:00
parent d7391b208d
commit 2662352541
4 changed files with 24 additions and 22 deletions

View File

@ -53,7 +53,7 @@ class MasterFeedTableViewCell : UITableViewCell {
var shouldShowImage = false {
didSet {
if shouldShowImage != oldValue {
resetLayout()
layout = nil
setNeedsLayout()
}
faviconImageView.image = shouldShowImage ? faviconImage : nil
@ -68,7 +68,7 @@ class MasterFeedTableViewCell : UITableViewCell {
if unreadCountView.unreadCount != newValue {
unreadCountView.unreadCount = newValue
unreadCountView.isHidden = (newValue < 1)
resetLayout()
layout = nil
setNeedsLayout()
}
}
@ -81,8 +81,7 @@ class MasterFeedTableViewCell : UITableViewCell {
set {
if titleView.text != newValue {
titleView.text = newValue
resetLayout()
setNeedsDisplay()
layout = nil
setNeedsLayout()
}
}
@ -187,7 +186,7 @@ private extension MasterFeedTableViewCell {
func resetLayout() {
let shouldShowDisclosure = !(showingEditControl && showsReorderControl)
layout = MasterFeedTableViewCellLayout(cellSize: bounds.size, insets: safeAreaInsets, shouldShowImage: shouldShowImage, label: titleView, unreadCountView: unreadCountView, showingEditingControl: showingEditControl, indent: indentationLevel == 1, shouldShowDisclosure: shouldShowDisclosure)
layout = MasterFeedTableViewCellLayout(cellWidth: bounds.size.width, insets: safeAreaInsets, shouldShowImage: shouldShowImage, label: titleView, unreadCountView: unreadCountView, showingEditingControl: showingEditControl, indent: indentationLevel == 1, shouldShowDisclosure: shouldShowDisclosure)
}
func layoutWith(_ layout: MasterFeedTableViewCellLayout) {

View File

@ -27,7 +27,7 @@ struct MasterFeedTableViewCellLayout {
let height: CGFloat
init(cellSize: CGSize, insets: UIEdgeInsets, shouldShowImage: Bool, label: UILabel, unreadCountView: MasterFeedUnreadCountView, showingEditingControl: Bool, indent: Bool, shouldShowDisclosure: Bool) {
init(cellWidth: CGFloat, insets: UIEdgeInsets, shouldShowImage: Bool, label: UILabel, unreadCountView: MasterFeedUnreadCountView, showingEditingControl: Bool, indent: Bool, shouldShowDisclosure: Bool) {
var initialIndent = MasterFeedTableViewCellLayout.marginLeft + insets.left
if indent {
@ -37,7 +37,7 @@ struct MasterFeedTableViewCellLayout {
initialIndent += MasterFeedTableViewCellLayout.editingControlIndent
}
let bounds = CGRect(x: initialIndent, y: 0.0, width: floor(cellSize.width - initialIndent - insets.right), height: floor(cellSize.height))
let bounds = CGRect(x: initialIndent, y: 0.0, width: floor(cellWidth - initialIndent - insets.right), height: 0.0)
// Favicon
var rFavicon = CGRect.zero

View File

@ -10,8 +10,6 @@ import UIKit
class MasterFeedTableViewSectionHeader: UITableViewHeaderFooterView {
private var layout: MasterFeedTableViewCellLayout?
override var accessibilityLabel: String? {
set {}
get {
@ -83,18 +81,27 @@ class MasterFeedTableViewSectionHeader: UITableViewHeaderFooterView {
}
override func sizeThatFits(_ size: CGSize) -> CGSize {
if layout == nil {
resetLayout()
}
return CGSize(width: bounds.width, height: layout!.height)
let unreadCountView = MasterFeedUnreadCountView(frame: CGRect.zero)
// Since we can't reload Section Headers to reset the height after we get the
// unread count did change, we always assume a large unread count
//
// This means that sometimes on the second to largest font size will have extra
// space under the account name. This is better than having it overflow into the
// cell below.
unreadCountView.unreadCount = 888
let layout = MasterFeedTableViewCellLayout(cellWidth: size.width, insets: safeAreaInsets, shouldShowImage: false, label: titleView, unreadCountView: unreadCountView, showingEditingControl: false, indent: true, shouldShowDisclosure: true)
return CGSize(width: bounds.width, height: layout.height)
}
override func layoutSubviews() {
super.layoutSubviews()
if layout == nil {
resetLayout()
}
layoutWith(layout!)
let layout = MasterFeedTableViewCellLayout(cellWidth: bounds.size.width, insets: safeAreaInsets, shouldShowImage: false, label: titleView, unreadCountView: unreadCountView, showingEditingControl: false, indent: true, shouldShowDisclosure: true)
layoutWith(layout)
}
}
@ -124,10 +131,6 @@ private extension MasterFeedTableViewSectionHeader {
view.translatesAutoresizingMaskIntoConstraints = false
}
func resetLayout() {
layout = MasterFeedTableViewCellLayout(cellSize: bounds.size, insets: safeAreaInsets, shouldShowImage: false, label: titleView, unreadCountView: unreadCountView, showingEditingControl: false, indent: true, shouldShowDisclosure: true)
}
func layoutWith(_ layout: MasterFeedTableViewCellLayout) {
titleView.setFrameIfNotEqual(layout.titleRect)
unreadCountView.setFrameIfNotEqual(layout.unreadCountRect)

View File

@ -175,7 +175,7 @@ class MasterFeedViewController: ProgressTableViewController, UndoableCommandRunn
headerView.unreadCount = 0
}
let size = headerView.sizeThatFits(CGSize.zero)
let size = headerView.sizeThatFits(CGSize(width: tableView.bounds.width, height: 0.0))
return size.height
}