From 7756f6f1218ea04342dc70eb72256a2aa1041157 Mon Sep 17 00:00:00 2001 From: Soner Yuksel Date: Mon, 27 Nov 2023 17:09:28 -0500 Subject: [PATCH] Cleanup and proper include for portrait switch --- .../Browser/BrowserViewController.swift | 14 +++++----- .../BrowserViewController+Menu.swift | 4 --- ...rowserViewController+ToolbarDelegate.swift | 2 +- .../BrowserViewController+Wallet.swift | 3 --- .../Tabs/TabTray/TabTrayController.swift | 7 +++-- .../Menu/MenuViewController.swift | 4 ++- .../SettingsNavigationController.swift | 20 ++++---------- .../Settings/SettingsViewController.swift | 5 +--- .../WalletHostingViewController.swift | 27 +++++++------------ .../WalletPanelHostingController.swift | 4 --- Sources/Shared/DeviceOrientation.swift | 2 -- 11 files changed, 28 insertions(+), 64 deletions(-) diff --git a/Sources/Brave/Frontend/Browser/BrowserViewController.swift b/Sources/Brave/Frontend/Browser/BrowserViewController.swift index fa7461b3ece..e922adac645 100644 --- a/Sources/Brave/Frontend/Browser/BrowserViewController.swift +++ b/Sources/Brave/Frontend/Browser/BrowserViewController.swift @@ -1497,16 +1497,15 @@ public class BrowserViewController: UIViewController { } guard let vc = BraveVPN.vpnState.enableVPNDestinationVC else { return } - let nav = SettingsNavigationController(rootViewController: vc) - nav.navigationBar.topItem?.leftBarButtonItem = - .init(barButtonSystemItem: .cancel, target: nav, action: #selector(nav.done)) + let navigationController = SettingsNavigationController(rootViewController: vc) + navigationController.navigationBar.topItem?.leftBarButtonItem = + .init(barButtonSystemItem: .cancel, target: navigationController, action: #selector(navigationController.done)) let idiom = UIDevice.current.userInterfaceIdiom -// DeviceOrientation.shared.allowOnlyPortrait = UIDevice.current.userInterfaceIdiom != .pad DeviceOrientation.shared.changeOrientationToPortraitOnPhone() - - nav.modalPresentationStyle = idiom == .phone ? .pageSheet : .formSheet - present(nav, animated: true) + + navigationController.modalPresentationStyle = idiom == .phone ? .pageSheet : .formSheet + present(navigationController, animated: true) } func updateInContentHomePanel(_ url: URL?) { @@ -2086,7 +2085,6 @@ public class BrowserViewController: UIViewController { UIBarButtonItem(barButtonSystemItem: .done, target: settingsNavigationController, action: #selector(settingsNavigationController.done)) // All menu views should be opened in portrait on iPhones. -// DeviceOrientation.shared.allowOnlyPortrait = UIDevice.current.userInterfaceIdiom != .pad DeviceOrientation.shared.changeOrientationToPortraitOnPhone() present(settingsNavigationController, animated: true) diff --git a/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+Menu.swift b/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+Menu.swift index f549996dbe3..73fc4630d9f 100644 --- a/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+Menu.swift +++ b/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+Menu.swift @@ -202,10 +202,6 @@ extension BrowserViewController { walletStore.origin = nil let vc = WalletHostingViewController(walletStore: walletStore, webImageDownloader: braveCore.webImageDownloader) vc.delegate = self - -// DeviceOrientation.shared.allowOnlyPortrait = UIDevice.current.userInterfaceIdiom != .pad - DeviceOrientation.shared.changeOrientationToPortraitOnPhone() - self.dismiss(animated: true) { self.present(vc, animated: true) } diff --git a/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+ToolbarDelegate.swift b/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+ToolbarDelegate.swift index 54d64bcb8d3..2f8563896b1 100644 --- a/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+ToolbarDelegate.swift +++ b/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+ToolbarDelegate.swift @@ -1011,7 +1011,7 @@ extension BrowserViewController: UIContextMenuInteractionDelegate { } } -// MARK: - UINavigationControllerDelegate +// MARK: UINavigationControllerDelegate extension BrowserViewController: UINavigationControllerDelegate { public func navigationControllerSupportedInterfaceOrientations(_ navigationController: UINavigationController) -> UIInterfaceOrientationMask { diff --git a/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+Wallet.swift b/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+Wallet.swift index 2f2e5cadc90..ce8704c7337 100644 --- a/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+Wallet.swift +++ b/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+Wallet.swift @@ -152,9 +152,6 @@ extension BrowserViewController: BraveWalletDelegate { ) walletHostingController.delegate = self -// DeviceOrientation.shared.allowOnlyPortrait = UIDevice.current.userInterfaceIdiom != .pad - DeviceOrientation.shared.changeOrientationToPortraitOnPhone() - switch presentWalletWithContext { case .default, .settings: // Dismiss Wallet Panel first, then present Wallet diff --git a/Sources/Brave/Frontend/Browser/Tabs/TabTray/TabTrayController.swift b/Sources/Brave/Frontend/Browser/Tabs/TabTray/TabTrayController.swift index a4220ef609b..cf1cb0edbec 100644 --- a/Sources/Brave/Frontend/Browser/Tabs/TabTray/TabTrayController.swift +++ b/Sources/Brave/Frontend/Browser/Tabs/TabTray/TabTrayController.swift @@ -752,9 +752,9 @@ class TabTrayController: AuthenticationController { syncProfileService: braveCore.syncProfileService, tabManager: tabManager, windowProtection: windowProtection) - + syncSettingsScreen.syncStatusDelegate = self - + openInsideSettingsNavigation(with: syncSettingsScreen) default: return @@ -772,7 +772,6 @@ class TabTrayController: AuthenticationController { settingsNavigationController.navigationBar.topItem?.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .done, target: settingsNavigationController, action: #selector(settingsNavigationController.done)) -// DeviceOrientation.shared.allowOnlyPortrait = UIDevice.current.userInterfaceIdiom != .pad DeviceOrientation.shared.changeOrientationToPortraitOnPhone() present(settingsNavigationController, animated: true) @@ -794,7 +793,7 @@ class TabTrayController: AuthenticationController { } } -// MARK: - InterfaceOrientation +// MARK: InterfaceOrientation extension TabTrayController { diff --git a/Sources/Brave/Frontend/Browser/Toolbars/BottomToolbar/Menu/MenuViewController.swift b/Sources/Brave/Frontend/Browser/Toolbars/BottomToolbar/Menu/MenuViewController.swift index dba3fce56ea..e88eb7e41ac 100644 --- a/Sources/Brave/Frontend/Browser/Toolbars/BottomToolbar/Menu/MenuViewController.swift +++ b/Sources/Brave/Frontend/Browser/Toolbars/BottomToolbar/Menu/MenuViewController.swift @@ -214,7 +214,7 @@ class MenuViewController: UINavigationController, UIPopoverPresentationControlle } } -// MARK: - PanModalPresentable +// MARK: PanModalPresentable extension MenuViewController: PanModalPresentable { var panScrollable: UIScrollView? { @@ -339,6 +339,8 @@ private class MenuHostingController: UIHostingController { public override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) view.window?.addGestureRecognizer(gesture) + + DeviceOrientation.shared.changeOrientationToPortraitOnPhone() + if #available(iOS 16.0, *) { + self.setNeedsUpdateOfSupportedInterfaceOrientations() + } } public override func viewDidLoad() { @@ -128,29 +133,15 @@ public class WalletHostingViewController: UIHostingController { walletStore?.isPresentingFullWallet = true } - public override func viewWillAppear(_ animated: Bool) { - super.viewWillAppear(animated) - - if #available(iOS 16.0, *) { - self.setNeedsUpdateOfSupportedInterfaceOrientations() - } - } - - public override func viewWillDisappear(_ animated: Bool) { - super.viewWillDisappear(animated) - -// DeviceOrientation.shared.allowOnlyPortrait = false - - if #available(iOS 16.0, *) { - self.setNeedsUpdateOfSupportedInterfaceOrientations() - } - } - // MARK: - public override var supportedInterfaceOrientations: UIInterfaceOrientationMask { [.portrait, .portraitUpsideDown] } + + public override var shouldAutorotate: Bool { + true + } } class WalletInteractionGestureRecognizer: UIGestureRecognizer { diff --git a/Sources/BraveWallet/WalletPanelHostingController.swift b/Sources/BraveWallet/WalletPanelHostingController.swift index cc20a12804f..5610672d1e0 100644 --- a/Sources/BraveWallet/WalletPanelHostingController.swift +++ b/Sources/BraveWallet/WalletPanelHostingController.swift @@ -54,10 +54,6 @@ public class WalletPanelHostingController: UIHostingController