summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@mullvad.net>2021-03-18 09:54:50 +0100
committerAndrej Mihajlov <and@mullvad.net>2021-03-22 16:36:14 +0100
commit1b8e34bd64cc6c7029bf33b993cf121c449a8064 (patch)
tree458361b59e82fca1e66e1280bc934a506a1661f9
parent807d3bd61161bccbc73ef15636274aefbd006916 (diff)
downloadmullvadvpn-1b8e34bd64cc6c7029bf33b993cf121c449a8064.tar.xz
mullvadvpn-1b8e34bd64cc6c7029bf33b993cf121c449a8064.zip
Use fixed dimensions for the split button side button
Fixes recursive layout loop when using .bounds observer to adjust the title label
-rw-r--r--ios/MullvadVPN/DisconnectSplitButton.swift30
1 files changed, 11 insertions, 19 deletions
diff --git a/ios/MullvadVPN/DisconnectSplitButton.swift b/ios/MullvadVPN/DisconnectSplitButton.swift
index 61ac11579a..09fa5424cd 100644
--- a/ios/MullvadVPN/DisconnectSplitButton.swift
+++ b/ios/MullvadVPN/DisconnectSplitButton.swift
@@ -10,13 +10,16 @@ import Foundation
import UIKit
class DisconnectSplitButton: UIView {
+
+ private var secondaryButtonSize: CGSize {
+ return CGSize(width: 42, height: 42)
+ }
+
let primaryButton = AppButton(style: .translucentDangerSplitLeft)
- var secondaryButton = AppButton(style: .translucentDangerSplitRight)
+ let secondaryButton = AppButton(style: .translucentDangerSplitRight)
private let stackView: UIStackView
- private var secondaryButtonObserver: NSObjectProtocol?
-
init() {
stackView = UIStackView(arrangedSubviews: [primaryButton, secondaryButton])
stackView.translatesAutoresizingMaskIntoConstraints = false
@@ -26,34 +29,23 @@ class DisconnectSplitButton: UIView {
stackView.spacing = 1
primaryButton.titleLabel?.font = UIFont.systemFont(ofSize: 18, weight: .semibold)
- primaryButton.setContentHuggingPriority(.defaultLow, for: .horizontal)
- primaryButton.setContentHuggingPriority(.defaultLow, for: .vertical)
- primaryButton.setContentCompressionResistancePriority(.defaultHigh, for: .horizontal)
- primaryButton.setContentCompressionResistancePriority(.defaultHigh, for: .vertical)
-
secondaryButton.setImage(UIImage(named: "IconReload"), for: .normal)
- secondaryButton.setContentHuggingPriority(.defaultHigh, for: .horizontal)
- secondaryButton.setContentHuggingPriority(.defaultHigh, for: .vertical)
- secondaryButton.setContentCompressionResistancePriority(UILayoutPriority(50), for: .horizontal)
- secondaryButton.setContentCompressionResistancePriority(UILayoutPriority(50), for: .vertical)
super.init(frame: .zero)
addSubview(stackView)
- secondaryButtonObserver = secondaryButton.observe(\.bounds, options: [.new]) { [weak self] (button, change) in
- self?.adjustTitleLabelPosition()
- }
-
NSLayoutConstraint.activate([
stackView.leadingAnchor.constraint(equalTo: leadingAnchor),
stackView.trailingAnchor.constraint(equalTo: trailingAnchor),
stackView.topAnchor.constraint(equalTo: topAnchor),
stackView.bottomAnchor.constraint(equalTo: bottomAnchor),
- primaryButton.heightAnchor.constraint(equalTo: secondaryButton.heightAnchor),
- secondaryButton.widthAnchor.constraint(equalTo: secondaryButton.heightAnchor)
+ secondaryButton.widthAnchor.constraint(equalToConstant: self.secondaryButtonSize.width),
+ secondaryButton.heightAnchor.constraint(equalToConstant: self.secondaryButtonSize.height)
])
+
+ adjustTitleLabelPosition()
}
required init?(coder: NSCoder) {
@@ -62,7 +54,7 @@ class DisconnectSplitButton: UIView {
private func adjustTitleLabelPosition() {
var contentInsets = AppButton.defaultContentInsets
- contentInsets.left = secondaryButton.frame.width + stackView.spacing
+ contentInsets.left = stackView.spacing + self.secondaryButtonSize.width
contentInsets.right = 0
primaryButton.contentEdgeInsets = contentInsets