-
Notifications
You must be signed in to change notification settings - Fork 336
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split select location view into two sections
- Loading branch information
Jon Petersson
committed
Mar 4, 2024
1 parent
75c0537
commit d715098
Showing
31 changed files
with
1,094 additions
and
513 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
ios/MullvadVPN/Coordinators/Settings/SettingsValidationErrorConfiguration.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// SettingsValidationErrorConfiguration.swift | ||
// MullvadVPN | ||
// | ||
// Created by Jon Petersson on 2024-02-16. | ||
// Copyright © 2024 Mullvad VPN AB. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
struct SettingsValidationErrorConfiguration: UIContentConfiguration, Equatable { | ||
var errors: [CustomListFieldValidationError] = [] | ||
var directionalLayoutMargins: NSDirectionalEdgeInsets = UIMetrics.SettingsCell.settingsValidationErrorLayoutMargins | ||
|
||
func makeContentView() -> UIView & UIContentView { | ||
return SettingsValidationErrorContentView(configuration: self) | ||
} | ||
|
||
func updated(for state: UIConfigurationState) -> Self { | ||
return self | ||
} | ||
} |
90 changes: 90 additions & 0 deletions
90
ios/MullvadVPN/Coordinators/Settings/SettingsValidationErrorContentView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// | ||
// SettingsValidationErrorContentView.swift | ||
// MullvadVPN | ||
// | ||
// Created by Jon Petersson on 2024-02-16. | ||
// Copyright © 2024 Mullvad VPN AB. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
class SettingsValidationErrorContentView: UIView, UIContentView { | ||
let contentView = UIStackView() | ||
|
||
var icon: UIImageView { | ||
let view = UIImageView(image: UIImage(resource: .iconAlert).withTintColor(.dangerColor)) | ||
view.heightAnchor.constraint(equalToConstant: 14).isActive = true | ||
view.widthAnchor.constraint(equalTo: view.heightAnchor, multiplier: 1).isActive = true | ||
return view | ||
} | ||
|
||
var configuration: UIContentConfiguration { | ||
get { | ||
actualConfiguration | ||
} | ||
set { | ||
guard let newConfiguration = newValue as? SettingsValidationErrorConfiguration else { return } | ||
|
||
let previousConfiguration = actualConfiguration | ||
actualConfiguration = newConfiguration | ||
|
||
configureSubviews(previousConfiguration: previousConfiguration) | ||
} | ||
} | ||
|
||
private var actualConfiguration: SettingsValidationErrorConfiguration | ||
|
||
func supports(_ configuration: UIContentConfiguration) -> Bool { | ||
configuration is SettingsValidationErrorConfiguration | ||
} | ||
|
||
init(configuration: SettingsValidationErrorConfiguration) { | ||
actualConfiguration = configuration | ||
|
||
super.init(frame: CGRect(x: 0, y: 0, width: 100, height: 44)) | ||
|
||
addSubviews() | ||
configureSubviews() | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
private func addSubviews() { | ||
contentView.axis = .vertical | ||
contentView.spacing = 6 | ||
|
||
addConstrainedSubviews([contentView]) { | ||
contentView.pinEdgesToSuperviewMargins() | ||
} | ||
} | ||
|
||
private func configureSubviews(previousConfiguration: SettingsValidationErrorConfiguration? = nil) { | ||
guard actualConfiguration != previousConfiguration else { return } | ||
|
||
configureLayoutMargins() | ||
|
||
contentView.arrangedSubviews.forEach { view in | ||
view.removeFromSuperview() | ||
} | ||
|
||
actualConfiguration.errors.forEach { error in | ||
let label = UILabel() | ||
label.text = error.errorDescription | ||
label.numberOfLines = 0 | ||
label.font = .systemFont(ofSize: 13) | ||
label.textColor = .white.withAlphaComponent(0.6) | ||
|
||
let stackView = UIStackView(arrangedSubviews: [icon, label]) | ||
stackView.alignment = .top | ||
stackView.spacing = 6 | ||
|
||
contentView.addArrangedSubview(stackView) | ||
} | ||
} | ||
|
||
private func configureLayoutMargins() { | ||
directionalLayoutMargins = actualConfiguration.directionalLayoutMargins | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.