Prevent account row float, add height, and add chevron. Issue #613
This commit is contained in:
parent
48d6f11aeb
commit
3a0517a299
|
@ -171,13 +171,13 @@
|
|||
<scene sceneID="smW-Zh-WAh">
|
||||
<objects>
|
||||
<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"/>
|
||||
<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>
|
||||
<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"/>
|
||||
<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"/>
|
||||
|
|
|
@ -48,6 +48,12 @@ class MasterTableViewSectionHeader: UITableViewHeaderFooterView {
|
|||
}
|
||||
}
|
||||
|
||||
var disclosureExpanded = false {
|
||||
didSet {
|
||||
updateDisclosureImage()
|
||||
}
|
||||
}
|
||||
|
||||
private let titleView: UILabel = {
|
||||
let label = UILabel()
|
||||
label.font = UIFont.boldSystemFont(ofSize: 17.0)
|
||||
|
@ -58,7 +64,12 @@ class MasterTableViewSectionHeader: UITableViewHeaderFooterView {
|
|||
}()
|
||||
|
||||
private let unreadCountView = MasterUnreadCountView(frame: CGRect.zero)
|
||||
|
||||
private var disclosureView: UIImageView = {
|
||||
let iView = UIImageView()
|
||||
iView.contentMode = .center
|
||||
return iView
|
||||
}()
|
||||
|
||||
override init(reuseIdentifier: String?) {
|
||||
super.init(reuseIdentifier: reuseIdentifier)
|
||||
commonInit()
|
||||
|
@ -71,10 +82,11 @@ class MasterTableViewSectionHeader: UITableViewHeaderFooterView {
|
|||
|
||||
override func 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)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private extension MasterTableViewSectionHeader {
|
||||
|
@ -85,8 +97,18 @@ private extension MasterTableViewSectionHeader {
|
|||
backgroundView = view
|
||||
addSubviewAtInit(unreadCountView)
|
||||
addSubviewAtInit(titleView)
|
||||
updateDisclosureImage()
|
||||
addSubviewAtInit(disclosureView)
|
||||
}
|
||||
|
||||
func updateDisclosureImage() {
|
||||
if disclosureExpanded {
|
||||
disclosureView.image = AppAssets.chevronDownImage
|
||||
} else {
|
||||
disclosureView.image = AppAssets.chevronRightImage
|
||||
}
|
||||
}
|
||||
|
||||
func addSubviewAtInit(_ view: UIView) {
|
||||
addSubview(view)
|
||||
view.translatesAutoresizingMaskIntoConstraints = false
|
||||
|
@ -95,6 +117,7 @@ private extension MasterTableViewSectionHeader {
|
|||
func layoutWith(_ layout: MasterTableViewCellLayout) {
|
||||
titleView.setFrameIfNotEqual(layout.titleRect)
|
||||
unreadCountView.setFrameIfNotEqual(layout.unreadCountRect)
|
||||
disclosureView.setFrameIfNotEqual(layout.disclosureButtonRect)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -173,6 +173,10 @@ class MasterViewController: UITableViewController, UndoableCommandRunner {
|
|||
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? {
|
||||
|
||||
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
|
||||
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
|
||||
} else {
|
||||
headerView.unreadCount = 0
|
||||
}
|
||||
|
||||
headerView.tag = section
|
||||
|
||||
headerView.disclosureExpanded = expandedNodes.contains(sectionNode)
|
||||
|
||||
let tap = UITapGestureRecognizer(target: self, action:#selector(self.toggleSectionHeader(_:)))
|
||||
headerView.addGestureRecognizer(tap)
|
||||
|
||||
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 {
|
||||
|
||||
|
@ -469,14 +486,17 @@ class MasterViewController: UITableViewController, UndoableCommandRunner {
|
|||
@objc func toggleSectionHeader(_ sender: UITapGestureRecognizer) {
|
||||
|
||||
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 {
|
||||
return
|
||||
}
|
||||
|
||||
if expandedNodes.contains(sectionNode) {
|
||||
headerView.disclosureExpanded = false
|
||||
collapse(section: sectionIndex)
|
||||
} else {
|
||||
headerView.disclosureExpanded = true
|
||||
expand(section: sectionIndex)
|
||||
}
|
||||
|
||||
|
@ -788,6 +808,7 @@ private extension MasterViewController {
|
|||
guard let collapseNode = treeController.rootNode.childAtIndex(section) else {
|
||||
return
|
||||
}
|
||||
|
||||
if let removeNode = expandedNodes.firstIndex(of: collapseNode) {
|
||||
expandedNodes.remove(at: removeNode)
|
||||
}
|
||||
|
@ -803,6 +824,7 @@ private extension MasterViewController {
|
|||
tableView.endUpdates()
|
||||
|
||||
animatingChanges = false
|
||||
|
||||
}
|
||||
|
||||
func collapse(_ cell: MasterTableViewCell) {
|
||||
|
|
Loading…
Reference in New Issue