mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2025-02-10 00:50:55 +01:00
Implement custom separator since the builtin separator is crazy when animating adds and deletes. Issue #1192
This commit is contained in:
parent
29efea3d00
commit
8cb080da6d
@ -60,6 +60,18 @@ class MasterFeedTableViewCell : VibrantTableViewCell {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var isSeparatorShown = true {
|
||||||
|
didSet {
|
||||||
|
if isSeparatorShown != oldValue {
|
||||||
|
if isSeparatorShown {
|
||||||
|
showView(bottomSeparatorView)
|
||||||
|
} else {
|
||||||
|
hideView(bottomSeparatorView)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var unreadCount: Int {
|
var unreadCount: Int {
|
||||||
get {
|
get {
|
||||||
return unreadCountView.unreadCount
|
return unreadCountView.unreadCount
|
||||||
@ -101,6 +113,12 @@ class MasterFeedTableViewCell : VibrantTableViewCell {
|
|||||||
return imageView
|
return imageView
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
private let bottomSeparatorView: UIView = {
|
||||||
|
let view = UIView()
|
||||||
|
view.backgroundColor = UIColor.separator
|
||||||
|
return view
|
||||||
|
}()
|
||||||
|
|
||||||
private var isDisclosureExpanded = false
|
private var isDisclosureExpanded = false
|
||||||
private var disclosureButton: UIButton?
|
private var disclosureButton: UIButton?
|
||||||
private var unreadCountView = MasterFeedUnreadCountView(frame: CGRect.zero)
|
private var unreadCountView = MasterFeedUnreadCountView(frame: CGRect.zero)
|
||||||
@ -173,6 +191,7 @@ private extension MasterFeedTableViewCell {
|
|||||||
addSubviewAtInit(faviconImageView)
|
addSubviewAtInit(faviconImageView)
|
||||||
addSubviewAtInit(titleView)
|
addSubviewAtInit(titleView)
|
||||||
addDisclosureView()
|
addDisclosureView()
|
||||||
|
addSubviewAtInit(bottomSeparatorView)
|
||||||
}
|
}
|
||||||
|
|
||||||
func addDisclosureView() {
|
func addDisclosureView() {
|
||||||
@ -195,7 +214,7 @@ private extension MasterFeedTableViewCell {
|
|||||||
unreadCountView.setFrameIfNotEqual(layout.unreadCountRect)
|
unreadCountView.setFrameIfNotEqual(layout.unreadCountRect)
|
||||||
disclosureButton?.setFrameIfNotEqual(layout.disclosureButtonRect)
|
disclosureButton?.setFrameIfNotEqual(layout.disclosureButtonRect)
|
||||||
disclosureButton?.isHidden = !isDisclosureAvailable
|
disclosureButton?.isHidden = !isDisclosureAvailable
|
||||||
separatorInset = layout.separatorInsets
|
bottomSeparatorView.setFrameIfNotEqual(layout.separatorRect)
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateVibrancy(animated: Bool) {
|
func updateVibrancy(animated: Bool) {
|
||||||
@ -210,4 +229,16 @@ private extension MasterFeedTableViewCell {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func hideView(_ view: UIView) {
|
||||||
|
if !view.isHidden {
|
||||||
|
view.isHidden = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func showView(_ view: UIView) {
|
||||||
|
if view.isHidden {
|
||||||
|
view.isHidden = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ struct MasterFeedTableViewCellLayout {
|
|||||||
let titleRect: CGRect
|
let titleRect: CGRect
|
||||||
let unreadCountRect: CGRect
|
let unreadCountRect: CGRect
|
||||||
let disclosureButtonRect: CGRect
|
let disclosureButtonRect: CGRect
|
||||||
let separatorInsets: UIEdgeInsets
|
let separatorRect: CGRect
|
||||||
|
|
||||||
let height: CGFloat
|
let height: CGFloat
|
||||||
|
|
||||||
@ -60,13 +60,6 @@ struct MasterFeedTableViewCellLayout {
|
|||||||
rFavicon = CGRect(x: x, y: y, width: MasterFeedTableViewCellLayout.imageSize.width, height: MasterFeedTableViewCellLayout.imageSize.height)
|
rFavicon = CGRect(x: x, y: y, width: MasterFeedTableViewCellLayout.imageSize.width, height: MasterFeedTableViewCellLayout.imageSize.height)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Separator Insets
|
|
||||||
if shouldShowDisclosure {
|
|
||||||
separatorInsets = UIEdgeInsets(top: 0, left: MasterFeedTableViewCellLayout.disclosureButtonSize.width, bottom: 0, right: 0)
|
|
||||||
} else {
|
|
||||||
separatorInsets = UIEdgeInsets(top: 0, left: rFavicon.maxX + MasterFeedTableViewCellLayout.imageMarginRight, bottom: 0, right: 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Unread Count
|
// Unread Count
|
||||||
let unreadCountSize = unreadCountView.contentSize
|
let unreadCountSize = unreadCountView.contentSize
|
||||||
let unreadCountIsHidden = unreadCountView.unreadCount < 1
|
let unreadCountIsHidden = unreadCountView.unreadCount < 1
|
||||||
@ -105,6 +98,15 @@ struct MasterFeedTableViewCellLayout {
|
|||||||
rDisclosure = MasterFeedTableViewCellLayout.centerVertically(rDisclosure, newBounds)
|
rDisclosure = MasterFeedTableViewCellLayout.centerVertically(rDisclosure, newBounds)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Separator Insets
|
||||||
|
var separatorInset = CGFloat.zero
|
||||||
|
if shouldShowDisclosure {
|
||||||
|
separatorInset = MasterFeedTableViewCellLayout.disclosureButtonSize.width
|
||||||
|
} else {
|
||||||
|
separatorInset = rFavicon.maxX + MasterFeedTableViewCellLayout.imageMarginRight
|
||||||
|
}
|
||||||
|
separatorRect = CGRect(x: separatorInset, y: cellHeight - 0.5, width: cellWidth - separatorInset, height: 0.5)
|
||||||
|
|
||||||
// Assign the properties
|
// Assign the properties
|
||||||
self.height = cellHeight
|
self.height = cellHeight
|
||||||
self.faviconRect = rFavicon
|
self.faviconRect = rFavicon
|
||||||
|
@ -48,7 +48,9 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner {
|
|||||||
|
|
||||||
tableView.register(MasterFeedTableViewSectionHeader.self, forHeaderFooterViewReuseIdentifier: "SectionHeader")
|
tableView.register(MasterFeedTableViewSectionHeader.self, forHeaderFooterViewReuseIdentifier: "SectionHeader")
|
||||||
tableView.dataSource = dataSource
|
tableView.dataSource = dataSource
|
||||||
|
resetEstimatedRowHeight()
|
||||||
|
tableView.separatorStyle = .none
|
||||||
|
|
||||||
NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: nil)
|
NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: nil)
|
||||||
NotificationCenter.default.addObserver(self, selector: #selector(faviconDidBecomeAvailable(_:)), name: .FaviconDidBecomeAvailable, object: nil)
|
NotificationCenter.default.addObserver(self, selector: #selector(faviconDidBecomeAvailable(_:)), name: .FaviconDidBecomeAvailable, object: nil)
|
||||||
NotificationCenter.default.addObserver(self, selector: #selector(feedSettingDidChange(_:)), name: .FeedSettingDidChange, object: nil)
|
NotificationCenter.default.addObserver(self, selector: #selector(feedSettingDidChange(_:)), name: .FeedSettingDidChange, object: nil)
|
||||||
@ -59,7 +61,6 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner {
|
|||||||
refreshControl = UIRefreshControl()
|
refreshControl = UIRefreshControl()
|
||||||
refreshControl!.addTarget(self, action: #selector(refreshAccounts(_:)), for: .valueChanged)
|
refreshControl!.addTarget(self, action: #selector(refreshAccounts(_:)), for: .valueChanged)
|
||||||
|
|
||||||
resetEstimatedRowHeight()
|
|
||||||
configureToolbar()
|
configureToolbar()
|
||||||
becomeFirstResponder()
|
becomeFirstResponder()
|
||||||
}
|
}
|
||||||
@ -628,6 +629,14 @@ private extension MasterFeedViewController {
|
|||||||
cell.unreadCount = coordinator.unreadCountFor(node)
|
cell.unreadCount = coordinator.unreadCountFor(node)
|
||||||
configureFavicon(cell, node)
|
configureFavicon(cell, node)
|
||||||
|
|
||||||
|
guard let indexPath = dataSource.indexPath(for: node) else { return }
|
||||||
|
let rowsInSection = tableView.numberOfRows(inSection: indexPath.section)
|
||||||
|
if indexPath.row == rowsInSection - 1 {
|
||||||
|
cell.isSeparatorShown = false
|
||||||
|
} else {
|
||||||
|
cell.isSeparatorShown = true
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func configureFavicon(_ cell: MasterFeedTableViewCell, _ node: Node) {
|
func configureFavicon(_ cell: MasterFeedTableViewCell, _ node: Node) {
|
||||||
@ -700,7 +709,9 @@ private extension MasterFeedViewController {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
coordinator.expand(node)
|
coordinator.expand(node)
|
||||||
self.applyChanges(animate: true)
|
applyChanges(animate: true) { [weak self] in
|
||||||
|
self?.reloadNode(node)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func collapse(_ cell: MasterFeedTableViewCell) {
|
func collapse(_ cell: MasterFeedTableViewCell) {
|
||||||
@ -708,7 +719,9 @@ private extension MasterFeedViewController {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
coordinator.collapse(node)
|
coordinator.collapse(node)
|
||||||
self.applyChanges(animate: true)
|
applyChanges(animate: true) { [weak self] in
|
||||||
|
self?.reloadNode(node)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeFeedContextMenu(indexPath: IndexPath, includeDeleteRename: Bool) -> UIContextMenuConfiguration {
|
func makeFeedContextMenu(indexPath: IndexPath, includeDeleteRename: Bool) -> UIContextMenuConfiguration {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user