From 061872b7ffb79b1a27478617bd03f4e9fba1d592 Mon Sep 17 00:00:00 2001 From: Jim Correia Date: Mon, 2 Sep 2019 22:39:01 -0700 Subject: [PATCH] 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