diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2021-06-07 15:08:20 +0200 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2021-06-08 14:27:28 +0200 |
| commit | 33de35c96bac4e56258dce242291ae7c1237b880 (patch) | |
| tree | ca568577bb3a61d9e3e843434285efd07e654e7c /ios | |
| parent | 96235b29e25ac3c73ee1d0b3ed89674dcc9eede7 (diff) | |
| download | mullvadvpn-33de35c96bac4e56258dce242291ae7c1237b880.tar.xz mullvadvpn-33de35c96bac4e56258dce242291ae7c1237b880.zip | |
SelectLocationCell: replace RelayStatusIndicatorView with a plain old UIView
Diffstat (limited to 'ios')
| -rw-r--r-- | ios/MullvadVPN.xcodeproj/project.pbxproj | 4 | ||||
| -rw-r--r-- | ios/MullvadVPN/RelayStatusIndicatorView.swift | 86 | ||||
| -rw-r--r-- | ios/MullvadVPN/SelectLocationCell.swift | 37 | ||||
| -rw-r--r-- | ios/MullvadVPN/SelectLocationViewController.swift | 1 | ||||
| -rw-r--r-- | ios/MullvadVPN/UIColor+Palette.swift | 1 |
5 files changed, 34 insertions, 95 deletions
diff --git a/ios/MullvadVPN.xcodeproj/project.pbxproj b/ios/MullvadVPN.xcodeproj/project.pbxproj index 6f2b14eee4..81ce229871 100644 --- a/ios/MullvadVPN.xcodeproj/project.pbxproj +++ b/ios/MullvadVPN.xcodeproj/project.pbxproj @@ -135,7 +135,6 @@ 58871D1825D5359B002297FA /* MullvadRest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58CB0EDF24B86751001EF0D8 /* MullvadRest.swift */; }; 58871D1E25D535A3002297FA /* WireGuardKit in Frameworks */ = {isa = PBXBuildFile; productRef = 58871D1D25D535A3002297FA /* WireGuardKit */; }; 58871D2325D535D2002297FA /* IPAddressRange+Codable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5850366725A47AC700A43E93 /* IPAddressRange+Codable.swift */; }; - 5888AD7F2279B6BF0051EB06 /* RelayStatusIndicatorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5888AD7E2279B6BF0051EB06 /* RelayStatusIndicatorView.swift */; }; 5888AD83227B11080051EB06 /* SelectLocationCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5888AD82227B11080051EB06 /* SelectLocationCell.swift */; }; 5888AD87227B17950051EB06 /* SelectLocationViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5888AD86227B17950051EB06 /* SelectLocationViewController.swift */; }; 588D2FE3248AC27F00E313F7 /* AsyncOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58E973DD24850EB600096F90 /* AsyncOperation.swift */; }; @@ -362,7 +361,6 @@ 587B7544266922BF00DEF7E9 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = "<group>"; }; 587CBFE222807F530028DED3 /* UIColor+Helpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIColor+Helpers.swift"; sourceTree = "<group>"; }; 588534BD246193C00018B744 /* AutomaticKeyRotationManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AutomaticKeyRotationManager.swift; sourceTree = "<group>"; }; - 5888AD7E2279B6BF0051EB06 /* RelayStatusIndicatorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RelayStatusIndicatorView.swift; sourceTree = "<group>"; }; 5888AD82227B11080051EB06 /* SelectLocationCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectLocationCell.swift; sourceTree = "<group>"; }; 5888AD86227B17950051EB06 /* SelectLocationViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectLocationViewController.swift; sourceTree = "<group>"; }; 58906DDF2445C7A5002F0673 /* NEProviderStopReason+Debug.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NEProviderStopReason+Debug.swift"; sourceTree = "<group>"; }; @@ -661,7 +659,6 @@ 58BFA5C522A7C97F00A6173D /* RelayCache.swift */, 58781CC822AE7CA8009B9D8E /* RelayConstraints.swift */, 58781CD422AFBA39009B9D8E /* RelaySelector.swift */, - 5888AD7E2279B6BF0051EB06 /* RelayStatusIndicatorView.swift */, 587425C02299833500CA2045 /* RootContainerViewController.swift */, 5888AD82227B11080051EB06 /* SelectLocationCell.swift */, 5857F24224C8662600CF6F47 /* SelectLocationHeaderView.swift */, @@ -1101,7 +1098,6 @@ 589AB4F7227B64450039131E /* BasicTableViewCell.swift in Sources */, 58B9EB152489139B00095626 /* DisplayChainedError.swift in Sources */, 5868BD33261DCD2600E6027F /* CustomSplitViewController.swift in Sources */, - 5888AD7F2279B6BF0051EB06 /* RelayStatusIndicatorView.swift in Sources */, 58CCA01E2242787B004F3011 /* AccountTextField.swift in Sources */, 584592612639B4A200EF967F /* ConsentContentView.swift in Sources */, 587AD7CA2342283900E93A53 /* Account.swift in Sources */, diff --git a/ios/MullvadVPN/RelayStatusIndicatorView.swift b/ios/MullvadVPN/RelayStatusIndicatorView.swift deleted file mode 100644 index ab8626001e..0000000000 --- a/ios/MullvadVPN/RelayStatusIndicatorView.swift +++ /dev/null @@ -1,86 +0,0 @@ -// -// RelayStatusIndicatorView.swift -// MullvadVPN -// -// Created by pronebird on 01/05/2019. -// Copyright © 2019 Mullvad VPN AB. All rights reserved. -// - -import UIKit - -@IBDesignable class RelayStatusIndicatorView: UIControl { - - private let circleLayer: CALayer = { - let layer = CALayer() - layer.needsDisplayOnBoundsChange = true - return layer - }() - - @IBInspectable var isActive: Bool = false { - didSet { - updateCircleLayerColor() - } - } - - override var isHighlighted: Bool { - didSet { - updateCircleLayerColor() - } - } - - override init(frame: CGRect) { - super.init(frame: frame) - - setup() - } - - required init?(coder aDecoder: NSCoder) { - super.init(coder: aDecoder) - - setup() - } - - override func tintColorDidChange() { - super.tintColorDidChange() - - updateCircleLayerColor() - } - - override func layoutSublayers(of layer: CALayer) { - super.layoutSublayers(of: layer) - - guard layer == self.layer else { return } - - // keep the circular layer square - let shortSide = min(layer.bounds.width, layer.bounds.height) - let circleOrigin = CGPoint( - x: (layer.bounds.width - shortSide) * 0.5, - y: (layer.bounds.height - shortSide) * 0.5 - ) - let circleSize = CGSize(width: shortSide, height: shortSide) - - circleLayer.frame = CGRect(origin: circleOrigin, size: circleSize) - circleLayer.cornerRadius = shortSide * 0.5 - } - - private func setup() { - isUserInteractionEnabled = false - backgroundColor = UIColor.clear - - layer.addSublayer(circleLayer) - updateCircleLayerColor() - } - - private func updateCircleLayerColor() { - let baseColor = isActive - ? UIColor.RelayStatusIndicator.activeColor - : UIColor.RelayStatusIndicator.inactiveColor - - let circleColor: UIColor = isHighlighted ? tintColor : baseColor - - CATransaction.begin() - CATransaction.setDisableActions(true) - circleLayer.backgroundColor = circleColor.cgColor - CATransaction.commit() - } -} diff --git a/ios/MullvadVPN/SelectLocationCell.swift b/ios/MullvadVPN/SelectLocationCell.swift index ef41257303..a86543d430 100644 --- a/ios/MullvadVPN/SelectLocationCell.swift +++ b/ios/MullvadVPN/SelectLocationCell.swift @@ -9,12 +9,20 @@ import UIKit private let kCollapseButtonWidth: CGFloat = 24 +private let kRelayIndicatorSize: CGFloat = 16 class SelectLocationCell: BasicTableViewCell { typealias CollapseHandler = (SelectLocationCell) -> Void let locationLabel = UILabel() - let statusIndicator = RelayStatusIndicatorView() + let statusIndicator: UIView = { + let view = UIView() + view.layer.cornerRadius = kRelayIndicatorSize * 0.5 + if #available(iOS 13.0, *) { + view.layer.cornerCurve = .circular + } + return view + }() let tickImageView = UIImageView(image: UIImage(named: "IconTick")) let collapseButton = UIButton(type: .custom) @@ -25,6 +33,7 @@ class SelectLocationCell: BasicTableViewCell { didSet { updateDisabled() updateBackgroundColor() + updateStatusIndicatorColor() } } @@ -75,10 +84,17 @@ class SelectLocationCell: BasicTableViewCell { ) } + override func setHighlighted(_ highlighted: Bool, animated: Bool) { + super.setHighlighted(highlighted, animated: animated) + + updateStatusIndicatorColor() + } + override func setSelected(_ selected: Bool, animated: Bool) { super.setSelected(selected, animated: animated) updateTickImage() + updateStatusIndicatorColor() } private func setupCell() { @@ -90,7 +106,6 @@ class SelectLocationCell: BasicTableViewCell { locationLabel.font = UIFont.systemFont(ofSize: 17) locationLabel.textColor = .white - statusIndicator.tintColor = .white tickImageView.tintColor = .white collapseButton.accessibilityIdentifier = "CollapseButton" @@ -112,8 +127,8 @@ class SelectLocationCell: BasicTableViewCell { tickImageView.leadingAnchor.constraint(equalTo: contentView.layoutMarginsGuide.leadingAnchor), tickImageView.centerYAnchor.constraint(equalTo: contentView.centerYAnchor), - statusIndicator.widthAnchor.constraint(equalToConstant: 16), - statusIndicator.heightAnchor.constraint(equalToConstant: 16), + statusIndicator.widthAnchor.constraint(equalToConstant: kRelayIndicatorSize), + statusIndicator.heightAnchor.constraint(equalTo: statusIndicator.widthAnchor), statusIndicator.centerXAnchor.constraint(equalTo: tickImageView.centerXAnchor), statusIndicator.centerYAnchor.constraint(equalTo: tickImageView.centerYAnchor), @@ -134,6 +149,10 @@ class SelectLocationCell: BasicTableViewCell { tickImageView.isHidden = !isSelected } + private func updateStatusIndicatorColor() { + statusIndicator.backgroundColor = statusIndicatorColor() + } + private func updateDisabled() { locationLabel.alpha = isDisabled ? 0.2 : 1 collapseButton.alpha = isDisabled ? 0.2 : 1 @@ -169,6 +188,16 @@ class SelectLocationCell: BasicTableViewCell { } } + private func statusIndicatorColor() -> UIColor { + if isDisabled { + return UIColor.RelayStatusIndicator.inactiveColor + } else if isHighlighted { + return UIColor.RelayStatusIndicator.highlightColor + } else { + return UIColor.RelayStatusIndicator.activeColor + } + } + @objc private func handleCollapseButton(_ sender: UIControl) { didCollapseHandler?(self) } diff --git a/ios/MullvadVPN/SelectLocationViewController.swift b/ios/MullvadVPN/SelectLocationViewController.swift index 947b138863..2e17e44a15 100644 --- a/ios/MullvadVPN/SelectLocationViewController.swift +++ b/ios/MullvadVPN/SelectLocationViewController.swift @@ -81,7 +81,6 @@ class SelectLocationViewController: UIViewController, UITableViewDelegate { cell.accessibilityIdentifier = item.location.stringRepresentation cell.isDisabled = !item.isActive cell.locationLabel.text = item.displayName - cell.statusIndicator.isActive = item.isActive cell.showsCollapseControl = item.isCollapsible cell.isExpanded = item.showsChildren cell.didCollapseHandler = { [weak self] (cell) in diff --git a/ios/MullvadVPN/UIColor+Palette.swift b/ios/MullvadVPN/UIColor+Palette.swift index b50b31fe70..edcc13d2b7 100644 --- a/ios/MullvadVPN/UIColor+Palette.swift +++ b/ios/MullvadVPN/UIColor+Palette.swift @@ -51,6 +51,7 @@ extension UIColor { enum RelayStatusIndicator { static let activeColor = successColor.withAlphaComponent(0.9) static let inactiveColor = dangerColor.withAlphaComponent(0.95) + static let highlightColor = UIColor.white } enum MainSplitView { |
