From eea450bee341d8c57a6450eb48133c5bce0393ec Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Wed, 23 Oct 2019 11:47:21 -0500 Subject: [PATCH] Make icon vibrancy deselections match the deselection animation --- .../Cell/MasterFeedTableViewCell.swift | 19 +++++++++++-------- .../SettingsAccountTableViewCell.swift | 19 ++++++++++++++----- iOS/Settings/SettingsViewController.swift | 1 + 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/iOS/MasterFeed/Cell/MasterFeedTableViewCell.swift b/iOS/MasterFeed/Cell/MasterFeedTableViewCell.swift index 3662b829a..d128d93f4 100644 --- a/iOS/MasterFeed/Cell/MasterFeedTableViewCell.swift +++ b/iOS/MasterFeed/Cell/MasterFeedTableViewCell.swift @@ -133,18 +133,12 @@ class MasterFeedTableViewCell : VibrantTableViewCell { override func setHighlighted(_ highlighted: Bool, animated: Bool) { super.setHighlighted(highlighted, animated: animated) - - let tintColor = isHighlighted || isSelected ? AppAssets.vibrantTextColor : AppAssets.secondaryAccentColor - disclosureButton?.tintColor = tintColor - faviconImageView.tintColor = tintColor + updateVibrancy(animated: animated) } override func setSelected(_ selected: Bool, animated: Bool) { super.setSelected(selected, animated: animated) - - let tintColor = isHighlighted || isSelected ? AppAssets.vibrantTextColor : AppAssets.secondaryAccentColor - disclosureButton?.tintColor = tintColor - faviconImageView.tintColor = tintColor + updateVibrancy(animated: animated) } override func willTransition(to state: UITableViewCell.StateMask) { @@ -201,5 +195,14 @@ private extension MasterFeedTableViewCell { disclosureButton?.isHidden = !isDisclosureAvailable separatorInset = layout.separatorInsets } + + func updateVibrancy(animated: Bool) { + let tintColor = isHighlighted || isSelected ? AppAssets.vibrantTextColor : AppAssets.secondaryAccentColor + let duration = animated ? 0.5 : 0.0 + UIView.animate(withDuration: duration) { + self.disclosureButton?.tintColor = tintColor + self.faviconImageView.tintColor = tintColor + } + } } diff --git a/iOS/Settings/SettingsAccountTableViewCell.swift b/iOS/Settings/SettingsAccountTableViewCell.swift index cc45c59b0..94b3478ac 100644 --- a/iOS/Settings/SettingsAccountTableViewCell.swift +++ b/iOS/Settings/SettingsAccountTableViewCell.swift @@ -15,16 +15,25 @@ class SettingsAccountTableViewCell: VibrantTableViewCell { override func setHighlighted(_ highlighted: Bool, animated: Bool) { super.setHighlighted(highlighted, animated: animated) - let tintColor = isHighlighted || isSelected ? AppAssets.vibrantTextColor : UIColor.label - accountImage?.tintColor = tintColor - accountNameLabel?.highlightedTextColor = tintColor + 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) { let tintColor = isHighlighted || isSelected ? AppAssets.vibrantTextColor : UIColor.label - accountImage?.tintColor = tintColor - accountNameLabel?.highlightedTextColor = tintColor + let duration = animated ? 0.5 : 0.0 + UIView.animate(withDuration: duration) { + self.accountImage?.tintColor = tintColor + } } } diff --git a/iOS/Settings/SettingsViewController.swift b/iOS/Settings/SettingsViewController.swift index 56fe7f11f..be8f7683c 100644 --- a/iOS/Settings/SettingsViewController.swift +++ b/iOS/Settings/SettingsViewController.swift @@ -103,6 +103,7 @@ class SettingsViewController: UITableViewController { cell.textLabel?.text = NSLocalizedString("Add Account", comment: "Accounts") } else { let acctCell = tableView.dequeueReusableCell(withIdentifier: "SettingsAccountTableViewCell", for: indexPath) as! SettingsAccountTableViewCell + acctCell.applyThemeProperties() let account = sortedAccounts[indexPath.row] acctCell.accountImage?.image = AppAssets.image(for: account.type) acctCell.accountNameLabel?.text = account.nameForDisplay