summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@mullvad.net>2021-04-14 15:33:55 +0200
committerAndrej Mihajlov <and@mullvad.net>2021-05-12 10:20:13 +0200
commitdb57a853613edb539b200e8732b500c8ccc99f67 (patch)
treef26bc1d1a333860d5f201e792ee1bee877f46ce5
parent24959b13394223547eb548f86f748a670a5f2b15 (diff)
downloadmullvadvpn-db57a853613edb539b200e8732b500c8ccc99f67.tar.xz
mullvadvpn-db57a853613edb539b200e8732b500c8ccc99f67.zip
Root: add methods to move settings button between header bar and presentation container
-rw-r--r--ios/MullvadVPN/RootContainerViewController.swift40
1 files changed, 35 insertions, 5 deletions
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)