Skip to content

Commit

Permalink
Add FXIOS-10022 ⁃ Add themeing to the menu (#22059)
Browse files Browse the repository at this point in the history
FXIOS-10022 #21993 ⁃ Add themeing to the menu
  • Loading branch information
dicarobinho authored Sep 18, 2024
1 parent f524add commit db79da6
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 19 deletions.
10 changes: 7 additions & 3 deletions BrowserKit/Sources/MenuKit/MenuAccountHeaderView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

import Foundation
import UIKit
import Common

final class MenuAccountHeaderView: UIView {
final class MenuAccountHeaderView: UIView, ThemeApplicable {
// MARK: - UI Elements

// MARK: - Properties
Expand All @@ -22,9 +23,12 @@ final class MenuAccountHeaderView: UIView {

// MARK: - UI Setup
private func setupView() {
backgroundColor = .systemPink

NSLayoutConstraint.activate([
])
}

// MARK: - Theme Applicable
func applyTheme(theme: Theme) {
backgroundColor = theme.colors.layer3
}
}
2 changes: 1 addition & 1 deletion BrowserKit/Sources/MenuKit/MenuCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public class MenuCell: UITableViewCell, ReusableCell, ThemeApplicable {
action()
}

// TODO: FXIOS-10022 ⁃ Add themeing to the menu (applying this method remained)
// MARK: - Theme Applicable
public func applyTheme(theme: Theme) {
guard let model else { return }
backgroundColor = theme.colors.layer2
Expand Down
10 changes: 8 additions & 2 deletions BrowserKit/Sources/MenuKit/MenuDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Common
import UIKit

public final class MenuDetailView: UIView,
MenuTableViewDataDelegate {
MenuTableViewDataDelegate, ThemeApplicable {
private struct UX {
static let headerHeight: CGFloat = 70
}
Expand All @@ -27,7 +27,6 @@ public final class MenuDetailView: UIView,

// MARK: - UI Setup
private func setupView() {
backgroundColor = .clear
addSubview(detailHeaderView)
addSubview(tableView)

Expand All @@ -52,4 +51,11 @@ public final class MenuDetailView: UIView,
public func setupHeaderNavigation(from delegate: MainMenuDetailNavigationHandler) {
detailHeaderView.navigationDelegate = delegate
}

// MARK: - Theme Applicable
public func applyTheme(theme: Theme) {
backgroundColor = .clear
tableView.applyTheme(theme: theme)
detailHeaderView.applyTheme(theme: theme)
}
}
10 changes: 8 additions & 2 deletions BrowserKit/Sources/MenuKit/MenuMainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Common
import UIKit

public final class MenuMainView: UIView,
MenuTableViewDataDelegate {
MenuTableViewDataDelegate, ThemeApplicable {
// MARK: - UI Elements
private var tableView: MenuTableView = .build()
private var accountHeaderView: MenuAccountHeaderView = .build()
Expand All @@ -25,7 +25,6 @@ public final class MenuMainView: UIView,

// MARK: - UI Setup
private func setupView() {
backgroundColor = .clear
self.addSubview(accountHeaderView)
self.addSubview(tableView)

Expand All @@ -46,4 +45,11 @@ public final class MenuMainView: UIView,
public func reloadTableView(with data: [MenuSection]) {
tableView.reloadTableView(with: data)
}

// MARK: - ThemeApplicable
public func applyTheme(theme: Theme) {
backgroundColor = .clear
tableView.applyTheme(theme: theme)
accountHeaderView.applyTheme(theme: theme)
}
}
10 changes: 7 additions & 3 deletions BrowserKit/Sources/MenuKit/MenuSubmenuHeaderView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ public protocol MainMenuDetailNavigationHandler: AnyObject {
func backToMainView()
}

final class MenuSubmenuHeaderView: UIView {
final class MenuSubmenuHeaderView: UIView, ThemeApplicable {
// MARK: - UI Elements
private lazy var backButton: UIButton = .build { button in
button.backgroundColor = .systemRed
button.addTarget(self, action: #selector(self.backButtonTapped), for: .touchUpInside)
}

Expand All @@ -32,7 +31,6 @@ final class MenuSubmenuHeaderView: UIView {

// MARK: - UI Setup
private func setupView() {
backgroundColor = .systemCyan
addSubviews(backButton)

NSLayoutConstraint.activate([
Expand All @@ -47,4 +45,10 @@ final class MenuSubmenuHeaderView: UIView {
private func backButtonTapped() {
navigationDelegate?.backToMainView()
}

// MARK: Theme Applicable
func applyTheme(theme: Theme) {
backgroundColor = theme.colors.layer3
backButton.tintColor = theme.colors.textAccent
}
}
15 changes: 11 additions & 4 deletions BrowserKit/Sources/MenuKit/MenuTableView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@

import Foundation
import UIKit
import Common

public protocol MenuTableViewDataDelegate: AnyObject {
func reloadTableView(with data: [MenuSection])
}

class MenuTableView: UIView,
UITableViewDelegate,
UITableViewDataSource {
UITableViewDataSource, ThemeApplicable {
private var tableView: UITableView
private var menuData: [MenuSection]
private var theme: Theme?

override init(frame: CGRect) {
tableView = UITableView(frame: .zero, style: .insetGrouped)
Expand All @@ -32,8 +34,6 @@ class MenuTableView: UIView,
}

private func setupUI() {
backgroundColor = .clear
tableView.backgroundColor = .clear
tableView.translatesAutoresizingMaskIntoConstraints = false
self.addSubview(tableView)

Expand Down Expand Up @@ -76,7 +76,7 @@ class MenuTableView: UIView,
) as! MenuCell

cell.configureCellWith(model: menuData[indexPath.section].options[indexPath.row])

if let theme { cell.applyTheme(theme: theme) }
return cell
}

Expand All @@ -96,4 +96,11 @@ class MenuTableView: UIView,
menuData = data
tableView.reloadData()
}

// MARK: - Theme Applicable
func applyTheme(theme: Theme) {
self.theme = theme
backgroundColor = .clear
tableView.backgroundColor = .clear
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,19 @@ class MainMenuDetailViewController: UIViewController,
submenuContent.setupHeaderNavigation(from: self)
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
applyTheme()
}

// MARK: - UX related
func applyTheme() {
let theme = themeManager.getCurrentTheme(for: windowUUID)
view.backgroundColor = theme.colors.layer3
submenuContent.applyTheme(theme: theme)
}

private func setupView() {
view.backgroundColor = .systemMint
view.addSubview(submenuContent)

NSLayoutConstraint.activate([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ class MainMenuViewController: UIViewController,

// MARK: - UX related
func applyTheme() {
// let theme = themeManager.getCurrentTheme(for: windowUUID)
// view.backgroundColor = theme.colors.layer1
view.backgroundColor = .systemPurple
let theme = themeManager.getCurrentTheme(for: windowUUID)
view.backgroundColor = theme.colors.layer3
menuContent.applyTheme(theme: theme)
}

// MARK: - Notifications
Expand Down

0 comments on commit db79da6

Please sign in to comment.