diff --git a/Client/Frontend/Browser/TabsBar/TabBarCell.swift b/Client/Frontend/Browser/TabsBar/TabBarCell.swift index 5a968f9eb74..8bfdb6d057a 100644 --- a/Client/Frontend/Browser/TabsBar/TabBarCell.swift +++ b/Client/Frontend/Browser/TabsBar/TabBarCell.swift @@ -5,7 +5,7 @@ import UIKit import BraveShared -class TabBarCell: UICollectionViewCell { +class TabBarCell: UICollectionViewCell, Themeable { lazy var titleLabel: UILabel = { let label = UILabel() @@ -25,15 +25,11 @@ class TabBarCell: UICollectionViewCell { private lazy var separatorLine: UIView = { let view = UIView() - let theme = Theme.of(nil) - view.backgroundColor = theme.colors.border.withAlphaComponent(theme.colors.transparencies.borderAlpha) return view }() lazy var separatorLineRight: UIView = { let view = UIView() - let theme = Theme.of(nil) - view.backgroundColor = theme.colors.border.withAlphaComponent(theme.colors.transparencies.borderAlpha) view.isHidden = true return view }() @@ -62,6 +58,25 @@ class TabBarCell: UICollectionViewCell { fatalError("init(coder:) has not been implemented") } + private var selectedBackgroundColor: UIColor? + private var normalBackgroundColor: UIColor? + + func applyTheme(_ theme: Theme) { + separatorLine.backgroundColor = theme.colors.border.withAlphaComponent(theme.colors.transparencies.borderAlpha) + separatorLineRight.backgroundColor = theme.colors.border.withAlphaComponent(theme.colors.transparencies.borderAlpha) + closeButton.tintColor = theme.colors.tints.header + titleLabel.textColor = theme.colors.tints.header + + selectedBackgroundColor = theme.colors.header + normalBackgroundColor = theme.colors.home + + if isSelected { + backgroundColor = selectedBackgroundColor + } else if currentIndex != tabManager?.currentDisplayedIndex { + backgroundColor = normalBackgroundColor + } + } + private func initConstraints() { titleLabel.snp.makeConstraints { make in make.top.bottom.equalTo(self) @@ -92,21 +107,18 @@ class TabBarCell: UICollectionViewCell { override var isSelected: Bool { didSet { - let theme = Theme.of(tab) - closeButton.tintColor = theme.colors.tints.header - if isSelected { titleLabel.font = UIFont.systemFont(ofSize: 12, weight: UIFont.Weight.semibold) closeButton.isHidden = false - titleLabel.textColor = theme.colors.tints.header - backgroundColor = theme.colors.header + titleLabel.alpha = 1.0 + backgroundColor = selectedBackgroundColor } // Prevent swipe and release outside- deselects cell. else if currentIndex != tabManager?.currentDisplayedIndex { titleLabel.font = UIFont.systemFont(ofSize: 12) - titleLabel.textColor = theme.colors.tints.header.withAlphaComponent(0.6) + titleLabel.alpha = 0.6 closeButton.isHidden = true - backgroundColor = theme.colors.home + backgroundColor = normalBackgroundColor } } } diff --git a/Client/Frontend/Browser/TabsBar/TabsBarViewController.swift b/Client/Frontend/Browser/TabsBar/TabsBarViewController.swift index 26feb77e500..8e27933d7ea 100644 --- a/Client/Frontend/Browser/TabsBar/TabsBarViewController.swift +++ b/Client/Frontend/Browser/TabsBar/TabsBarViewController.swift @@ -62,6 +62,8 @@ class TabsBarViewController: UIViewController { fatalError("init(coder:) has not been implemented") } + private var currentTheme: Theme? + override func viewDidLoad() { super.viewDidLoad() @@ -136,14 +138,6 @@ class TabsBarViewController: UIViewController { overflowIndicators() } - override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { - super.traitCollectionDidChange(previousTraitCollection) - - if traitCollection.userInterfaceStyle != previousTraitCollection?.userInterfaceStyle { - applyTheme(Theme.of(nil)) - } - } - @objc func addTabPressed() { tabManager?.addTabAndSelect(isPrivate: PrivateBrowsingManager.shared.isPrivateBrowsing) } @@ -315,7 +309,7 @@ extension TabsBarViewController: UICollectionViewDataSource { cell.titleLabel.text = tab.displayTitle cell.currentIndex = indexPath.row cell.separatorLineRight.isHidden = (indexPath.row != tabList.count() - 1) - + cell.applyTheme(currentTheme ?? Theme.of(tab)) cell.closeTabCallback = { [weak self] tab in guard let strongSelf = self, let tabManager = strongSelf.tabManager, let previousIndex = strongSelf.tabList.index(of: tab) else { return } @@ -372,6 +366,7 @@ extension TabsBarViewController: TabManagerDelegate { extension TabsBarViewController: Themeable { func applyTheme(_ theme: Theme) { styleChildren(theme: theme) + currentTheme = theme view.backgroundColor = theme.colors.header plusButton.tintColor = theme.colors.tints.header