summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@mullvad.net>2021-05-18 10:49:28 +0200
committerAndrej Mihajlov <and@mullvad.net>2021-05-18 10:49:28 +0200
commit5bdce484c807042d1319ca11b123c220795e134c (patch)
tree57880870c9449ff81028063171718c09456850c4
parent3dde5e0693dc9b6364bf4207e70d936b45ef3230 (diff)
parente05ed21cf044466ba41fc0af22ea58ac1c5721ed (diff)
downloadmullvadvpn-5bdce484c807042d1319ca11b123c220795e134c.tar.xz
mullvadvpn-5bdce484c807042d1319ca11b123c220795e134c.zip
Merge branch 'ios12-fixes'
-rw-r--r--ios/MullvadVPN/AppDelegate.swift39
-rw-r--r--ios/MullvadVPN/AutomaticKeyboardResponder.swift20
-rw-r--r--ios/MullvadVPN/RootContainerViewController.swift4
3 files changed, 42 insertions, 21 deletions
diff --git a/ios/MullvadVPN/AppDelegate.swift b/ios/MullvadVPN/AppDelegate.swift
index 81dd1fea2f..c5bd912b40 100644
--- a/ios/MullvadVPN/AppDelegate.swift
+++ b/ios/MullvadVPN/AppDelegate.swift
@@ -295,28 +295,24 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
private func makeLoginContainerController() -> RootContainerViewController {
let rootContainerWrapper = RootContainerViewController()
rootContainerWrapper.delegate = self
- rootContainerWrapper.presentationController?.delegate = self
rootContainerWrapper.preferredContentSize = CGSize(width: 480, height: 600)
- if #available(iOS 13.0, *) {
- // Prevent swiping off the login or consent controllers
- rootContainerWrapper.isModalInPresentation = true
+ if UIDevice.current.userInterfaceIdiom == .pad {
+ rootContainerWrapper.modalPresentationStyle = .formSheet
+ if #available(iOS 13.0, *) {
+ // Prevent swiping off the login or consent controllers
+ rootContainerWrapper.isModalInPresentation = true
+ }
}
+ rootContainerWrapper.presentationController?.delegate = self
+
return rootContainerWrapper
}
private func makeLoginController() -> LoginViewController {
let controller = LoginViewController()
controller.delegate = self
-
- if UIDevice.current.userInterfaceIdiom == .pad {
- controller.modalPresentationStyle = .formSheet
- if #available(iOS 13.0, *) {
- controller.isModalInPresentation = true
- }
- }
-
return controller
}
@@ -637,17 +633,22 @@ extension AppDelegate: UIAdaptivePresentationControllerDelegate {
}
}
- func presentationController(_ controller: UIPresentationController, viewControllerForAdaptivePresentationStyle style: UIModalPresentationStyle) -> UIViewController? {
- return nil
- }
-
func presentationController(_ presentationController: UIPresentationController, willPresentWithAdaptiveStyle style: UIModalPresentationStyle, transitionCoordinator: UIViewControllerTransitionCoordinator?) {
+ let actualStyle: UIModalPresentationStyle
+
+ // When adaptive presentation is not changing, the `style` is set to `.none`
+ if case .none = style {
+ actualStyle = presentationController.presentedViewController.modalPresentationStyle
+ } else {
+ actualStyle = style
+ }
+
// Force hide header bar in .formSheet presentation and show it in .fullScreen presentation
if let wrapper = presentationController.presentedViewController as? RootContainerViewController {
- wrapper.setOverrideHeaderBarHidden(style == .formSheet, animated: false)
+ wrapper.setOverrideHeaderBarHidden(actualStyle == .formSheet, animated: false)
}
- guard style == .formSheet else {
+ guard actualStyle == .formSheet else {
// Move the settings button back into header bar
self.rootContainer?.removeSettingsButtonFromPresentationContainer()
@@ -665,7 +666,7 @@ extension AppDelegate: UIAdaptivePresentationControllerDelegate {
if let containerView = presentationController.containerView {
self.rootContainer?.addSettingsButtonToPresentationContainer(containerView)
} else {
- logger?.warning("Cannot obtain the containerView for presentation controller when presenting with adaptive style \(style.rawValue) and missing transition coordinator.")
+ logger?.warning("Cannot obtain the containerView for presentation controller when presenting with adaptive style \(actualStyle.rawValue) and missing transition coordinator.")
}
}
}
diff --git a/ios/MullvadVPN/AutomaticKeyboardResponder.swift b/ios/MullvadVPN/AutomaticKeyboardResponder.swift
index 04518a40ef..eef063261d 100644
--- a/ios/MullvadVPN/AutomaticKeyboardResponder.swift
+++ b/ios/MullvadVPN/AutomaticKeyboardResponder.swift
@@ -111,8 +111,24 @@ class AutomaticKeyboardResponder {
}
private var isFormSheetPresentation: Bool {
- return UIDevice.current.userInterfaceIdiom == .pad &&
- parentViewController?.modalPresentationStyle == .formSheet
+ // Form sheet is only supported on iPad
+ guard UIDevice.current.userInterfaceIdiom == .pad else { return false }
+
+ // Find the parent controller holding the view
+ guard let parent = parentViewController else { return false }
+
+ // Determine presentation style within the context
+ let presentationStyle: UIModalPresentationStyle
+
+ // Use the presentation style of a presented controller when parent controller is being presented as a child of
+ // other modal controller.
+ if let presented = parent.presentingViewController?.presentedViewController {
+ presentationStyle = presented.modalPresentationStyle
+ } else {
+ presentationStyle = parent.modalPresentationStyle
+ }
+
+ return presentationStyle == .formSheet
}
private func adjustContentInsets(keyboardRect: CGRect) {
diff --git a/ios/MullvadVPN/RootContainerViewController.swift b/ios/MullvadVPN/RootContainerViewController.swift
index ad5a76996e..d692e30835 100644
--- a/ios/MullvadVPN/RootContainerViewController.swift
+++ b/ios/MullvadVPN/RootContainerViewController.swift
@@ -86,6 +86,10 @@ class RootContainerViewController: UIViewController {
return false
}
+ override var disablesAutomaticKeyboardDismissal: Bool {
+ return topViewController?.disablesAutomaticKeyboardDismissal ?? super.disablesAutomaticKeyboardDismissal
+ }
+
// MARK: - View lifecycle
override func viewDidLoad() {