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

Fix #8475: Always update some toolbar state, move workaround to new API #8476

Merged
merged 1 commit into from
Nov 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions Sources/Brave/Frontend/Browser/BrowserViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -625,12 +625,13 @@ public class BrowserViewController: UIViewController {

fileprivate func updateToolbarStateForTraitCollection(_ newCollection: UITraitCollection, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator? = nil) {
let showToolbar = shouldShowFooterForTraitCollection(newCollection)
bottomTouchArea.isEnabled = showToolbar
topToolbar.setShowToolbar(!showToolbar)

if (showToolbar && toolbar == nil) || (!showToolbar && toolbar != nil) {
topToolbar.setShowToolbar(!showToolbar)
toolbar?.removeFromSuperview()
toolbar?.tabToolbarDelegate = nil
toolbar = nil
bottomTouchArea.isEnabled = showToolbar

if showToolbar {
toolbar = BottomToolbarView(privateBrowsingManager: privateBrowsingManager)
Expand All @@ -639,11 +640,12 @@ public class BrowserViewController: UIViewController {
toolbar?.tabToolbarDelegate = self
toolbar?.menuButton.setBadges(Array(topToolbar.menuButton.badges.keys))
}
updateToolbarUsingTabManager(tabManager)
updateUsingBottomBar(using: newCollection)

view.setNeedsUpdateConstraints()
}

updateToolbarUsingTabManager(tabManager)
updateUsingBottomBar(using: newCollection)

if let tab = tabManager.selectedTab,
let webView = tab.webView {
updateURLBar()
Expand Down Expand Up @@ -1116,6 +1118,17 @@ public class BrowserViewController: UIViewController {

override public func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
updateToolbarUsingTabManager(tabManager)

if let tabId = tabManager.selectedTab?.rewardsId, rewards.rewardsAPI?.selectedTabId == 0 {
rewards.rewardsAPI?.selectedTabId = tabId
}
}

#if swift(>=5.9)
public override func viewIsAppearing(_ animated: Bool) {
super.viewIsAppearing(animated)

if #available(iOS 17, *) {
// Have to defer this to the next cycle to avoid an iOS bug which lays out the toolbars without any
// bottom safe area, resulting in a layout bug.
Expand All @@ -1126,12 +1139,8 @@ public class BrowserViewController: UIViewController {
self.updateToolbarStateForTraitCollection(self.traitCollection)
}
}
updateToolbarUsingTabManager(tabManager)

if let tabId = tabManager.selectedTab?.rewardsId, rewards.rewardsAPI?.selectedTabId == 0 {
rewards.rewardsAPI?.selectedTabId = tabId
}
}
#endif

private func checkCrashRestorationOrSetupTabs() {
if crashedLastSession {
Expand Down