From 0653d695d94868bd7ea99aef1abfde0d231d9d8f Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Mon, 16 Jan 2023 11:24:42 -0500 Subject: [PATCH] Fix various things not adjusting to accent color preference Closes #325 --- Tusker/Activities/OpenInSafariActivity.swift | 4 ++- .../Explore/TrendingLinksViewController.swift | 4 ++- .../FastSwitchingAccountView.swift | 34 +++++++++++-------- .../Screens/Search/SearchViewController.swift | 4 ++- Tusker/TuskerNavigationDelegate.swift | 4 ++- Tusker/Views/ContentTextView.swift | 4 ++- Tusker/Views/Poll/PollOptionView.swift | 2 +- .../Status/BaseStatusTableViewCell.swift | 4 +-- Tusker/Views/Status/StatusCardView.swift | 4 ++- 9 files changed, 41 insertions(+), 23 deletions(-) diff --git a/Tusker/Activities/OpenInSafariActivity.swift b/Tusker/Activities/OpenInSafariActivity.swift index 41f4b62e..0a3b772f 100644 --- a/Tusker/Activities/OpenInSafariActivity.swift +++ b/Tusker/Activities/OpenInSafariActivity.swift @@ -39,7 +39,9 @@ class OpenInSafariActivity: UIActivity { static func completionHandler(navigator: TuskerNavigationDelegate, url: URL) -> UIActivityViewController.CompletionWithItemsHandler { return { (activityType, _, _, _) in if activityType == .openInSafari { - navigator.show(SFSafariViewController(url: url)) + let vc = SFSafariViewController(url: url) + vc.preferredControlTintColor = Preferences.shared.accentColor.color + navigator.show(vc) } } } diff --git a/Tusker/Screens/Explore/TrendingLinksViewController.swift b/Tusker/Screens/Explore/TrendingLinksViewController.swift index b882baa6..4f71bf67 100644 --- a/Tusker/Screens/Explore/TrendingLinksViewController.swift +++ b/Tusker/Screens/Explore/TrendingLinksViewController.swift @@ -75,7 +75,9 @@ class TrendingLinksViewController: EnhancedTableViewController { return nil } return UIContextMenuConfiguration(identifier: nil) { - return SFSafariViewController(url: url) + let vc = SFSafariViewController(url: url) + vc.preferredControlTintColor = Preferences.shared.accentColor.color + return vc } actionProvider: { _ in return UIMenu(children: self.actionsForTrendingLink(card: item.card)) } diff --git a/Tusker/Screens/Fast Account Switcher/FastSwitchingAccountView.swift b/Tusker/Screens/Fast Account Switcher/FastSwitchingAccountView.swift index a939a0e4..3f1733c2 100644 --- a/Tusker/Screens/Fast Account Switcher/FastSwitchingAccountView.swift +++ b/Tusker/Screens/Fast Account Switcher/FastSwitchingAccountView.swift @@ -10,19 +10,25 @@ import UIKit class FastSwitchingAccountView: UIView { - private static let selectedColor = UIColor { (traits) in - if traits.userInterfaceStyle == .dark { - return UIColor(hue: 211 / 360, saturation: 85 / 100, brightness: 100 / 100, alpha: 1) - } else { - return UIColor(hue: 211 / 360, saturation: 70 / 100, brightness: 100 / 100, alpha: 1) - } + private lazy var selectedColor = UIColor { [unowned self] (traits) in + var hue: CGFloat = 0 + var saturation: CGFloat = 0 + var brightness: CGFloat = 0 + var alpha: CGFloat = 0 + self.tintColor.resolvedColor(with: traits).getHue(&hue, saturation: &saturation, brightness: &brightness, alpha: &alpha) + brightness = min(1, brightness + 0.4) + saturation = max(0, saturation - 0.3) + return UIColor(hue: hue, saturation: saturation, brightness: brightness, alpha: alpha) } - private static let currentColor = UIColor { (traits) in - if traits.userInterfaceStyle == .dark { - return UIColor(hue: 211 / 360, saturation: 85 / 100, brightness: 85 / 100, alpha: 1) - } else { - return UIColor(hue: 211 / 360, saturation: 50 / 100, brightness: 100 / 100, alpha: 1) - } + private lazy var currentColor = UIColor { [unowned self] (traits) in + var hue: CGFloat = 0 + var saturation: CGFloat = 0 + var brightness: CGFloat = 0 + var alpha: CGFloat = 0 + self.tintColor.resolvedColor(with: traits).getHue(&hue, saturation: &saturation, brightness: &brightness, alpha: &alpha) + brightness = min(1, brightness + 0.3) + saturation = max(0, saturation - 0.2) + return UIColor(hue: hue, saturation: saturation, brightness: brightness, alpha: alpha) } var isSelected = false { didSet { @@ -139,9 +145,9 @@ class FastSwitchingAccountView: UIView { private func updateLabelColors() { let color: UIColor if isSelected { - color = FastSwitchingAccountView.selectedColor + color = selectedColor } else if isCurrent { - color = FastSwitchingAccountView.currentColor + color = currentColor } else { color = .white } diff --git a/Tusker/Screens/Search/SearchViewController.swift b/Tusker/Screens/Search/SearchViewController.swift index e862ef80..cc755f93 100644 --- a/Tusker/Screens/Search/SearchViewController.swift +++ b/Tusker/Screens/Search/SearchViewController.swift @@ -278,7 +278,9 @@ extension SearchViewController: UICollectionViewDelegate { return nil } return UIContextMenuConfiguration { - SFSafariViewController(url: url) + let vc = SFSafariViewController(url: url) + vc.preferredControlTintColor = Preferences.shared.accentColor.color + return vc } actionProvider: { _ in UIMenu(children: self.actionsForTrendingLink(card: card)) } diff --git a/Tusker/TuskerNavigationDelegate.swift b/Tusker/TuskerNavigationDelegate.swift index 5291377a..f9079523 100644 --- a/Tusker/TuskerNavigationDelegate.swift +++ b/Tusker/TuskerNavigationDelegate.swift @@ -50,7 +50,9 @@ extension TuskerNavigationDelegate { url.scheme == "https" || url.scheme == "http" { let config = SFSafariViewController.Configuration() config.entersReaderIfAvailable = Preferences.shared.inAppSafariAutomaticReaderMode - present(SFSafariViewController(url: url, configuration: config), animated: true) + let vc = SFSafariViewController(url: url, configuration: config) + vc.preferredControlTintColor = Preferences.shared.accentColor.color + present(vc, animated: true) } else if UIApplication.shared.canOpenURL(url) { UIApplication.shared.open(url, options: [:]) } else { diff --git a/Tusker/Views/ContentTextView.swift b/Tusker/Views/ContentTextView.swift index 709c6c8d..a67f9b58 100644 --- a/Tusker/Views/ContentTextView.swift +++ b/Tusker/Views/ContentTextView.swift @@ -185,7 +185,9 @@ class ContentTextView: LinkTextView, BaseEmojiLabel { } else if let tag = getHashtag(for: url, text: text) { return HashtagTimelineViewController(for: tag, mastodonController: mastodonController!) } else if url.scheme == "https" || url.scheme == "http" { - return SFSafariViewController(url: url) + let vc = SFSafariViewController(url: url) + vc.preferredControlTintColor = Preferences.shared.accentColor.color + return vc } else { return nil } diff --git a/Tusker/Views/Poll/PollOptionView.swift b/Tusker/Views/Poll/PollOptionView.swift index 426ae2a2..57ea343b 100644 --- a/Tusker/Views/Poll/PollOptionView.swift +++ b/Tusker/Views/Poll/PollOptionView.swift @@ -56,7 +56,7 @@ class PollOptionView: UIView { let fillView = UIView() fillView.translatesAutoresizingMaskIntoConstraints = false - fillView.backgroundColor = tintColor.withAlphaComponent(0.6) + fillView.backgroundColor = .tintColor.withAlphaComponent(0.6) fillView.layer.zPosition = -1 fillView.layer.cornerRadius = layer.cornerRadius addSubview(fillView) diff --git a/Tusker/Views/Status/BaseStatusTableViewCell.swift b/Tusker/Views/Status/BaseStatusTableViewCell.swift index 0be91061..bab4031c 100644 --- a/Tusker/Views/Status/BaseStatusTableViewCell.swift +++ b/Tusker/Views/Status/BaseStatusTableViewCell.swift @@ -294,7 +294,7 @@ class BaseStatusTableViewCell: UITableViewCell { } else { let view = UIView() view.translatesAutoresizingMaskIntoConstraints = false - view.backgroundColor = tintColor.withAlphaComponent(0.5) + view.backgroundColor = .tintColor.withAlphaComponent(0.5) view.layer.cornerRadius = 2.5 view.layer.maskedCorners = [.layerMinXMaxYCorner, .layerMaxXMaxYCorner] prevThreadLinkView = view @@ -316,7 +316,7 @@ class BaseStatusTableViewCell: UITableViewCell { } else { let view = UIView() view.translatesAutoresizingMaskIntoConstraints = false - view.backgroundColor = tintColor.withAlphaComponent(0.5) + view.backgroundColor = .tintColor.withAlphaComponent(0.5) view.layer.cornerRadius = 2.5 view.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner] nextThreadLinkView = view diff --git a/Tusker/Views/Status/StatusCardView.swift b/Tusker/Views/Status/StatusCardView.swift index 96ee95f1..19c44e8e 100644 --- a/Tusker/Views/Status/StatusCardView.swift +++ b/Tusker/Views/Status/StatusCardView.swift @@ -229,7 +229,9 @@ extension StatusCardView: UIContextMenuInteractionDelegate { guard let card = card else { return nil } return UIContextMenuConfiguration(identifier: nil) { - return SFSafariViewController(url: URL(card.url)!) + let vc = SFSafariViewController(url: URL(card.url)!) + vc.preferredControlTintColor = Preferences.shared.accentColor.color + return vc } actionProvider: { (_) in let actions = self.actionProvider?.actionsForURL(URL(card.url)!, source: .view(self)) ?? [] return UIMenu(title: "", image: nil, identifier: nil, options: [], children: actions)