From b83c7f7237f55820b63030a656391ac8dca49270 Mon Sep 17 00:00:00 2001 From: Kyle Hickinson Date: Tue, 21 Nov 2023 06:23:34 -0500 Subject: [PATCH] Fix #8451: Defer toolbar state updates on `viewWillAppear` by 1 cycle (#8452) For some reason without this there's a chance iOS lays out the toolbars without any safe area insets --- .../Frontend/Browser/BrowserViewController.swift | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Sources/Brave/Frontend/Browser/BrowserViewController.swift b/Sources/Brave/Frontend/Browser/BrowserViewController.swift index 0c4e0c93b58..1c1caaa8ea2 100644 --- a/Sources/Brave/Frontend/Browser/BrowserViewController.swift +++ b/Sources/Brave/Frontend/Browser/BrowserViewController.swift @@ -1117,10 +1117,14 @@ public class BrowserViewController: UIViewController { override public func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) if #available(iOS 17, *) { - // On iOS 17 rotating the device with a full screen modal presented (e.g. Playlist, Tab Tray) - // to landscape then back to portrait does not trigger `traitCollectionDidChange`/`willTransition`/etc - // calls and so the toolbar remains in the wrong state. - updateToolbarStateForTraitCollection(traitCollection) + // 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. + DispatchQueue.main.async { + // On iOS 17 rotating the device with a full screen modal presented (e.g. Playlist, Tab Tray) + // to landscape then back to portrait does not trigger `traitCollectionDidChange`/`willTransition`/etc + // calls and so the toolbar remains in the wrong state. + self.updateToolbarStateForTraitCollection(self.traitCollection) + } } updateToolbarUsingTabManager(tabManager)