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

Commit

Permalink
Cleanup and proper include for portrait switch
Browse files Browse the repository at this point in the history
  • Loading branch information
soner-yuksel committed Nov 27, 2023
1 parent 665bc45 commit 7756f6f
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 64 deletions.
14 changes: 6 additions & 8 deletions Sources/Brave/Frontend/Browser/BrowserViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?) {
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,7 @@ extension BrowserViewController: UIContextMenuInteractionDelegate {
}
}

// MARK: - UINavigationControllerDelegate
// MARK: UINavigationControllerDelegate

extension BrowserViewController: UINavigationControllerDelegate {
public func navigationControllerSupportedInterfaceOrientations(_ navigationController: UINavigationController) -> UIInterfaceOrientationMask {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -752,9 +752,9 @@ class TabTrayController: AuthenticationController {
syncProfileService: braveCore.syncProfileService,
tabManager: tabManager,
windowProtection: windowProtection)

syncSettingsScreen.syncStatusDelegate = self

openInsideSettingsNavigation(with: syncSettingsScreen)
default:
return
Expand All @@ -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)
Expand All @@ -794,7 +793,7 @@ class TabTrayController: AuthenticationController {
}
}

// MARK: - InterfaceOrientation
// MARK: InterfaceOrientation

extension TabTrayController {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ class MenuViewController: UINavigationController, UIPopoverPresentationControlle
}
}

// MARK: - PanModalPresentable
// MARK: PanModalPresentable

extension MenuViewController: PanModalPresentable {
var panScrollable: UIScrollView? {
Expand Down Expand Up @@ -339,6 +339,8 @@ private class MenuHostingController<MenuContent: View>: UIHostingController<Menu
}
}

// MARK: MenuNavigationControllerDelegate

private class MenuNavigationControllerDelegate: NSObject, UINavigationControllerDelegate {
weak var panModal: (UIViewController & PanModalPresentable)?
init(panModal: UIViewController & PanModalPresentable) {
Expand Down
20 changes: 5 additions & 15 deletions Sources/Brave/Frontend/Settings/SettingsNavigationController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,17 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import UIKit
import Shared

class SettingsNavigationController: UINavigationController {
var popoverDelegate: PresentingModalViewControllerDelegate?

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)

if #available(iOS 16.0, *) {
self.setNeedsUpdateOfSupportedInterfaceOrientations()
}
}

override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)

// DeviceOrientation.shared.allowOnlyPortrait = false
if #available(iOS 16.0, *) {
self.setNeedsUpdateOfSupportedInterfaceOrientations()
}
}

@objc func done() {
if let delegate = popoverDelegate {
Expand All @@ -41,11 +31,11 @@ class SettingsNavigationController: UINavigationController {
}

override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return self.topViewController?.supportedInterfaceOrientations ?? .portrait
return .portrait
}

override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
return self.topViewController?.preferredInterfaceOrientationForPresentation ?? .portrait
return .portrait
}
}

Expand Down
5 changes: 1 addition & 4 deletions Sources/Brave/Frontend/Settings/SettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -355,10 +355,7 @@ class SettingsViewController: TableViewController {
syncProfileService:
syncProfileServices,
tabManager: tabManager,
windowProtection: windowProtection)

// DeviceOrientation.shared.allowOnlyPortrait = UIDevice.current.userInterfaceIdiom != .pad
DeviceOrientation.shared.changeOrientationToPortraitOnPhone()
windowProtection: windowProtection)

self.navigationController?
.pushViewController(syncSettingsViewController, animated: true)
Expand Down
27 changes: 9 additions & 18 deletions Sources/BraveWallet/WalletHostingViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,36 +121,27 @@ public class WalletHostingViewController: UIHostingController<CryptoView> {
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() {
super.viewDidLoad()
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 {
Expand Down
4 changes: 0 additions & 4 deletions Sources/BraveWallet/WalletPanelHostingController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ public class WalletPanelHostingController: UIHostingController<WalletPanelContai
completion: {
let walletHostingController = WalletHostingViewController(walletStore: walletStore, webImageDownloader: webImageDownloader, presentingContext: .buySendSwap(destination))
walletHostingController.delegate = self.delegate

// DeviceOrientation.shared.allowOnlyPortrait = UIDevice.current.userInterfaceIdiom != .pad
DeviceOrientation.shared.changeOrientationToPortraitOnPhone()

self.present(walletHostingController, animated: true)
})
})
Expand Down
2 changes: 0 additions & 2 deletions Sources/Shared/DeviceOrientation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ public final class DeviceOrientation {

public static let shared: DeviceOrientation = DeviceOrientation()

// public var allowOnlyPortrait = false

public func changeOrientation(_ orientationMask: UIInterfaceOrientationMask) {
if #available(iOS 16.0, *) {
windowScene?.requestGeometryUpdate(.iOS(interfaceOrientations: orientationMask))
Expand Down

0 comments on commit 7756f6f

Please sign in to comment.