Prevent account row float, add height, and add chevron. Issue #613

This commit is contained in:
Maurice Parker 2019-04-20 18:20:25 -05:00
parent 48d6f11aeb
commit 3a0517a299
3 changed files with 53 additions and 8 deletions

View File

@ -171,13 +171,13 @@
<scene sceneID="smW-Zh-WAh"> <scene sceneID="smW-Zh-WAh">
<objects> <objects>
<tableViewController storyboardIdentifier="MasterViewController" title="Master" useStoryboardIdentifierAsRestorationIdentifier="YES" clearsSelectionOnViewWillAppear="NO" id="7bK-jq-Zjz" customClass="MasterViewController" customModule="NetNewsWire" customModuleProvider="target" sceneMemberID="viewController"> <tableViewController storyboardIdentifier="MasterViewController" title="Master" useStoryboardIdentifierAsRestorationIdentifier="YES" clearsSelectionOnViewWillAppear="NO" id="7bK-jq-Zjz" customClass="MasterViewController" customModule="NetNewsWire" customModuleProvider="target" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" id="r7i-6Z-zg0"> <tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="grouped" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="18" sectionFooterHeight="18" id="r7i-6Z-zg0">
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/> <rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> <color key="backgroundColor" cocoaTouchSystemColor="groupTableViewBackgroundColor"/>
<prototypes> <prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="Cell" id="zNG-5C-pQm" customClass="MasterTableViewCell" customModule="NetNewsWire" customModuleProvider="target"> <tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="Cell" id="zNG-5C-pQm" customClass="MasterTableViewCell" customModule="NetNewsWire" customModuleProvider="target">
<rect key="frame" x="0.0" y="28" width="414" height="44"/> <rect key="frame" x="0.0" y="55.5" width="414" height="44"/>
<autoresizingMask key="autoresizingMask"/> <autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="zNG-5C-pQm" id="5gB-Jr-qIo"> <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="zNG-5C-pQm" id="5gB-Jr-qIo">
<rect key="frame" x="0.0" y="0.0" width="414" height="43.5"/> <rect key="frame" x="0.0" y="0.0" width="414" height="43.5"/>

View File

@ -48,6 +48,12 @@ class MasterTableViewSectionHeader: UITableViewHeaderFooterView {
} }
} }
var disclosureExpanded = false {
didSet {
updateDisclosureImage()
}
}
private let titleView: UILabel = { private let titleView: UILabel = {
let label = UILabel() let label = UILabel()
label.font = UIFont.boldSystemFont(ofSize: 17.0) label.font = UIFont.boldSystemFont(ofSize: 17.0)
@ -58,7 +64,12 @@ class MasterTableViewSectionHeader: UITableViewHeaderFooterView {
}() }()
private let unreadCountView = MasterUnreadCountView(frame: CGRect.zero) private let unreadCountView = MasterUnreadCountView(frame: CGRect.zero)
private var disclosureView: UIImageView = {
let iView = UIImageView()
iView.contentMode = .center
return iView
}()
override init(reuseIdentifier: String?) { override init(reuseIdentifier: String?) {
super.init(reuseIdentifier: reuseIdentifier) super.init(reuseIdentifier: reuseIdentifier)
commonInit() commonInit()
@ -71,10 +82,11 @@ class MasterTableViewSectionHeader: UITableViewHeaderFooterView {
override func layoutSubviews() { override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
let layout = MasterTableViewCellLayout(cellSize: bounds.size, insets: safeAreaInsets, shouldShowImage: false, label: titleView, unreadCountView: unreadCountView, showingEditingControl: false, indent: true, shouldShowDisclosure: false) let layout = MasterTableViewCellLayout(cellSize: bounds.size, insets: safeAreaInsets, shouldShowImage: false, label: titleView, unreadCountView: unreadCountView, showingEditingControl: false, indent: true, shouldShowDisclosure: true)
layoutWith(layout) layoutWith(layout)
} }
} }
private extension MasterTableViewSectionHeader { private extension MasterTableViewSectionHeader {
@ -85,8 +97,18 @@ private extension MasterTableViewSectionHeader {
backgroundView = view backgroundView = view
addSubviewAtInit(unreadCountView) addSubviewAtInit(unreadCountView)
addSubviewAtInit(titleView) addSubviewAtInit(titleView)
updateDisclosureImage()
addSubviewAtInit(disclosureView)
} }
func updateDisclosureImage() {
if disclosureExpanded {
disclosureView.image = AppAssets.chevronDownImage
} else {
disclosureView.image = AppAssets.chevronRightImage
}
}
func addSubviewAtInit(_ view: UIView) { func addSubviewAtInit(_ view: UIView) {
addSubview(view) addSubview(view)
view.translatesAutoresizingMaskIntoConstraints = false view.translatesAutoresizingMaskIntoConstraints = false
@ -95,6 +117,7 @@ private extension MasterTableViewSectionHeader {
func layoutWith(_ layout: MasterTableViewCellLayout) { func layoutWith(_ layout: MasterTableViewCellLayout) {
titleView.setFrameIfNotEqual(layout.titleRect) titleView.setFrameIfNotEqual(layout.titleRect)
unreadCountView.setFrameIfNotEqual(layout.unreadCountRect) unreadCountView.setFrameIfNotEqual(layout.unreadCountRect)
disclosureView.setFrameIfNotEqual(layout.disclosureButtonRect)
} }
} }

View File

@ -173,6 +173,10 @@ class MasterViewController: UITableViewController, UndoableCommandRunner {
return shadowTable[section].count return shadowTable[section].count
} }
override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return CGFloat(integerLiteral: 44)
}
override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
guard let nameProvider = treeController.rootNode.childAtIndex(section)?.representedObject as? DisplayNameProvider else { guard let nameProvider = treeController.rootNode.childAtIndex(section)?.representedObject as? DisplayNameProvider else {
@ -182,20 +186,33 @@ class MasterViewController: UITableViewController, UndoableCommandRunner {
let headerView = tableView.dequeueReusableHeaderFooterView(withIdentifier: "SectionHeader") as! MasterTableViewSectionHeader let headerView = tableView.dequeueReusableHeaderFooterView(withIdentifier: "SectionHeader") as! MasterTableViewSectionHeader
headerView.name = nameProvider.nameForDisplay headerView.name = nameProvider.nameForDisplay
if let account = treeController.rootNode.childAtIndex(section)?.representedObject as? Account { guard let sectionNode = treeController.rootNode.childAtIndex(section) else {
return headerView
}
if let account = sectionNode.representedObject as? Account {
headerView.unreadCount = account.unreadCount headerView.unreadCount = account.unreadCount
} else { } else {
headerView.unreadCount = 0 headerView.unreadCount = 0
} }
headerView.tag = section headerView.tag = section
headerView.disclosureExpanded = expandedNodes.contains(sectionNode)
let tap = UITapGestureRecognizer(target: self, action:#selector(self.toggleSectionHeader(_:))) let tap = UITapGestureRecognizer(target: self, action:#selector(self.toggleSectionHeader(_:)))
headerView.addGestureRecognizer(tap) headerView.addGestureRecognizer(tap)
return headerView return headerView
} }
override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return CGFloat.leastNormalMagnitude
}
override func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
return UIView(frame: CGRect.zero)
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
@ -469,14 +486,17 @@ class MasterViewController: UITableViewController, UndoableCommandRunner {
@objc func toggleSectionHeader(_ sender: UITapGestureRecognizer) { @objc func toggleSectionHeader(_ sender: UITapGestureRecognizer) {
guard let sectionIndex = sender.view?.tag, guard let sectionIndex = sender.view?.tag,
let sectionNode = treeController.rootNode.childAtIndex(sectionIndex) let sectionNode = treeController.rootNode.childAtIndex(sectionIndex),
let headerView = sender.view as? MasterTableViewSectionHeader
else { else {
return return
} }
if expandedNodes.contains(sectionNode) { if expandedNodes.contains(sectionNode) {
headerView.disclosureExpanded = false
collapse(section: sectionIndex) collapse(section: sectionIndex)
} else { } else {
headerView.disclosureExpanded = true
expand(section: sectionIndex) expand(section: sectionIndex)
} }
@ -788,6 +808,7 @@ private extension MasterViewController {
guard let collapseNode = treeController.rootNode.childAtIndex(section) else { guard let collapseNode = treeController.rootNode.childAtIndex(section) else {
return return
} }
if let removeNode = expandedNodes.firstIndex(of: collapseNode) { if let removeNode = expandedNodes.firstIndex(of: collapseNode) {
expandedNodes.remove(at: removeNode) expandedNodes.remove(at: removeNode)
} }
@ -803,6 +824,7 @@ private extension MasterViewController {
tableView.endUpdates() tableView.endUpdates()
animatingChanges = false animatingChanges = false
} }
func collapse(_ cell: MasterTableViewCell) { func collapse(_ cell: MasterTableViewCell) {