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

Commit

Permalink
NavigationController is added for changing orientation
Browse files Browse the repository at this point in the history
  • Loading branch information
soner-yuksel committed Nov 27, 2023
1 parent 5ae13af commit 665bc45
Show file tree
Hide file tree
Showing 13 changed files with 67 additions and 16 deletions.
3 changes: 0 additions & 3 deletions App/iOS/Delegates/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
if let presentedViewController = window?.rootViewController?.presentedViewController {
if DeviceOrientation.shared.allowOnlyPortrait {
return [.portrait, .portraitUpsideDown]
}
return presentedViewController.supportedInterfaceOrientations
} else {
return window?.rootViewController?.supportedInterfaceOrientations ?? .portraitUpsideDown
Expand Down
4 changes: 2 additions & 2 deletions Sources/Brave/Frontend/Browser/BrowserViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1502,7 +1502,7 @@ public class BrowserViewController: UIViewController {
.init(barButtonSystemItem: .cancel, target: nav, action: #selector(nav.done))
let idiom = UIDevice.current.userInterfaceIdiom

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

nav.modalPresentationStyle = idiom == .phone ? .pageSheet : .formSheet
Expand Down Expand Up @@ -2086,7 +2086,7 @@ 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.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 @@ -203,7 +203,7 @@ extension BrowserViewController {
let vc = WalletHostingViewController(walletStore: walletStore, webImageDownloader: braveCore.webImageDownloader)
vc.delegate = self

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

self.dismiss(animated: true) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ extension BrowserViewController: TopToolbarDelegate {
$0.toolbarUrlActionsDelegate = self
}
let container = UINavigationController(rootViewController: tabTrayController)
container.delegate = self

if !UIAccessibility.isReduceMotionEnabled {
if !isExternallyPresented {
Expand Down Expand Up @@ -1009,3 +1010,15 @@ extension BrowserViewController: UIContextMenuInteractionDelegate {
return UIMenu(options: .displayInline, children: children)
}
}

// MARK: - UINavigationControllerDelegate

extension BrowserViewController: UINavigationControllerDelegate {
public func navigationControllerSupportedInterfaceOrientations(_ navigationController: UINavigationController) -> UIInterfaceOrientationMask {
return navigationController.visibleViewController?.supportedInterfaceOrientations ?? navigationController.supportedInterfaceOrientations
}

public func navigationControllerPreferredInterfaceOrientationForPresentation(_ navigationController: UINavigationController) -> UIInterfaceOrientation {
return navigationController.visibleViewController?.preferredInterfaceOrientationForPresentation ?? navigationController.preferredInterfaceOrientationForPresentation
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ extension BrowserViewController: BraveWalletDelegate {
)
walletHostingController.delegate = self

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

switch presentWalletWithContext {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ 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.allowOnlyPortrait = UIDevice.current.userInterfaceIdiom != .pad
DeviceOrientation.shared.changeOrientationToPortraitOnPhone()

present(settingsNavigationController, animated: true)
Expand All @@ -794,6 +794,19 @@ class TabTrayController: AuthenticationController {
}
}

// MARK: - InterfaceOrientation

extension TabTrayController {

override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
return self.presentedViewController?.preferredInterfaceOrientationForPresentation ?? super.preferredInterfaceOrientationForPresentation
}

override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return self.presentedViewController?.supportedInterfaceOrientations ?? super.supportedInterfaceOrientations
}
}

// MARK: PresentingModalViewControllerDelegate

extension TabTrayController: PresentingModalViewControllerDelegate {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ class MenuViewController: UINavigationController, UIPopoverPresentationControlle
}
}

// MARK: - PanModalPresentable

extension MenuViewController: PanModalPresentable {
var panScrollable: UIScrollView? {
// For SwiftUI:
Expand Down Expand Up @@ -350,6 +352,14 @@ private class MenuNavigationControllerDelegate: NSObject, UINavigationController
) {
panModal?.panModalSetNeedsLayoutUpdate()
}

public func navigationControllerSupportedInterfaceOrientations(_ navigationController: UINavigationController) -> UIInterfaceOrientationMask {
return navigationController.visibleViewController?.supportedInterfaceOrientations ?? navigationController.supportedInterfaceOrientations
}

public func navigationControllerPreferredInterfaceOrientationForPresentation(_ navigationController: UINavigationController) -> UIInterfaceOrientation {
return navigationController.visibleViewController?.preferredInterfaceOrientationForPresentation ?? navigationController.preferredInterfaceOrientationForPresentation
}
}

private class InnerMenuNavigationController: UINavigationController {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class SettingsNavigationController: UINavigationController {
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)

DeviceOrientation.shared.allowOnlyPortrait = false
// DeviceOrientation.shared.allowOnlyPortrait = false
if #available(iOS 16.0, *) {
self.setNeedsUpdateOfSupportedInterfaceOrientations()
}
Expand All @@ -41,11 +41,11 @@ class SettingsNavigationController: UINavigationController {
}

override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return [.portrait, .portraitUpsideDown]
return self.topViewController?.supportedInterfaceOrientations ?? .portrait
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ class SettingsViewController: TableViewController {
tabManager: tabManager,
windowProtection: windowProtection)

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

self.navigationController?
Expand Down
18 changes: 18 additions & 0 deletions Sources/Brave/Frontend/Sync/SyncViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,21 @@ class SyncViewController: AuthenticationController {
}
}
}

// MARK: - InterfaceOrientation

extension SyncViewController {

override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return .portrait
}

override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
return .portrait
}

override var shouldAutorotate: Bool {
return false
}
}

2 changes: 1 addition & 1 deletion Sources/BraveWallet/WalletHostingViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public class WalletHostingViewController: UIHostingController<CryptoView> {
public override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)

DeviceOrientation.shared.allowOnlyPortrait = false
// DeviceOrientation.shared.allowOnlyPortrait = false

if #available(iOS 16.0, *) {
self.setNeedsUpdateOfSupportedInterfaceOrientations()
Expand Down
2 changes: 1 addition & 1 deletion Sources/BraveWallet/WalletPanelHostingController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class WalletPanelHostingController: UIHostingController<WalletPanelContai
let walletHostingController = WalletHostingViewController(walletStore: walletStore, webImageDownloader: webImageDownloader, presentingContext: .buySendSwap(destination))
walletHostingController.delegate = self.delegate

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

self.present(walletHostingController, animated: true)
Expand Down
2 changes: 1 addition & 1 deletion Sources/Shared/DeviceOrientation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public final class DeviceOrientation {

public static let shared: DeviceOrientation = DeviceOrientation()

public var allowOnlyPortrait = false
// public var allowOnlyPortrait = false

public func changeOrientation(_ orientationMask: UIInterfaceOrientationMask) {
if #available(iOS 16.0, *) {
Expand Down

0 comments on commit 665bc45

Please sign in to comment.