Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
Style tabs bar with private theme
Browse files Browse the repository at this point in the history
  • Loading branch information
kylehickinson committed Apr 6, 2021
1 parent e56a830 commit 6e9395d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 21 deletions.
36 changes: 24 additions & 12 deletions Client/Frontend/Browser/TabsBar/TabBarCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import UIKit
import BraveShared

class TabBarCell: UICollectionViewCell {
class TabBarCell: UICollectionViewCell, Themeable {

lazy var titleLabel: UILabel = {
let label = UILabel()
Expand All @@ -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
}()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
}
}
Expand Down
13 changes: 4 additions & 9 deletions Client/Frontend/Browser/TabsBar/TabsBarViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class TabsBarViewController: UIViewController {
fatalError("init(coder:) has not been implemented")
}

private var currentTheme: Theme?

override func viewDidLoad() {
super.viewDidLoad()

Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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 }

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6e9395d

Please sign in to comment.