summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@mullvad.net>2021-03-08 12:48:28 +0100
committerAndrej Mihajlov <and@mullvad.net>2021-03-17 16:28:25 +0100
commitd7d77f855f4f19e6643aa155e08ae419a90a32a9 (patch)
tree361442022435c04d0aa7f44b9a81df6e49d02499
parent0b9ad2949ccfba7f4f7c1369dbc8fd158c528d1e (diff)
downloadmullvadvpn-d7d77f855f4f19e6643aa155e08ae419a90a32a9.tar.xz
mullvadvpn-d7d77f855f4f19e6643aa155e08ae419a90a32a9.zip
Handle interface orientation
-rw-r--r--ios/MullvadVPN/AppDelegate.swift11
-rw-r--r--ios/MullvadVPN/RootContainerViewController.swift34
2 files changed, 45 insertions, 0 deletions
diff --git a/ios/MullvadVPN/AppDelegate.swift b/ios/MullvadVPN/AppDelegate.swift
index 07b20b7d36..f36a4c8560 100644
--- a/ios/MullvadVPN/AppDelegate.swift
+++ b/ios/MullvadVPN/AppDelegate.swift
@@ -142,6 +142,17 @@ extension AppDelegate: RootContainerViewControllerDelegate {
controller.present(navController, animated: animated)
}
+
+ func rootContainerViewSupportedInterfaceOrientations(_ controller: RootContainerViewController) -> UIInterfaceOrientationMask {
+ switch self.window?.traitCollection.userInterfaceIdiom {
+ case .pad:
+ return [.landscape, .portrait]
+ case .phone:
+ return [.portrait]
+ default:
+ fatalError("Not supported")
+ }
+ }
}
extension AppDelegate: LoginViewControllerDelegate {
diff --git a/ios/MullvadVPN/RootContainerViewController.swift b/ios/MullvadVPN/RootContainerViewController.swift
index 9ddc903af5..465fff6f1e 100644
--- a/ios/MullvadVPN/RootContainerViewController.swift
+++ b/ios/MullvadVPN/RootContainerViewController.swift
@@ -38,6 +38,8 @@ protocol RootContainment {
protocol RootContainerViewControllerDelegate: class {
func rootContainerViewControllerShouldShowSettings(_ controller: RootContainerViewController, navigateTo route: SettingsNavigationRoute?, animated: Bool)
+
+ func rootContainerViewSupportedInterfaceOrientations(_ controller: RootContainerViewController) -> UIInterfaceOrientationMask
}
/// A root container view controller
@@ -53,6 +55,8 @@ class RootContainerViewController: UIViewController {
private(set) var viewControllers = [UIViewController]()
+ private var interfaceOrientationMask: UIInterfaceOrientationMask?
+
var topViewController: UIViewController? {
return viewControllers.last
}
@@ -122,6 +126,16 @@ class RootContainerViewController: UIViewController {
topViewController?.endAppearanceTransition()
}
+ // MARK: - Autorotation
+
+ override var shouldAutorotate: Bool {
+ return true
+ }
+
+ override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
+ return interfaceOrientationMask ?? super.supportedInterfaceOrientations
+ }
+
// MARK: - Storyboard segue handling
override func unwind(for unwindSegue: UIStoryboardSegue, towards subsequentVC: UIViewController) {
@@ -142,6 +156,11 @@ class RootContainerViewController: UIViewController {
animated: Bool,
completion: CompletionHandler? = nil)
{
+ // Fetch the initial orientation mask
+ if interfaceOrientationMask == nil {
+ updateInterfaceOrientation(attemptRotateToDeviceOrientation: false)
+ }
+
setViewControllersInternal(
newViewControllers,
isUnwinding: false,
@@ -260,6 +279,8 @@ class RootContainerViewController: UIViewController {
}
}
+ self.updateInterfaceOrientation(attemptRotateToDeviceOrientation: true)
+
completion?()
}
@@ -408,6 +429,19 @@ class RootContainerViewController: UIViewController {
}
}
+ private func updateInterfaceOrientation(attemptRotateToDeviceOrientation: Bool) {
+ let newSupportedOrientations = delegate?.rootContainerViewSupportedInterfaceOrientations(self)
+
+ if interfaceOrientationMask != newSupportedOrientations {
+ interfaceOrientationMask = newSupportedOrientations
+
+ // Tell UIKit to update the interface orientation
+ if attemptRotateToDeviceOrientation {
+ Self.attemptRotationToDeviceOrientation()
+ }
+ }
+ }
+
}
class RootContainerPushSegue: UIStoryboardSegue {