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

Commit

Permalink
Fix #8475: Always update some toolbar state, move workaround to new A…
Browse files Browse the repository at this point in the history
…PI (#8476)

Sometimes the `traitCollection` is _still_ incorrect in `viewWillAppear` even with a runloop hop, so switching to the new API the iOS 17 SDK introduced `viewIsAppearing`
  • Loading branch information
kylehickinson authored Nov 24, 2023
1 parent 0cb3e7f commit 9c20c33
Showing 1 changed file with 19 additions and 10 deletions.
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

0 comments on commit 9c20c33

Please sign in to comment.