Skip to content

Commit

Permalink
Fix brave/brave-ios#7717: Match color on reader mode bar to private/n…
Browse files Browse the repository at this point in the history
…ight mode (brave/brave-ios#7936)
  • Loading branch information
kylehickinson authored Aug 23, 2023
1 parent 09da812 commit 634a4b8
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ extension BrowserViewController {

func showReaderModeBar(animated: Bool) {
if self.readerModeBar == nil {
let readerModeBar = ReaderModeBarView(frame: CGRect.zero)
let readerModeBar = ReaderModeBarView(privateBrowsingManager: tabManager.privateBrowsingManager)
readerModeBar.delegate = self
view.insertSubview(readerModeBar, aboveSubview: webViewContainer)
self.readerModeBar = readerModeBar
Expand Down
44 changes: 39 additions & 5 deletions Sources/Brave/Frontend/Browser/ReaderModeBarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import UIKit
import SnapKit
import Shared
import Preferences
import Combine

protocol ReaderModeBarViewDelegate: AnyObject {
func readerModeSettingsTapped(_ view: UIView)
Expand All @@ -25,12 +27,26 @@ class ReaderModeBarView: UIView {
$0.tintColor = .braveLabel
$0.accessibilityIdentifier = "ReaderModeBarView.settingsButton"
}

private var privateBrowsingManager: PrivateBrowsingManager

override init(frame: CGRect) {
super.init(frame: frame)

backgroundColor = .urlBarBackground

private var cancellables: Set<AnyCancellable> = []
private func updateColors(_ isPrivateBrowsing: Bool) {
if isPrivateBrowsing {
overrideUserInterfaceStyle = .dark
backgroundColor = .privateModeBackground
} else {
overrideUserInterfaceStyle = DefaultTheme(
rawValue: Preferences.General.themeNormalMode.value)?.userInterfaceStyleOverride ?? .unspecified
backgroundColor = Preferences.General.nightModeEnabled.value ? .nightModeBackground : .urlBarBackground
}
}

init(privateBrowsingManager: PrivateBrowsingManager) {
self.privateBrowsingManager = privateBrowsingManager

super.init(frame: .zero)

addSubview(readerModeButton)
readerModeButton.addTarget(self, action: #selector(tappedSettingsButton), for: .touchUpInside)
readerModeButton.snp.makeConstraints {
Expand All @@ -50,6 +66,24 @@ class ReaderModeBarView: UIView {
$0.trailing.equalToSuperview().inset(16)
$0.centerY.equalToSuperview()
}

privateBrowsingManager
.$isPrivateBrowsing
.removeDuplicates()
.sink(receiveValue: { [weak self] isPrivateBrowsing in
self?.updateColors(isPrivateBrowsing)
})
.store(in: &cancellables)

Preferences.General.nightModeEnabled.objectWillChange
.receive(on: RunLoop.main)
.sink { [weak self] _ in
guard let self = self else { return }
self.updateColors(self.privateBrowsingManager.isPrivateBrowsing)
}
.store(in: &cancellables)

updateColors(privateBrowsingManager.isPrivateBrowsing)
}

required init?(coder aDecoder: NSCoder) {
Expand Down

0 comments on commit 634a4b8

Please sign in to comment.