From 932f6fdd30a2e2b2042505694168d2f34ff8b20f Mon Sep 17 00:00:00 2001 From: Jim Correia Date: Mon, 2 Sep 2019 19:02:07 -0700 Subject: [PATCH 1/2] Added NNWTableViewCell; a base class for cells with the NNW selection color. Defined a semantic color for the selection color which is identical to netNewsWireBlue. MasterFeedTableViewCell and MasterTimelineTableViewCell now subclass NNWTableViewCell and no longer directly customize their selected background view. --- NetNewsWire.xcodeproj/project.pbxproj | 20 ++++++++-- iOS/AppAssets.swift | 4 ++ .../Cell/MasterFeedTableViewCell.swift | 9 +---- .../Cell/MasterTimelineTableViewCell.swift | 9 +---- .../Contents.json | 38 +++++++++++++++++++ iOS/Views/NNWTableViewCell.swift | 32 ++++++++++++++++ 6 files changed, 92 insertions(+), 20 deletions(-) create mode 100644 iOS/Resources/Assets.xcassets/tableViewCellSelectionColor.colorset/Contents.json create mode 100644 iOS/Views/NNWTableViewCell.swift diff --git a/NetNewsWire.xcodeproj/project.pbxproj b/NetNewsWire.xcodeproj/project.pbxproj index 467cd87af..b6330c445 100644 --- a/NetNewsWire.xcodeproj/project.pbxproj +++ b/NetNewsWire.xcodeproj/project.pbxproj @@ -159,6 +159,7 @@ 51F85BFD2275DCA800C787DC /* SingleLineUILabelSizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51F85BFC2275DCA800C787DC /* SingleLineUILabelSizer.swift */; }; 55E15BCB229D65A900D6602A /* AccountsReaderAPI.xib in Resources */ = {isa = PBXBuildFile; fileRef = 55E15BC1229D65A900D6602A /* AccountsReaderAPI.xib */; }; 55E15BCC229D65A900D6602A /* AccountsReaderAPIWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55E15BCA229D65A900D6602A /* AccountsReaderAPIWindowController.swift */; }; + 5F323809231DF9F000706F6B /* NNWTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F323808231DF9F000706F6B /* NNWTableViewCell.swift */; }; 6581C73820CED60100F4AD34 /* SafariExtensionHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6581C73720CED60100F4AD34 /* SafariExtensionHandler.swift */; }; 6581C73A20CED60100F4AD34 /* SafariExtensionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6581C73920CED60100F4AD34 /* SafariExtensionViewController.swift */; }; 6581C73D20CED60100F4AD34 /* SafariExtensionViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6581C73B20CED60100F4AD34 /* SafariExtensionViewController.xib */; }; @@ -773,6 +774,7 @@ 557EE1A522B6F4E1004206FA /* SettingsReaderAPIAccountView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingsReaderAPIAccountView.swift; sourceTree = ""; }; 55E15BC1229D65A900D6602A /* AccountsReaderAPI.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = AccountsReaderAPI.xib; sourceTree = ""; }; 55E15BCA229D65A900D6602A /* AccountsReaderAPIWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AccountsReaderAPIWindowController.swift; sourceTree = ""; }; + 5F323808231DF9F000706F6B /* NNWTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NNWTableViewCell.swift; sourceTree = ""; }; 6581C73320CED60000F4AD34 /* Subscribe to Feed.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = "Subscribe to Feed.appex"; sourceTree = BUILT_PRODUCTS_DIR; }; 6581C73420CED60100F4AD34 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; }; 6581C73720CED60100F4AD34 /* SafariExtensionHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SafariExtensionHandler.swift; sourceTree = ""; }; @@ -1244,6 +1246,14 @@ path = UIKit; sourceTree = ""; }; + 5F3237FF231DF9D000706F6B /* Views */ = { + isa = PBXGroup; + children = ( + 5F323808231DF9F000706F6B /* NNWTableViewCell.swift */, + ); + path = Views; + sourceTree = ""; + }; 6581C73620CED60100F4AD34 /* SafariExtension */ = { isa = PBXGroup; children = ( @@ -1766,6 +1776,7 @@ 5183CCEB227117C70010922C /* Settings */, 5183CCDB226F1EEB0010922C /* Progress */, 51C45245226506C800C03939 /* Extensions */, + 5F3237FF231DF9D000706F6B /* Views */, 5194B5E222B693EC00144881 /* Wrappers */, 84C9FC9A2262A1A900D921D6 /* Resources */, ); @@ -2018,11 +2029,11 @@ TargetAttributes = { 6581C73220CED60000F4AD34 = { DevelopmentTeam = SHJK2V3AJG; - ProvisioningStyle = Automatic; + ProvisioningStyle = Manual; }; 840D617B2029031C009BC708 = { CreatedOnToolsVersion = 9.3; - DevelopmentTeam = SHJK2V3AJG; + DevelopmentTeam = DY2XQRVWN9; ProvisioningStyle = Automatic; SystemCapabilities = { com.apple.BackgroundModes = { @@ -2033,7 +2044,7 @@ 849C645F1ED37A5D003D8FC0 = { CreatedOnToolsVersion = 8.2.1; DevelopmentTeam = SHJK2V3AJG; - ProvisioningStyle = Automatic; + ProvisioningStyle = Manual; SystemCapabilities = { com.apple.HardenedRuntime = { enabled = 1; @@ -2042,7 +2053,7 @@ }; 849C64701ED37A5D003D8FC0 = { CreatedOnToolsVersion = 8.2.1; - DevelopmentTeam = SHJK2V3AJG; + DevelopmentTeam = 9C84TZ7Q6Z; ProvisioningStyle = Automatic; TestTargetID = 849C645F1ED37A5D003D8FC0; }; @@ -2431,6 +2442,7 @@ 51C452A622650A3500C03939 /* Node-Extensions.swift in Sources */, 5183CCDF226F1FCC0010922C /* UINavigationController+Progress.swift in Sources */, 51C45294226509C800C03939 /* SearchFeedDelegate.swift in Sources */, + 5F323809231DF9F000706F6B /* NNWTableViewCell.swift in Sources */, 512E09352268B25900BDCFDD /* UISplitViewController-Extensions.swift in Sources */, 51C452A022650A1900C03939 /* FeedIconDownloader.swift in Sources */, 51F85BE7227245FC00C787DC /* AboutViewController.swift in Sources */, diff --git a/iOS/AppAssets.swift b/iOS/AppAssets.swift index 6b18f8f42..ecf5e5e85 100644 --- a/iOS/AppAssets.swift +++ b/iOS/AppAssets.swift @@ -128,6 +128,10 @@ struct AppAssets { return UIImage(systemName: "star")! }() + static var tableViewCellSelectionColor: UIColor = { + return UIColor(named: "tableViewCellSelectionColor")! + }() + static var timelineStarImage: UIImage = { let image = UIImage(systemName: "star.fill")! return image.withTintColor(AppAssets.starColor, renderingMode: .alwaysOriginal) diff --git a/iOS/MasterFeed/Cell/MasterFeedTableViewCell.swift b/iOS/MasterFeed/Cell/MasterFeedTableViewCell.swift index 935a24ecc..876b631b2 100644 --- a/iOS/MasterFeed/Cell/MasterFeedTableViewCell.swift +++ b/iOS/MasterFeed/Cell/MasterFeedTableViewCell.swift @@ -15,7 +15,7 @@ protocol MasterFeedTableViewCellDelegate: class { func disclosureSelected(_ sender: MasterFeedTableViewCell, expanding: Bool) } -class MasterFeedTableViewCell : UITableViewCell { +class MasterFeedTableViewCell : NNWTableViewCell { weak var delegate: MasterFeedTableViewCellDelegate? var allowDisclosureSelection = false @@ -141,19 +141,12 @@ class MasterFeedTableViewCell : UITableViewCell { private extension MasterFeedTableViewCell { func commonInit() { - theme() addSubviewAtInit(unreadCountView) addSubviewAtInit(faviconImageView) addSubviewAtInit(titleView) addDisclosureView() } - func theme() { - let bgView = UIView() - bgView.backgroundColor = AppAssets.netNewsWireBlueColor - selectedBackgroundView = bgView - } - func addDisclosureView() { disclosureButton = NonIntrinsicButton(type: .roundedRect) diff --git a/iOS/MasterTimeline/Cell/MasterTimelineTableViewCell.swift b/iOS/MasterTimeline/Cell/MasterTimelineTableViewCell.swift index 7b10d7079..f03f4c6c9 100644 --- a/iOS/MasterTimeline/Cell/MasterTimelineTableViewCell.swift +++ b/iOS/MasterTimeline/Cell/MasterTimelineTableViewCell.swift @@ -9,7 +9,7 @@ import UIKit import RSCore -class MasterTimelineTableViewCell: UITableViewCell { +class MasterTimelineTableViewCell: NNWTableViewCell { private let titleView = MasterTimelineTableViewCell.multiLineUILabel() private let summaryView = MasterTimelineTableViewCell.multiLineUILabel() @@ -124,7 +124,6 @@ private extension MasterTimelineTableViewCell { func commonInit() { - theme() addAccessoryView() addSubviewAtInit(titleView, hidden: false) addSubviewAtInit(summaryView, hidden: true) @@ -136,12 +135,6 @@ private extension MasterTimelineTableViewCell { } - func theme() { - let bgView = UIView() - bgView.backgroundColor = AppAssets.netNewsWireBlueColor - selectedBackgroundView = bgView - } - func addAccessoryView() { accessoryView = UIImageView(image: AppAssets.chevronRightImage) } diff --git a/iOS/Resources/Assets.xcassets/tableViewCellSelectionColor.colorset/Contents.json b/iOS/Resources/Assets.xcassets/tableViewCellSelectionColor.colorset/Contents.json new file mode 100644 index 000000000..f488c73d7 --- /dev/null +++ b/iOS/Resources/Assets.xcassets/tableViewCellSelectionColor.colorset/Contents.json @@ -0,0 +1,38 @@ +{ + "info" : { + "version" : 1, + "author" : "xcode" + }, + "colors" : [ + { + "idiom" : "universal", + "color" : { + "color-space" : "srgb", + "components" : { + "red" : "0.031", + "alpha" : "1.000", + "blue" : "0.933", + "green" : "0.416" + } + } + }, + { + "idiom" : "universal", + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "dark" + } + ], + "color" : { + "color-space" : "srgb", + "components" : { + "red" : "0.267", + "alpha" : "1.000", + "blue" : "0.886", + "green" : "0.565" + } + } + } + ] +} \ No newline at end of file diff --git a/iOS/Views/NNWTableViewCell.swift b/iOS/Views/NNWTableViewCell.swift new file mode 100644 index 000000000..140706dad --- /dev/null +++ b/iOS/Views/NNWTableViewCell.swift @@ -0,0 +1,32 @@ +// +// NNWTableViewCell.swift +// NetNewsWire-iOS +// +// Created by Jim Correia on 9/2/19. +// Copyright © 2019 Ranchero Software. All rights reserved. +// + +import UIKit + +class NNWTableViewCell: UITableViewCell { + override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { + super.init(style: style, reuseIdentifier: reuseIdentifier) + commonInit() + } + + required init?(coder: NSCoder) { + super.init(coder: coder) + commonInit() + } + + private func commonInit() { + applyThemeProperties() + } + + /// Subclass overrides should call super + func applyThemeProperties() { + let selectedBackgroundView = UIView(frame: .zero) + selectedBackgroundView.backgroundColor = AppAssets.tableViewCellSelectionColor + self.selectedBackgroundView = selectedBackgroundView + } +} From 061872b7ffb79b1a27478617bd03f4e9fba1d592 Mon Sep 17 00:00:00 2001 From: Jim Correia Date: Mon, 2 Sep 2019 22:39:01 -0700 Subject: [PATCH 2/2] Simplified/corrected highlighted/selected appearance of feed and timeline cells. - Set the highlighted text color on labels in table cells. This will be used for both the highlight and selected states automatically. (And since it is used for both states, we avoid anachronistic state where we have black text on a dark blue background in light mode as we transition from none -> highlighted -> selected.) - Keep the selected/highlighted overrides to adjust colors for non-UIControl subelements. --- iOS/AppAssets.swift | 8 +++---- .../Cell/MasterFeedTableViewCell.swift | 17 +++++++++++-- .../Cell/MasterTimelineTableViewCell.swift | 24 +++++++++++++------ .../Cell/MasterUnreadIndicatorView.swift | 7 ++---- .../Contents.json | 13 ++++++++++ 5 files changed, 51 insertions(+), 18 deletions(-) rename iOS/Resources/Assets.xcassets/{selectedTextColor.colorset => tableViewCellHighlightedTextColor.colorset}/Contents.json (56%) diff --git a/iOS/AppAssets.swift b/iOS/AppAssets.swift index ecf5e5e85..276b0afe9 100644 --- a/iOS/AppAssets.swift +++ b/iOS/AppAssets.swift @@ -96,10 +96,6 @@ struct AppAssets { return UIImage(systemName: "safari")! }() - static var selectedTextColor: UIColor = { - return UIColor(named: "selectedTextColor")! - }() - static var settingsImage: UIImage = { return UIImage(named: "settingsImage")! }() @@ -128,6 +124,10 @@ struct AppAssets { return UIImage(systemName: "star")! }() + static var tableViewCellHighlightedTextColor: UIColor = { + return UIColor(named: "tableViewCellHighlightedTextColor")! + }() + static var tableViewCellSelectionColor: UIColor = { return UIColor(named: "tableViewCellSelectionColor")! }() diff --git a/iOS/MasterFeed/Cell/MasterFeedTableViewCell.swift b/iOS/MasterFeed/Cell/MasterFeedTableViewCell.swift index 876b631b2..3a91cd5d4 100644 --- a/iOS/MasterFeed/Cell/MasterFeedTableViewCell.swift +++ b/iOS/MasterFeed/Cell/MasterFeedTableViewCell.swift @@ -104,11 +104,24 @@ class MasterFeedTableViewCell : NNWTableViewCell { super.init(coder: coder) commonInit() } + + override func applyThemeProperties() { + super.applyThemeProperties() + titleView.highlightedTextColor = AppAssets.tableViewCellHighlightedTextColor + } + + override func setHighlighted(_ highlighted: Bool, animated: Bool) { + super.setHighlighted(highlighted, animated: animated) + + let tintColor = isHighlighted || isSelected ? AppAssets.tableViewCellHighlightedTextColor : AppAssets.netNewsWireBlueColor + faviconImageView.tintColor = tintColor + } override func setSelected(_ selected: Bool, animated: Bool) { - titleView.textColor = selected ? AppAssets.selectedTextColor : UIColor.label - faviconImageView.tintColor = selected ? AppAssets.selectedTextColor : AppAssets.netNewsWireBlueColor super.setSelected(selected, animated: animated) + + let tintColor = isHighlighted || isSelected ? AppAssets.tableViewCellHighlightedTextColor : AppAssets.netNewsWireBlueColor + faviconImageView.tintColor = tintColor } override func willTransition(to state: UITableViewCell.StateMask) { diff --git a/iOS/MasterTimeline/Cell/MasterTimelineTableViewCell.swift b/iOS/MasterTimeline/Cell/MasterTimelineTableViewCell.swift index f03f4c6c9..1fc979a8d 100644 --- a/iOS/MasterTimeline/Cell/MasterTimelineTableViewCell.swift +++ b/iOS/MasterTimeline/Cell/MasterTimelineTableViewCell.swift @@ -38,21 +38,31 @@ class MasterTimelineTableViewCell: NNWTableViewCell { commonInit() } + override func applyThemeProperties() { + super.applyThemeProperties() + + let highlightedTextColor = AppAssets.tableViewCellHighlightedTextColor + + titleView.highlightedTextColor = highlightedTextColor + summaryView.highlightedTextColor = highlightedTextColor + dateView.highlightedTextColor = highlightedTextColor + feedNameView.highlightedTextColor = highlightedTextColor + } + override var frame: CGRect { didSet { setNeedsLayout() } } + override func setHighlighted(_ highlighted: Bool, animated: Bool) { + super.setHighlighted(highlighted, animated: animated) + unreadIndicatorView.isSelected = isHighlighted || isSelected + } + override func setSelected(_ selected: Bool, animated: Bool) { - let selectedTextColor = selected ? AppAssets.selectedTextColor : UIColor.label - titleView.textColor = selectedTextColor - summaryView.textColor = selectedTextColor - dateView.textColor = selectedTextColor - feedNameView.textColor = selectedTextColor - unreadIndicatorView.isSelected = selected - super.setSelected(selected, animated: animated) + unreadIndicatorView.isSelected = isHighlighted || isSelected } override func sizeThatFits(_ size: CGSize) -> CGSize { diff --git a/iOS/MasterTimeline/Cell/MasterUnreadIndicatorView.swift b/iOS/MasterTimeline/Cell/MasterUnreadIndicatorView.swift index d09cd8f34..e2e1c3fed 100644 --- a/iOS/MasterTimeline/Cell/MasterUnreadIndicatorView.swift +++ b/iOS/MasterTimeline/Cell/MasterUnreadIndicatorView.swift @@ -32,11 +32,8 @@ class MasterUnreadIndicatorView: UIView { }() override func draw(_ dirtyRect: CGRect) { - if isSelected { - AppAssets.selectedTextColor.setFill() - } else { - AppAssets.timelineUnreadCircleColor.setFill() - } + let color = isSelected ? AppAssets.tableViewCellHighlightedTextColor : AppAssets.timelineUnreadCircleColor + color.setFill() MasterUnreadIndicatorView.bezierPath.fill() } diff --git a/iOS/Resources/Assets.xcassets/selectedTextColor.colorset/Contents.json b/iOS/Resources/Assets.xcassets/tableViewCellHighlightedTextColor.colorset/Contents.json similarity index 56% rename from iOS/Resources/Assets.xcassets/selectedTextColor.colorset/Contents.json rename to iOS/Resources/Assets.xcassets/tableViewCellHighlightedTextColor.colorset/Contents.json index c6e5d3d43..f425bf252 100644 --- a/iOS/Resources/Assets.xcassets/selectedTextColor.colorset/Contents.json +++ b/iOS/Resources/Assets.xcassets/tableViewCellHighlightedTextColor.colorset/Contents.json @@ -15,6 +15,19 @@ "green" : "1.000" } } + }, + { + "idiom" : "universal", + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "dark" + } + ], + "color" : { + "platform" : "ios", + "reference" : "labelColor" + } } ] } \ No newline at end of file