diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2021-05-12 10:21:43 +0200 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2021-05-12 10:21:43 +0200 |
| commit | 7b58bbeddd85cc09c1b872bd74db6c0d40422cf3 (patch) | |
| tree | bbfbeb5115edfcbd452960b11824bdee7bc37133 | |
| parent | b85dafd57d077f42dbcde68e292e598ef74b0938 (diff) | |
| parent | d0f42a1a777ae36b0239c82432542fdd51df4149 (diff) | |
| download | mullvadvpn-7b58bbeddd85cc09c1b872bd74db6c0d40422cf3.tar.xz mullvadvpn-7b58bbeddd85cc09c1b872bd74db6c0d40422cf3.zip | |
Merge branch 'ipad-formsheet-settings-button'
| -rw-r--r-- | ios/MullvadVPN/AppDelegate.swift | 25 | ||||
| -rw-r--r-- | ios/MullvadVPN/HeaderBarView.swift | 19 | ||||
| -rw-r--r-- | ios/MullvadVPN/RootContainerViewController.swift | 40 |
3 files changed, 72 insertions, 12 deletions
diff --git a/ios/MullvadVPN/AppDelegate.swift b/ios/MullvadVPN/AppDelegate.swift index 1fce9cc3c7..749cfb749e 100644 --- a/ios/MullvadVPN/AppDelegate.swift +++ b/ios/MullvadVPN/AppDelegate.swift @@ -434,6 +434,9 @@ extension AppDelegate: LoginViewControllerDelegate { func loginViewControllerDidLogin(_ controller: LoginViewController) { self.window?.isUserInteractionEnabled = false + // Move the settings button back into header bar + self.rootContainer?.removeSettingsButtonFromPresentationContainer() + TunnelManager.shared.getRelayConstraints { [weak self] (result) in guard let self = self else { return } @@ -651,6 +654,28 @@ extension AppDelegate: UIAdaptivePresentationControllerDelegate { if let wrapper = presentationController.presentedViewController as? RootContainerViewController { wrapper.setOverrideHeaderBarHidden(style == .formSheet, animated: false) } + + guard style == .formSheet else { + // Move the settings button back into header bar + self.rootContainer?.removeSettingsButtonFromPresentationContainer() + + return + } + + // Add settings button into the modal container to make it accessible by user + if let transitionCoordinator = transitionCoordinator { + transitionCoordinator.animate(alongsideTransition: { (context) in + self.rootContainer?.addSettingsButtonToPresentationContainer(context.containerView) + }, completion: { (context) in + // no-op + }) + } else { + 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.") + } + } } } diff --git a/ios/MullvadVPN/HeaderBarView.swift b/ios/MullvadVPN/HeaderBarView.swift index 0fd4b8f7e9..54ef4b77b2 100644 --- a/ios/MullvadVPN/HeaderBarView.swift +++ b/ios/MullvadVPN/HeaderBarView.swift @@ -10,22 +10,30 @@ import Foundation import UIKit class HeaderBarView: UIView { - let logoImageView = UIImageView(image: UIImage(named: "LogoIcon")) + let logoImageView: UIImageView = { + let imageView = UIImageView(image: UIImage(named: "LogoIcon")) + imageView.translatesAutoresizingMaskIntoConstraints = false + return imageView + }() lazy var titleLabel: UILabel = { let titleLabel = UILabel() + titleLabel.translatesAutoresizingMaskIntoConstraints = false titleLabel.text = "MULLVAD VPN" titleLabel.font = UIFont.boldSystemFont(ofSize: 24) titleLabel.textColor = UIColor.white.withAlphaComponent(0.8) return titleLabel }() - lazy var settingsButton: UIButton = { + let settingsButton = makeSettingsButton() + + class func makeSettingsButton() -> UIButton { let settingsButton = UIButton(type: .custom) settingsButton.setImage(UIImage(named: "IconSettings"), for: .normal) + settingsButton.translatesAutoresizingMaskIntoConstraints = false settingsButton.accessibilityIdentifier = "SettingsButton" return settingsButton - }() + } override init(frame: CGRect) { super.init(frame: frame) @@ -52,10 +60,7 @@ class HeaderBarView: UIView { settingsButton.centerYAnchor.constraint(equalTo: titleLabel.centerYAnchor) ] - for view in [logoImageView, titleLabel, settingsButton] { - view.translatesAutoresizingMaskIntoConstraints = false - addSubview(view) - } + [logoImageView, titleLabel, settingsButton].forEach { addSubview($0) } NSLayoutConstraint.activate(constraints) } diff --git a/ios/MullvadVPN/RootContainerViewController.swift b/ios/MullvadVPN/RootContainerViewController.swift index dfa51344b7..c10d54fd35 100644 --- a/ios/MullvadVPN/RootContainerViewController.swift +++ b/ios/MullvadVPN/RootContainerViewController.swift @@ -49,6 +49,7 @@ class RootContainerViewController: UIViewController { private let headerBarView = HeaderBarView(frame: CGRect(x: 0, y: 0, width: 100, height: 100)) private let transitionContainer = UIView(frame: UIScreen.main.bounds) + private var presentationContainerSettingsButton: UIButton? private(set) var headerBarStyle = HeaderBarStyle.default private(set) var headerBarHidden = false @@ -200,6 +201,39 @@ class RootContainerViewController: UIViewController { /// Enable or disable the settings bar button displayed in the header bar func setEnableSettingsButton(_ isEnabled: Bool) { headerBarView.settingsButton.isEnabled = isEnabled + presentationContainerSettingsButton?.isEnabled = isEnabled + } + + /// Add settings bar button into the presentation container to make settings accessible even + /// when the root container is covered with modal. + func addSettingsButtonToPresentationContainer(_ presentationContainer: UIView) { + let settingsButton: UIButton + + if let transitionViewSettingsButton = presentationContainerSettingsButton { + transitionViewSettingsButton.removeFromSuperview() + settingsButton = transitionViewSettingsButton + } else { + settingsButton = HeaderBarView.makeSettingsButton() + settingsButton.isEnabled = headerBarView.settingsButton.isEnabled + settingsButton.addTarget(self, action: #selector(handleSettingsButtonTap), for: .touchUpInside) + + presentationContainerSettingsButton = settingsButton + } + + // Hide the settings button inside the header bar to avoid color blending issues + headerBarView.settingsButton.alpha = 0 + + presentationContainer.addSubview(settingsButton) + + NSLayoutConstraint.activate([ + settingsButton.centerXAnchor.constraint(equalTo: headerBarView.settingsButton.centerXAnchor), + settingsButton.centerYAnchor.constraint(equalTo: headerBarView.settingsButton.centerYAnchor), + ]) + } + + func removeSettingsButtonFromPresentationContainer() { + presentationContainerSettingsButton?.removeFromSuperview() + headerBarView.settingsButton.alpha = 1 } func setOverrideHeaderBarHidden(_ isHidden: Bool?, animated: Bool) { @@ -240,11 +274,7 @@ class RootContainerViewController: UIViewController { // Prevent automatic layout margins adjustment as we manually control them. headerBarView.insetsLayoutMarginsFromSafeArea = false - headerBarView.settingsButton.addTarget( - self, - action: #selector(handleSettingsButtonTap), - for: .touchUpInside - ) + headerBarView.settingsButton.addTarget(self, action: #selector(handleSettingsButtonTap), for: .touchUpInside) view.addSubview(headerBarView) |
