diff --git a/ConsentViewController/Classes/Views/tvOS/NativePrivacyManager/Common/SPAppleTVButton.swift b/ConsentViewController/Classes/Views/tvOS/NativePrivacyManager/Common/SPAppleTVButton.swift index 944702e45..17ae85472 100644 --- a/ConsentViewController/Classes/Views/tvOS/NativePrivacyManager/Common/SPAppleTVButton.swift +++ b/ConsentViewController/Classes/Views/tvOS/NativePrivacyManager/Common/SPAppleTVButton.swift @@ -7,34 +7,30 @@ import UIKit -extension UIView { - var allSubviews: [UIView] { - subviews.reduce(into: [self]) { array, subview in - array += subview.allSubviews - } +/// A button that enforces clear background colors. +/// To style the background, use ``UIButton.setBackgroundImage(_ image:for:)``. +/// This suppresses unwanted background and border effects automatically added when using +/// the system button type while keeping the default appearance, drop shadow, and scaling effect. +final class SPAppleTVButton: UIButton { + override func layoutSubviews() { + super.layoutSubviews() + clearBackgroundColors() } } -class SPAppleTVButton: UIButton { - var viewBeforeUITitleView: UIView? { allSubviews.dropFirst(allSubviews.count - 2).first } +extension UIView { + + /// Sets the background colors of all the view's subviews to ``UIColor.clear``. + /// - Parameter ignoredColor: Exception that is not overridden. + func clearBackgroundColors(ignoring ignoredColor: UIColor? = nil) { + for subview in subviews { + subview.clearBackgroundColors(ignoring: ignoredColor) - var onFocusBackgroundColor: UIColor? - var onUnfocusBackgroundColor: UIColor? { - didSet { - viewBeforeUITitleView?.backgroundColor = onUnfocusBackgroundColor - } - } + if let ignoredColor, subview.backgroundColor == ignoredColor { + continue + } - override func didUpdateFocus(in context: UIFocusUpdateContext, with coordinator: UIFocusAnimationCoordinator) { - super.didUpdateFocus(in: context, with: coordinator) - if isFocused { - backgroundColor = onFocusBackgroundColor - coordinator.addCoordinatedAnimations({ [weak self] in - self?.viewBeforeUITitleView?.backgroundColor = self?.onFocusBackgroundColor - }) - } else { - backgroundColor = onUnfocusBackgroundColor - viewBeforeUITitleView?.backgroundColor = onUnfocusBackgroundColor + subview.backgroundColor = .clear } } } diff --git a/ConsentViewController/Classes/Views/tvOS/NativePrivacyManager/Common/SPNativeScreenViewController.swift b/ConsentViewController/Classes/Views/tvOS/NativePrivacyManager/Common/SPNativeScreenViewController.swift index d534cfc8c..2b6c5ab8d 100644 --- a/ConsentViewController/Classes/Views/tvOS/NativePrivacyManager/Common/SPNativeScreenViewController.swift +++ b/ConsentViewController/Classes/Views/tvOS/NativePrivacyManager/Common/SPNativeScreenViewController.swift @@ -194,11 +194,13 @@ class FocusGuideDebugView: UIView { button.setTitle(action.settings.text, for: .normal) button.setTitleColor(UIColor(hexString: style.onUnfocusTextColor), for: .normal) button.setTitleColor(UIColor(hexString: style.onFocusTextColor), for: .focused) - button.backgroundColor = UIColor(hexString: style.onUnfocusBackgroundColor) - button.onUnfocusBackgroundColor = button.backgroundColor - button.onFocusBackgroundColor = UIColor(hexString: style.onFocusBackgroundColor) button.titleLabel?.font = UIFont(from: style.font) - button.layer.cornerRadius = 12 + UIColor(hexString: style.onUnfocusBackgroundColor) + .map { getImageWithColor(color: $0) } + .map { button.setBackgroundImage($0, for: .normal) } + UIColor(hexString: style.onFocusBackgroundColor) + .map { getImageWithColor(color: $0) } + .map { button.setBackgroundImage($0, for: .focused) } } else { button.isHidden = true } diff --git a/ConsentViewController/Classes/Views/tvOS/NativePrivacyManager/GDPR/SPGDPRNativePrivacyManagerViewController.swift b/ConsentViewController/Classes/Views/tvOS/NativePrivacyManager/GDPR/SPGDPRNativePrivacyManagerViewController.swift index c247f204c..2552fb921 100644 --- a/ConsentViewController/Classes/Views/tvOS/NativePrivacyManager/GDPR/SPGDPRNativePrivacyManagerViewController.swift +++ b/ConsentViewController/Classes/Views/tvOS/NativePrivacyManager/GDPR/SPGDPRNativePrivacyManagerViewController.swift @@ -58,7 +58,11 @@ protocol SPNativePrivacyManagerHome { setFocusGuidesForButtons() categoryTableView.accessibilityIdentifier = "Categories List" categoryTableView.allowsSelection = false - categoryTableView.register(UITableViewCell.self, forCellReuseIdentifier: cellReuseIdentifier) + if #available(tvOS 14.0, *) { + categoryTableView.register(CategoryCellView.self, forCellReuseIdentifier: cellReuseIdentifier) + } else { + categoryTableView.register(UITableViewCell.self, forCellReuseIdentifier: cellReuseIdentifier) + } categoryTableView.delegate = self categoryTableView.dataSource = self disableMenuButton() @@ -296,6 +300,7 @@ extension SPGDPRNativePrivacyManagerViewController: UITableViewDataSource { let cell = categoryTableView.dequeueReusableCell(withIdentifier: cellReuseIdentifier, for: indexPath) cell.textLabel?.text = categories[indexPath.row].name.trimmingCharacters(in: .whitespacesAndNewlines) cell.textLabel?.setDefaultTextColorForDarkMode() + cell.textLabel?.font = .preferredFont(forTextStyle: .footnote) return cell } } @@ -317,4 +322,32 @@ class FocusableScrollView: UIScrollView { } } +/// A table view cell with a custom background configuration. +/// It suppresses unwanted background and border effects that are automatically added by the system +/// while while keeping the drop shadow and scaling effect when being focused. +@available(tvOS 14.0, *) +class CategoryCellView: UITableViewCell { + + override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { + super.init(style: style, reuseIdentifier: reuseIdentifier) + setupBackground() + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + private func setupBackground() { + var backgroundConfiguration = UIBackgroundConfiguration.listPlainCell() + backgroundConfiguration.backgroundColor = .darkGray + self.backgroundConfiguration = backgroundConfiguration + } + + override func updateConfiguration(using state: UICellConfigurationState) { + super.updateConfiguration(using: state) + textLabel?.textColor = .white + clearBackgroundColors(ignoring: backgroundConfiguration?.backgroundColor) + } +} + // swiftlint:enable function_body_length