From 8fb87a7c87804ae588d28a660947c0b50bc2c8b7 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Sat, 2 Nov 2019 19:57:01 -0500 Subject: [PATCH] Update label animations to match cell selection fading and changed table animation speeds to 1.5. Issue #1237 --- iOS/AppAssets.swift | 6 ++-- .../Cell/MasterFeedTableViewCell.swift | 28 +++++---------- iOS/MasterFeed/MasterFeedViewController.swift | 2 +- .../Cell/MasterTimelineTableViewCell.swift | 32 ++++++----------- .../MasterTimelineViewController.swift | 5 +++ .../Contents.json | 28 --------------- iOS/Settings/Settings.storyboard | 1 - .../SettingsAccountTableViewCell.swift | 23 +++---------- iOS/Settings/SettingsTableViewCell.xib | 18 +++++++++- iOS/Settings/SettingsViewController.swift | 20 ++++++++--- .../VibrantTableViewCell.swift | 34 +++++++++++++++++-- 11 files changed, 97 insertions(+), 100 deletions(-) delete mode 100644 iOS/Resources/Assets.xcassets/timelineBackgroundColor.colorset/Contents.json diff --git a/iOS/AppAssets.swift b/iOS/AppAssets.swift index 2dda0cf04..94ec25bcf 100644 --- a/iOS/AppAssets.swift +++ b/iOS/AppAssets.swift @@ -10,6 +10,8 @@ import RSCore import Account struct AppAssets { + + static let layerSpeed: Float = 1.5 static var accountLocalPadImage: UIImage = { return UIImage(named: "accountLocalPad")! @@ -161,10 +163,6 @@ struct AppAssets { return UIImage(systemName: "star.fill")! }() - static var timelineBackgroundColor: UIColor = { - return UIColor(named: "timelineBackgroundColor")! - }() - 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 9e1b7523b..ff5d48a6d 100644 --- a/iOS/MasterFeed/Cell/MasterFeedTableViewCell.swift +++ b/iOS/MasterFeed/Cell/MasterFeedTableViewCell.swift @@ -127,19 +127,8 @@ class MasterFeedTableViewCell : VibrantTableViewCell { override func applyThemeProperties() { super.applyThemeProperties() - titleView.highlightedTextColor = AppAssets.vibrantTextColor } - override func setHighlighted(_ highlighted: Bool, animated: Bool) { - super.setHighlighted(highlighted, animated: animated) - updateVibrancy(animated: animated) - } - - override func setSelected(_ selected: Bool, animated: Bool) { - super.setSelected(selected, animated: animated) - updateVibrancy(animated: animated) - } - override func willTransition(to state: UITableViewCell.StateMask) { super.willTransition(to: state) isShowingEditControl = state.contains(.showingEditControl) @@ -163,6 +152,15 @@ class MasterFeedTableViewCell : VibrantTableViewCell { } } + override func updateVibrancy(animated: Bool) { + super.updateVibrancy(animated: animated) + let avatarTintColor = isHighlighted || isSelected ? AppAssets.vibrantTextColor : AppAssets.secondaryAccentColor + UIView.animate(withDuration: duration(animated: animated)) { + self.avatarView.tintColor = avatarTintColor + } + updateLabelVibrancy(titleView, animated: animated) + } + } private extension MasterFeedTableViewCell { @@ -199,14 +197,6 @@ private extension MasterFeedTableViewCell { bottomSeparatorView.setFrameIfNotEqual(layout.separatorRect) } - func updateVibrancy(animated: Bool) { - let avatarTintColor = isHighlighted || isSelected ? AppAssets.vibrantTextColor : AppAssets.secondaryAccentColor - let duration = animated ? 0.6 : 0.0 - UIView.animate(withDuration: duration) { - self.avatarView.tintColor = avatarTintColor - } - } - func hideView(_ view: UIView) { if !view.isHidden { view.isHidden = true diff --git a/iOS/MasterFeed/MasterFeedViewController.swift b/iOS/MasterFeed/MasterFeedViewController.swift index 202788d8b..65ffa17e0 100644 --- a/iOS/MasterFeed/MasterFeedViewController.swift +++ b/iOS/MasterFeed/MasterFeedViewController.swift @@ -75,7 +75,7 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner { override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) - tableView.layer.speed = 2.0 + tableView.layer.speed = AppAssets.layerSpeed } // MARK: Notifications diff --git a/iOS/MasterTimeline/Cell/MasterTimelineTableViewCell.swift b/iOS/MasterTimeline/Cell/MasterTimelineTableViewCell.swift index 9100b0571..63fc84e1b 100644 --- a/iOS/MasterTimeline/Cell/MasterTimelineTableViewCell.swift +++ b/iOS/MasterTimeline/Cell/MasterTimelineTableViewCell.swift @@ -34,35 +34,23 @@ class MasterTimelineTableViewCell: VibrantTableViewCell { commonInit() } - override func applyThemeProperties() { - super.applyThemeProperties() - - let highlightedTextColor = AppAssets.vibrantTextColor - - titleView.highlightedTextColor = highlightedTextColor - summaryView.highlightedTextColor = highlightedTextColor - dateView.highlightedTextColor = highlightedTextColor - feedNameView.highlightedTextColor = highlightedTextColor - - backgroundColor = AppAssets.timelineBackgroundColor - } - override var frame: CGRect { didSet { setNeedsLayout() } } - override func setHighlighted(_ highlighted: Bool, animated: Bool) { - super.setHighlighted(highlighted, animated: animated) - unreadIndicatorView.isSelected = isHighlighted || isSelected + override func updateVibrancy(animated: Bool) { + updateLabelVibrancy(titleView, animated: animated) + updateLabelVibrancy(summaryView, animated: animated) + updateLabelVibrancy(dateView, animated: animated) + updateLabelVibrancy(feedNameView, animated: animated) + + UIView.animate(withDuration: duration(animated: animated)) { + self.unreadIndicatorView.isSelected = self.isHighlighted || self.isSelected + } } - - override func setSelected(_ selected: Bool, animated: Bool) { - super.setSelected(selected, animated: animated) - unreadIndicatorView.isSelected = isHighlighted || isSelected - } - + override func sizeThatFits(_ size: CGSize) -> CGSize { let layout = updatedLayout(width: size.width) return CGSize(width: size.width, height: layout.height) diff --git a/iOS/MasterTimeline/MasterTimelineViewController.swift b/iOS/MasterTimeline/MasterTimelineViewController.swift index 78c7ab56c..9c1c28a76 100644 --- a/iOS/MasterTimeline/MasterTimelineViewController.swift +++ b/iOS/MasterTimeline/MasterTimelineViewController.swift @@ -74,6 +74,11 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner super.viewWillAppear(animated) } + override func viewDidAppear(_ animated: Bool) { + super.viewDidAppear(animated) + tableView.layer.speed = AppAssets.layerSpeed + } + // MARK: Actions @IBAction func markAllAsRead(_ sender: Any) { diff --git a/iOS/Resources/Assets.xcassets/timelineBackgroundColor.colorset/Contents.json b/iOS/Resources/Assets.xcassets/timelineBackgroundColor.colorset/Contents.json deleted file mode 100644 index 702421056..000000000 --- a/iOS/Resources/Assets.xcassets/timelineBackgroundColor.colorset/Contents.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "info" : { - "version" : 1, - "author" : "xcode" - }, - "colors" : [ - { - "idiom" : "universal", - "color" : { - "platform" : "ios", - "reference" : "systemBackgroundColor" - } - }, - { - "idiom" : "universal", - "appearances" : [ - { - "appearance" : "luminosity", - "value" : "dark" - } - ], - "color" : { - "platform" : "ios", - "reference" : "systemBackgroundColor" - } - } - ] -} \ No newline at end of file diff --git a/iOS/Settings/Settings.storyboard b/iOS/Settings/Settings.storyboard index a49be81f1..6ab806122 100644 --- a/iOS/Settings/Settings.storyboard +++ b/iOS/Settings/Settings.storyboard @@ -353,7 +353,6 @@ - diff --git a/iOS/Settings/SettingsAccountTableViewCell.swift b/iOS/Settings/SettingsAccountTableViewCell.swift index 0ae9a6ec2..d958b5087 100644 --- a/iOS/Settings/SettingsAccountTableViewCell.swift +++ b/iOS/Settings/SettingsAccountTableViewCell.swift @@ -13,25 +13,12 @@ class SettingsAccountTableViewCell: VibrantTableViewCell { @IBOutlet weak var accountImage: UIImageView! @IBOutlet weak var accountNameLabel: UILabel! - override func setHighlighted(_ highlighted: Bool, animated: Bool) { - super.setHighlighted(highlighted, animated: animated) - updateVibrancy(animated: animated) - } - - override func setSelected(_ selected: Bool, animated: Bool) { - super.setSelected(selected, animated: animated) - updateVibrancy(animated: animated) - } - - override func applyThemeProperties() { - super.applyThemeProperties() - accountNameLabel?.highlightedTextColor = AppAssets.vibrantTextColor - } - - func updateVibrancy(animated: Bool) { + override func updateVibrancy(animated: Bool) { + super.updateVibrancy(animated: animated) + updateLabelVibrancy(accountNameLabel, animated: animated) + let tintColor = isHighlighted || isSelected ? AppAssets.vibrantTextColor : UIColor.label - let duration = animated ? 0.6 : 0.0 - UIView.animate(withDuration: duration) { + UIView.animate(withDuration: duration(animated: animated)) { self.accountImage?.tintColor = tintColor } } diff --git a/iOS/Settings/SettingsTableViewCell.xib b/iOS/Settings/SettingsTableViewCell.xib index 71f516107..76a7cdfcc 100644 --- a/iOS/Settings/SettingsTableViewCell.xib +++ b/iOS/Settings/SettingsTableViewCell.xib @@ -8,12 +8,28 @@ - + + + + + diff --git a/iOS/Settings/SettingsViewController.swift b/iOS/Settings/SettingsViewController.swift index b7c926536..0b155f06b 100644 --- a/iOS/Settings/SettingsViewController.swift +++ b/iOS/Settings/SettingsViewController.swift @@ -17,7 +17,6 @@ class SettingsViewController: UITableViewController { static let preferredContentSizeForFormSheetDisplay = CGSize(width: 460.0, height: 400.0) - @IBOutlet weak var refreshIntervalLabel: UILabel! @IBOutlet weak var timelineSortOrderSwitch: UISwitch! @IBOutlet weak var groupByFeedSwitch: UISwitch! @IBOutlet weak var numberOfTextLinesLabel: UILabel! @@ -33,6 +32,7 @@ class SettingsViewController: UITableViewController { NotificationCenter.default.addObserver(self, selector: #selector(accountsDidChange), name: .UserDidAddAccount, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(accountsDidChange), name: .UserDidDeleteAccount, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(displayNameDidChange), name: .DisplayNameDidChange, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(userDefaultsDidChange), name: UserDefaults.didChangeNotification, object: nil) tableView.register(UINib(nibName: "SettingsAccountTableViewCell", bundle: nil), forCellReuseIdentifier: "SettingsAccountTableViewCell") tableView.register(UINib(nibName: "SettingsTableViewCell", bundle: nil), forCellReuseIdentifier: "SettingsTableViewCell") @@ -54,8 +54,6 @@ class SettingsViewController: UITableViewController { groupByFeedSwitch.isOn = false } - refreshIntervalLabel.text = AppDefaults.refreshInterval.description() - let numberOfTextLines = AppDefaults.timelineNumberOfLines numberOfTextLinesSteppper.value = Double(numberOfTextLines) updateNumberOfTextLinesLabel(value: numberOfTextLines) @@ -76,6 +74,7 @@ class SettingsViewController: UITableViewController { override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) + tableView.layer.speed = AppAssets.layerSpeed self.tableView.selectRow(at: nil, animated: true, scrollPosition: .none) } @@ -104,7 +103,6 @@ class SettingsViewController: UITableViewController { let sortedAccounts = AccountManager.shared.sortedAccounts if indexPath.row == sortedAccounts.count { cell = tableView.dequeueReusableCell(withIdentifier: "SettingsTableViewCell", for: indexPath) - cell.textLabel?.adjustsFontForContentSizeCategory = true cell.textLabel?.text = NSLocalizedString("Add Account", comment: "Accounts") } else { let acctCell = tableView.dequeueReusableCell(withIdentifier: "SettingsAccountTableViewCell", for: indexPath) as! SettingsAccountTableViewCell @@ -114,6 +112,16 @@ class SettingsViewController: UITableViewController { acctCell.accountNameLabel?.text = account.nameForDisplay cell = acctCell } + + case 2: + + if indexPath.row == 0 { + cell = tableView.dequeueReusableCell(withIdentifier: "SettingsTableViewCell", for: indexPath) + cell.textLabel?.text = NSLocalizedString("Refresh Interval", comment: "Refresh Interval") + cell.detailTextLabel?.text = AppDefaults.refreshInterval.description() + } else { + cell = super.tableView(tableView, cellForRowAt: indexPath) + } default: @@ -260,6 +268,10 @@ class SettingsViewController: UITableViewController { tableView.reloadData() } + @objc func userDefaultsDidChange() { + tableView.reloadData() + } + } // MARK: OPML Document Picker diff --git a/iOS/UIKit Extensions/VibrantTableViewCell.swift b/iOS/UIKit Extensions/VibrantTableViewCell.swift index bd6998bca..c49c1a5e1 100644 --- a/iOS/UIKit Extensions/VibrantTableViewCell.swift +++ b/iOS/UIKit Extensions/VibrantTableViewCell.swift @@ -10,6 +10,10 @@ import UIKit class VibrantTableViewCell: UITableViewCell { + var labelColor: UIColor { + return isHighlighted || isSelected ? AppAssets.vibrantTextColor : UIColor.label + } + override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { super.init(style: style, reuseIdentifier: reuseIdentifier) commonInit() @@ -23,13 +27,39 @@ class VibrantTableViewCell: UITableViewCell { private func commonInit() { applyThemeProperties() } + + override func setHighlighted(_ highlighted: Bool, animated: Bool) { + super.setHighlighted(highlighted, animated: animated) + updateVibrancy(animated: animated) + } + + override func setSelected(_ selected: Bool, animated: Bool) { + super.setSelected(selected, animated: animated) + updateVibrancy(animated: animated) + } /// Subclass overrides should call super func applyThemeProperties() { let selectedBackgroundView = UIView(frame: .zero) selectedBackgroundView.backgroundColor = AppAssets.secondaryAccentColor self.selectedBackgroundView = selectedBackgroundView - - textLabel?.highlightedTextColor = AppAssets.vibrantTextColor } + + /// Subclass overrides should call super + func updateVibrancy(animated: Bool) { + updateLabelVibrancy(textLabel, animated: animated) + updateLabelVibrancy(detailTextLabel, animated: animated) + } + + func duration(animated: Bool) -> TimeInterval { + return animated ? 0.6 : 0.0 + } + + func updateLabelVibrancy(_ label: UILabel?, animated: Bool) { + guard let label = label else { return } + UIView.transition(with: label, duration: duration(animated: animated), options: .transitionCrossDissolve, animations: { + label.textColor = self.labelColor + }, completion: nil) + } + }