diff --git a/NetNewsWire.xcodeproj/project.pbxproj b/NetNewsWire.xcodeproj/project.pbxproj index 130375a2f..403c8a8a8 100644 --- a/NetNewsWire.xcodeproj/project.pbxproj +++ b/NetNewsWire.xcodeproj/project.pbxproj @@ -130,6 +130,7 @@ 51E595A6228CC36500FCC42B /* ArticleStatusSyncTimer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51E595A4228CC36500FCC42B /* ArticleStatusSyncTimer.swift */; }; 51E595AB228DF94C00FCC42B /* SettingsTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 51E595AA228DF94C00FCC42B /* SettingsTableViewCell.xib */; }; 51E595AD228E1C2100FCC42B /* AddAccountViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51E595AC228E1C2100FCC42B /* AddAccountViewController.swift */; }; + 51EAED96231363EF00A9EEE3 /* NonIntrinsicButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51EAED95231363EF00A9EEE3 /* NonIntrinsicButton.swift */; }; 51EC114C2149FE3300B296E3 /* FolderTreeMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51EC114B2149FE3300B296E3 /* FolderTreeMenu.swift */; }; 51EF0F77227716200050506E /* FaviconGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51EF0F76227716200050506E /* FaviconGenerator.swift */; }; 51EF0F79227716380050506E /* ColorHash.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51EF0F78227716380050506E /* ColorHash.swift */; }; @@ -737,6 +738,7 @@ 51E595A4228CC36500FCC42B /* ArticleStatusSyncTimer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArticleStatusSyncTimer.swift; sourceTree = ""; }; 51E595AA228DF94C00FCC42B /* SettingsTableViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SettingsTableViewCell.xib; sourceTree = ""; }; 51E595AC228E1C2100FCC42B /* AddAccountViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddAccountViewController.swift; sourceTree = ""; }; + 51EAED95231363EF00A9EEE3 /* NonIntrinsicButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NonIntrinsicButton.swift; sourceTree = ""; }; 51EC114B2149FE3300B296E3 /* FolderTreeMenu.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = FolderTreeMenu.swift; path = AddFeed/FolderTreeMenu.swift; sourceTree = ""; }; 51EF0F76227716200050506E /* FaviconGenerator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FaviconGenerator.swift; sourceTree = ""; }; 51EF0F78227716380050506E /* ColorHash.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColorHash.swift; sourceTree = ""; }; @@ -1113,6 +1115,7 @@ children = ( 51F85BFA2275D85000C787DC /* Array-Extensions.swift */, 51F85BF42273625800C787DC /* Bundle-Extensions.swift */, + 51EAED95231363EF00A9EEE3 /* NonIntrinsicButton.swift */, 5183CCD9226E31A50010922C /* NonIntrinsicImageView.swift */, 5183CCCF226E1E880010922C /* NonIntrinsicLabel.swift */, 51C45250226506F400C03939 /* String-Extensions.swift */, @@ -2385,6 +2388,7 @@ 51C452A422650A2D00C03939 /* ArticleUtilities.swift in Sources */, 51EF0F79227716380050506E /* ColorHash.swift in Sources */, 5183CCDA226E31A50010922C /* NonIntrinsicImageView.swift in Sources */, + 51EAED96231363EF00A9EEE3 /* NonIntrinsicButton.swift in Sources */, 51C4527B2265091600C03939 /* MasterUnreadIndicatorView.swift in Sources */, 515ADE4022E11FAE006B2460 /* SystemMessageViewController.swift in Sources */, 51F85BF92274AA7B00C787DC /* UIBarButtonItem-Extensions.swift in Sources */, diff --git a/iOS/Extensions/NonIntrinsicButton.swift b/iOS/Extensions/NonIntrinsicButton.swift new file mode 100644 index 000000000..715f85c7f --- /dev/null +++ b/iOS/Extensions/NonIntrinsicButton.swift @@ -0,0 +1,20 @@ +// +// NonIntrinsicButton.swift +// NetNewsWire-iOS +// +// Created by Maurice Parker on 8/25/19. +// Copyright © 2019 Ranchero Software. All rights reserved. +// + +import Foundation + +import UIKit + +class NonIntrinsicButton: UIButton { + + // Prevent autolayout from messing around with our frame settings + override var intrinsicContentSize: CGSize { + return CGSize(width: UIView.noIntrinsicMetric, height: UIView.noIntrinsicMetric) + } + +} diff --git a/iOS/MasterFeed/Cell/MasterFeedTableViewCell.swift b/iOS/MasterFeed/Cell/MasterFeedTableViewCell.swift index 6121f34ef..935a24ecc 100644 --- a/iOS/MasterFeed/Cell/MasterFeedTableViewCell.swift +++ b/iOS/MasterFeed/Cell/MasterFeedTableViewCell.swift @@ -93,7 +93,7 @@ class MasterFeedTableViewCell : UITableViewCell { }() private let faviconImageView: UIImageView = { - return UIImageView(image: AppAssets.feedImage) + return NonIntrinsicImageView(image: AppAssets.feedImage) }() private var unreadCountView = MasterFeedUnreadCountView(frame: CGRect.zero) @@ -156,7 +156,7 @@ private extension MasterFeedTableViewCell { func addDisclosureView() { - disclosureButton = UIButton(type: .roundedRect) + disclosureButton = NonIntrinsicButton(type: .roundedRect) disclosureButton!.tintColor = AppAssets.chevronDisclosureColor disclosureButton!.addTarget(self, action: #selector(buttonPressed(_:)), for: UIControl.Event.touchUpInside) diff --git a/iOS/MasterFeed/Cell/MasterFeedTableViewCellLayout.swift b/iOS/MasterFeed/Cell/MasterFeedTableViewCellLayout.swift index 23981e87a..6da4a0345 100644 --- a/iOS/MasterFeed/Cell/MasterFeedTableViewCellLayout.swift +++ b/iOS/MasterFeed/Cell/MasterFeedTableViewCellLayout.swift @@ -52,7 +52,7 @@ struct MasterFeedTableViewCellLayout { separatorInsets = UIEdgeInsets(top: 0, left: rFavicon.maxX + MasterFeedTableViewCellLayout.imageMarginRight, bottom: 0, right: 0) // Unread Count - let unreadCountSize = unreadCountView.intrinsicContentSize + let unreadCountSize = unreadCountView.contentSize let unreadCountIsHidden = unreadCountView.unreadCount < 1 var rUnread = CGRect.zero diff --git a/iOS/MasterFeed/Cell/MasterFeedUnreadCountView.swift b/iOS/MasterFeed/Cell/MasterFeedUnreadCountView.swift index a86edb2b7..855e464c0 100644 --- a/iOS/MasterFeed/Cell/MasterFeedUnreadCountView.swift +++ b/iOS/MasterFeed/Cell/MasterFeedUnreadCountView.swift @@ -31,8 +31,8 @@ class MasterFeedUnreadCountView : UIView { return unreadCount < 1 ? "" : "\(unreadCount)" } - private var intrinsicContentSizeIsValid = false - private var _intrinsicContentSize = CGSize.zero + private var contentSizeIsValid = false + private var _contentSize = CGSize.zero override init(frame: CGRect) { super.init(frame: frame) @@ -46,26 +46,27 @@ class MasterFeedUnreadCountView : UIView { override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { textSizeCache = [Int: CGSize]() - invalidateIntrinsicContentSize() + contentSizeIsValid = false setNeedsDisplay() } - override var intrinsicContentSize: CGSize { - if !intrinsicContentSizeIsValid { + var contentSize: CGSize { + if !contentSizeIsValid { var size = CGSize.zero if unreadCount > 0 { size = textSize() size.width += (padding.left + padding.right) size.height += (padding.top + padding.bottom) } - _intrinsicContentSize = size - intrinsicContentSizeIsValid = true + _contentSize = size + contentSizeIsValid = true } - return _intrinsicContentSize + return _contentSize } - override func invalidateIntrinsicContentSize() { - intrinsicContentSizeIsValid = false + // Prevent autolayout from messing around with our frame settings + override var intrinsicContentSize: CGSize { + return CGSize(width: UIView.noIntrinsicMetric, height: UIView.noIntrinsicMetric) } private func textSize() -> CGSize { diff --git a/iOS/MasterFeed/MasterFeedViewController.swift b/iOS/MasterFeed/MasterFeedViewController.swift index d8951a81d..14bd25023 100644 --- a/iOS/MasterFeed/MasterFeedViewController.swift +++ b/iOS/MasterFeed/MasterFeedViewController.swift @@ -281,16 +281,16 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner { } -// override func tableView(_ tableView: UITableView, contextMenuConfigurationForRowAt indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration? { -// guard let node = coordinator.nodeFor(indexPath), !(node.representedObject is PseudoFeed) else { -// return nil -// } -// if node.representedObject is Feed { -// return makeFeedContextMenu(indexPath: indexPath, includeDeleteRename: true) -// } else { -// return makeFolderContextMenu(indexPath: indexPath) -// } -// } + override func tableView(_ tableView: UITableView, contextMenuConfigurationForRowAt indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration? { + guard let node = coordinator.nodeFor(indexPath), !(node.representedObject is PseudoFeed) else { + return nil + } + if node.representedObject is Feed { + return makeFeedContextMenu(indexPath: indexPath, includeDeleteRename: true) + } else { + return makeFolderContextMenu(indexPath: indexPath) + } + } override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { coordinator.selectFeed(indexPath)