Fix dynamic type bug in account section header layouts where the account name needed to wrap
This commit is contained in:
parent
d7391b208d
commit
2662352541
|
@ -53,7 +53,7 @@ class MasterFeedTableViewCell : UITableViewCell {
|
||||||
var shouldShowImage = false {
|
var shouldShowImage = false {
|
||||||
didSet {
|
didSet {
|
||||||
if shouldShowImage != oldValue {
|
if shouldShowImage != oldValue {
|
||||||
resetLayout()
|
layout = nil
|
||||||
setNeedsLayout()
|
setNeedsLayout()
|
||||||
}
|
}
|
||||||
faviconImageView.image = shouldShowImage ? faviconImage : nil
|
faviconImageView.image = shouldShowImage ? faviconImage : nil
|
||||||
|
@ -68,7 +68,7 @@ class MasterFeedTableViewCell : UITableViewCell {
|
||||||
if unreadCountView.unreadCount != newValue {
|
if unreadCountView.unreadCount != newValue {
|
||||||
unreadCountView.unreadCount = newValue
|
unreadCountView.unreadCount = newValue
|
||||||
unreadCountView.isHidden = (newValue < 1)
|
unreadCountView.isHidden = (newValue < 1)
|
||||||
resetLayout()
|
layout = nil
|
||||||
setNeedsLayout()
|
setNeedsLayout()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -81,8 +81,7 @@ class MasterFeedTableViewCell : UITableViewCell {
|
||||||
set {
|
set {
|
||||||
if titleView.text != newValue {
|
if titleView.text != newValue {
|
||||||
titleView.text = newValue
|
titleView.text = newValue
|
||||||
resetLayout()
|
layout = nil
|
||||||
setNeedsDisplay()
|
|
||||||
setNeedsLayout()
|
setNeedsLayout()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -187,7 +186,7 @@ private extension MasterFeedTableViewCell {
|
||||||
|
|
||||||
func resetLayout() {
|
func resetLayout() {
|
||||||
let shouldShowDisclosure = !(showingEditControl && showsReorderControl)
|
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) {
|
func layoutWith(_ layout: MasterFeedTableViewCellLayout) {
|
||||||
|
|
|
@ -27,7 +27,7 @@ struct MasterFeedTableViewCellLayout {
|
||||||
|
|
||||||
let height: CGFloat
|
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
|
var initialIndent = MasterFeedTableViewCellLayout.marginLeft + insets.left
|
||||||
if indent {
|
if indent {
|
||||||
|
@ -37,7 +37,7 @@ struct MasterFeedTableViewCellLayout {
|
||||||
initialIndent += MasterFeedTableViewCellLayout.editingControlIndent
|
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
|
// Favicon
|
||||||
var rFavicon = CGRect.zero
|
var rFavicon = CGRect.zero
|
||||||
|
|
|
@ -10,8 +10,6 @@ import UIKit
|
||||||
|
|
||||||
class MasterFeedTableViewSectionHeader: UITableViewHeaderFooterView {
|
class MasterFeedTableViewSectionHeader: UITableViewHeaderFooterView {
|
||||||
|
|
||||||
private var layout: MasterFeedTableViewCellLayout?
|
|
||||||
|
|
||||||
override var accessibilityLabel: String? {
|
override var accessibilityLabel: String? {
|
||||||
set {}
|
set {}
|
||||||
get {
|
get {
|
||||||
|
@ -83,18 +81,27 @@ class MasterFeedTableViewSectionHeader: UITableViewHeaderFooterView {
|
||||||
}
|
}
|
||||||
|
|
||||||
override func sizeThatFits(_ size: CGSize) -> CGSize {
|
override func sizeThatFits(_ size: CGSize) -> CGSize {
|
||||||
if layout == nil {
|
|
||||||
resetLayout()
|
let unreadCountView = MasterFeedUnreadCountView(frame: CGRect.zero)
|
||||||
}
|
|
||||||
return CGSize(width: bounds.width, height: layout!.height)
|
// 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() {
|
override func layoutSubviews() {
|
||||||
super.layoutSubviews()
|
super.layoutSubviews()
|
||||||
if layout == nil {
|
let layout = MasterFeedTableViewCellLayout(cellWidth: bounds.size.width, insets: safeAreaInsets, shouldShowImage: false, label: titleView, unreadCountView: unreadCountView, showingEditingControl: false, indent: true, shouldShowDisclosure: true)
|
||||||
resetLayout()
|
layoutWith(layout)
|
||||||
}
|
|
||||||
layoutWith(layout!)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -124,10 +131,6 @@ private extension MasterFeedTableViewSectionHeader {
|
||||||
view.translatesAutoresizingMaskIntoConstraints = false
|
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) {
|
func layoutWith(_ layout: MasterFeedTableViewCellLayout) {
|
||||||
titleView.setFrameIfNotEqual(layout.titleRect)
|
titleView.setFrameIfNotEqual(layout.titleRect)
|
||||||
unreadCountView.setFrameIfNotEqual(layout.unreadCountRect)
|
unreadCountView.setFrameIfNotEqual(layout.unreadCountRect)
|
||||||
|
|
|
@ -175,7 +175,7 @@ class MasterFeedViewController: ProgressTableViewController, UndoableCommandRunn
|
||||||
headerView.unreadCount = 0
|
headerView.unreadCount = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
let size = headerView.sizeThatFits(CGSize.zero)
|
let size = headerView.sizeThatFits(CGSize(width: tableView.bounds.width, height: 0.0))
|
||||||
return size.height
|
return size.height
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue