aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard/UI/iOS/View
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-12-21 23:34:56 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2018-12-21 23:34:56 +0100
commit7b9d4cb9e35a88f13face71543ce4773102fe224 (patch)
tree90810e67570a1bd2b520f352b50117925d3b1fab /WireGuard/WireGuard/UI/iOS/View
parentproviderConfiguration is now a WgQuickConfig (diff)
downloadwireguard-apple-7b9d4cb9e35a88f13face71543ce4773102fe224.tar.xz
wireguard-apple-7b9d4cb9e35a88f13face71543ce4773102fe224.zip
Nuke trailing spaces
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'WireGuard/WireGuard/UI/iOS/View')
-rw-r--r--WireGuard/WireGuard/UI/iOS/View/BorderedTextButton.swift20
-rw-r--r--WireGuard/WireGuard/UI/iOS/View/ButtonCell.swift16
-rw-r--r--WireGuard/WireGuard/UI/iOS/View/CheckmarkCell.swift6
-rw-r--r--WireGuard/WireGuard/UI/iOS/View/KeyValueCell.swift56
-rw-r--r--WireGuard/WireGuard/UI/iOS/View/SwitchCell.swift12
-rw-r--r--WireGuard/WireGuard/UI/iOS/View/TunnelEditKeyValueCell.swift18
-rw-r--r--WireGuard/WireGuard/UI/iOS/View/TunnelListCell.swift30
7 files changed, 79 insertions, 79 deletions
diff --git a/WireGuard/WireGuard/UI/iOS/View/BorderedTextButton.swift b/WireGuard/WireGuard/UI/iOS/View/BorderedTextButton.swift
index ab6dcc5..b1951e4 100644
--- a/WireGuard/WireGuard/UI/iOS/View/BorderedTextButton.swift
+++ b/WireGuard/WireGuard/UI/iOS/View/BorderedTextButton.swift
@@ -10,42 +10,42 @@ class BorderedTextButton: UIView {
button.titleLabel?.adjustsFontForContentSizeCategory = true
return button
}()
-
+
override var intrinsicContentSize: CGSize {
let buttonSize = button.intrinsicContentSize
return CGSize(width: buttonSize.width + 32, height: buttonSize.height + 16)
}
-
+
var title: String {
get { return button.title(for: .normal) ?? "" }
set(value) { button.setTitle(value, for: .normal) }
}
-
+
var onTapped: (() -> Void)?
-
+
init() {
super.init(frame: CGRect.zero)
-
+
layer.borderWidth = 1
layer.cornerRadius = 5
layer.borderColor = button.tintColor.cgColor
-
+
addSubview(button)
button.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
button.centerXAnchor.constraint(equalTo: centerXAnchor),
button.centerYAnchor.constraint(equalTo: centerYAnchor)
])
-
+
button.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)
}
-
+
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
-
+
@objc func buttonTapped() {
onTapped?()
}
-
+
}
diff --git a/WireGuard/WireGuard/UI/iOS/View/ButtonCell.swift b/WireGuard/WireGuard/UI/iOS/View/ButtonCell.swift
index aff17ee..5d9ab92 100644
--- a/WireGuard/WireGuard/UI/iOS/View/ButtonCell.swift
+++ b/WireGuard/WireGuard/UI/iOS/View/ButtonCell.swift
@@ -13,20 +13,20 @@ class ButtonCell: UITableViewCell {
set(value) { button.tintColor = value ? .red : buttonStandardTintColor }
}
var onTapped: (() -> Void)?
-
+
let button: UIButton = {
let button = UIButton(type: .system)
button.titleLabel?.font = UIFont.preferredFont(forTextStyle: .body)
button.titleLabel?.adjustsFontForContentSizeCategory = true
return button
}()
-
+
var buttonStandardTintColor: UIColor
-
+
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
buttonStandardTintColor = button.tintColor
super.init(style: style, reuseIdentifier: reuseIdentifier)
-
+
contentView.addSubview(button)
button.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
@@ -34,18 +34,18 @@ class ButtonCell: UITableViewCell {
contentView.layoutMarginsGuide.bottomAnchor.constraint(equalTo: button.bottomAnchor),
button.centerXAnchor.constraint(equalTo: contentView.centerXAnchor)
])
-
+
button.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)
}
-
+
@objc func buttonTapped() {
onTapped?()
}
-
+
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
-
+
override func prepareForReuse() {
super.prepareForReuse()
buttonText = ""
diff --git a/WireGuard/WireGuard/UI/iOS/View/CheckmarkCell.swift b/WireGuard/WireGuard/UI/iOS/View/CheckmarkCell.swift
index db4b6c9..77cd501 100644
--- a/WireGuard/WireGuard/UI/iOS/View/CheckmarkCell.swift
+++ b/WireGuard/WireGuard/UI/iOS/View/CheckmarkCell.swift
@@ -13,16 +13,16 @@ class CheckmarkCell: UITableViewCell {
accessoryType = isChecked ? .checkmark : .none
}
}
-
+
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
isChecked = false
super.init(style: .default, reuseIdentifier: reuseIdentifier)
}
-
+
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
-
+
override func prepareForReuse() {
super.prepareForReuse()
message = ""
diff --git a/WireGuard/WireGuard/UI/iOS/View/KeyValueCell.swift b/WireGuard/WireGuard/UI/iOS/View/KeyValueCell.swift
index a456de1..81a1712 100644
--- a/WireGuard/WireGuard/UI/iOS/View/KeyValueCell.swift
+++ b/WireGuard/WireGuard/UI/iOS/View/KeyValueCell.swift
@@ -4,7 +4,7 @@
import UIKit
class KeyValueCell: UITableViewCell {
-
+
let keyLabel: UILabel = {
let keyLabel = UILabel()
keyLabel.font = UIFont.preferredFont(forTextStyle: .body)
@@ -13,7 +13,7 @@ class KeyValueCell: UITableViewCell {
keyLabel.textAlignment = .left
return keyLabel
}()
-
+
let valueLabelScrollView: UIScrollView = {
let scrollView = UIScrollView(frame: .zero)
scrollView.isDirectionalLockEnabled = true
@@ -21,7 +21,7 @@ class KeyValueCell: UITableViewCell {
scrollView.showsVerticalScrollIndicator = false
return scrollView
}()
-
+
let valueTextField: UITextField = {
let valueTextField = UITextField()
valueTextField.textAlignment = .right
@@ -34,7 +34,7 @@ class KeyValueCell: UITableViewCell {
valueTextField.textColor = .gray
return valueTextField
}()
-
+
var copyableGesture = true
var key: String {
@@ -53,7 +53,7 @@ class KeyValueCell: UITableViewCell {
get { return valueTextField.keyboardType }
set(value) { valueTextField.keyboardType = value }
}
-
+
var isValueValid = true {
didSet {
if isValueValid {
@@ -63,26 +63,26 @@ class KeyValueCell: UITableViewCell {
}
}
}
-
+
var isStackedHorizontally = false
var isStackedVertically = false
var contentSizeBasedConstraints = [NSLayoutConstraint]()
-
+
var onValueChanged: ((String) -> Void)?
var onValueBeingEdited: ((String) -> Void)?
-
+
private var textFieldValueOnBeginEditing: String = ""
-
+
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
-
+
contentView.addSubview(keyLabel)
keyLabel.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
keyLabel.leftAnchor.constraint(equalTo: contentView.layoutMarginsGuide.leftAnchor),
keyLabel.topAnchor.constraint(equalToSystemSpacingBelow: contentView.layoutMarginsGuide.topAnchor, multiplier: 0.5)
])
-
+
valueTextField.delegate = self
valueLabelScrollView.addSubview(valueTextField)
valueTextField.translatesAutoresizingMaskIntoConstraints = false
@@ -96,31 +96,31 @@ class KeyValueCell: UITableViewCell {
let expandToFitValueLabelConstraint = NSLayoutConstraint(item: valueTextField, attribute: .width, relatedBy: .equal, toItem: valueLabelScrollView, attribute: .width, multiplier: 1, constant: 0)
expandToFitValueLabelConstraint.priority = .defaultLow + 1
expandToFitValueLabelConstraint.isActive = true
-
+
contentView.addSubview(valueLabelScrollView)
-
+
contentView.addSubview(valueLabelScrollView)
valueLabelScrollView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
valueLabelScrollView.rightAnchor.constraint(equalTo: contentView.layoutMarginsGuide.rightAnchor),
contentView.layoutMarginsGuide.bottomAnchor.constraint(equalToSystemSpacingBelow: valueLabelScrollView.bottomAnchor, multiplier: 0.5)
])
-
+
keyLabel.setContentCompressionResistancePriority(.defaultHigh + 1, for: .horizontal)
keyLabel.setContentHuggingPriority(.defaultHigh, for: .horizontal)
valueLabelScrollView.setContentHuggingPriority(.defaultLow, for: .horizontal)
-
+
let gestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(handleTapGesture(_:)))
addGestureRecognizer(gestureRecognizer)
isUserInteractionEnabled = true
-
+
configureForContentSize()
}
-
+
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
-
+
func configureForContentSize() {
var constraints = [NSLayoutConstraint]()
if traitCollection.preferredContentSizeCategory.isAccessibilityCategory {
@@ -152,13 +152,13 @@ class KeyValueCell: UITableViewCell {
contentSizeBasedConstraints = constraints
}
}
-
+
@objc func handleTapGesture(_ recognizer: UIGestureRecognizer) {
if !copyableGesture {
return
}
guard recognizer.state == .recognized else { return }
-
+
if let recognizerView = recognizer.view,
let recognizerSuperView = recognizerView.superview, recognizerView.becomeFirstResponder() {
let menuController = UIMenuController.shared
@@ -166,19 +166,19 @@ class KeyValueCell: UITableViewCell {
menuController.setMenuVisible(true, animated: true)
}
}
-
+
override var canBecomeFirstResponder: Bool {
return true
}
-
+
override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
return (action == #selector(UIResponderStandardEditActions.copy(_:)))
}
-
+
override func copy(_ sender: Any?) {
UIPasteboard.general.string = valueTextField.text
}
-
+
override func prepareForReuse() {
super.prepareForReuse()
copyableGesture = true
@@ -194,18 +194,18 @@ class KeyValueCell: UITableViewCell {
}
extension KeyValueCell: UITextFieldDelegate {
-
+
func textFieldDidBeginEditing(_ textField: UITextField) {
textFieldValueOnBeginEditing = textField.text ?? ""
isValueValid = true
}
-
+
func textFieldDidEndEditing(_ textField: UITextField) {
let isModified = textField.text ?? "" != textFieldValueOnBeginEditing
guard isModified else { return }
onValueChanged?(textField.text ?? "")
}
-
+
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
if let onValueBeingEdited = onValueBeingEdited {
let modifiedText = ((textField.text ?? "") as NSString).replacingCharacters(in: range, with: string)
@@ -213,5 +213,5 @@ extension KeyValueCell: UITextFieldDelegate {
}
return true
}
-
+
}
diff --git a/WireGuard/WireGuard/UI/iOS/View/SwitchCell.swift b/WireGuard/WireGuard/UI/iOS/View/SwitchCell.swift
index d0c29aa..68939a7 100644
--- a/WireGuard/WireGuard/UI/iOS/View/SwitchCell.swift
+++ b/WireGuard/WireGuard/UI/iOS/View/SwitchCell.swift
@@ -19,14 +19,14 @@ class SwitchCell: UITableViewCell {
textLabel?.textColor = value ? .black : .gray
}
}
-
+
var onSwitchToggled: ((Bool) -> Void)?
-
+
let switchView = UISwitch()
-
+
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: .default, reuseIdentifier: reuseIdentifier)
-
+
accessoryView = switchView
switchView.addTarget(self, action: #selector(switchToggled), for: .valueChanged)
}
@@ -34,11 +34,11 @@ class SwitchCell: UITableViewCell {
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
-
+
@objc func switchToggled() {
onSwitchToggled?(switchView.isOn)
}
-
+
override func prepareForReuse() {
super.prepareForReuse()
isEnabled = true
diff --git a/WireGuard/WireGuard/UI/iOS/View/TunnelEditKeyValueCell.swift b/WireGuard/WireGuard/UI/iOS/View/TunnelEditKeyValueCell.swift
index fc9595f..57132d6 100644
--- a/WireGuard/WireGuard/UI/iOS/View/TunnelEditKeyValueCell.swift
+++ b/WireGuard/WireGuard/UI/iOS/View/TunnelEditKeyValueCell.swift
@@ -4,40 +4,40 @@
import UIKit
class TunnelEditKeyValueCell: KeyValueCell {
-
+
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
-
+
keyLabel.textAlignment = .right
valueTextField.textAlignment = .left
-
+
let widthRatioConstraint = NSLayoutConstraint(item: keyLabel, attribute: .width, relatedBy: .equal, toItem: self, attribute: .width, multiplier: 0.4, constant: 0)
// In case the key doesn't fit into 0.4 * width,
// set a CR priority > the 0.4-constraint's priority.
widthRatioConstraint.priority = .defaultHigh + 1
widthRatioConstraint.isActive = true
}
-
+
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
-
+
}
class TunnelEditEditableKeyValueCell: TunnelEditKeyValueCell {
-
+
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
-
+
copyableGesture = false
valueTextField.textColor = .black
valueTextField.isEnabled = true
valueLabelScrollView.isScrollEnabled = false
valueTextField.widthAnchor.constraint(equalTo: valueLabelScrollView.widthAnchor).isActive = true
}
-
+
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
-
+
}
diff --git a/WireGuard/WireGuard/UI/iOS/View/TunnelListCell.swift b/WireGuard/WireGuard/UI/iOS/View/TunnelListCell.swift
index d13346a..2965476 100644
--- a/WireGuard/WireGuard/UI/iOS/View/TunnelListCell.swift
+++ b/WireGuard/WireGuard/UI/iOS/View/TunnelListCell.swift
@@ -19,7 +19,7 @@ class TunnelListCell: UITableViewCell {
}
}
var onSwitchToggled: ((Bool) -> Void)?
-
+
let nameLabel: UILabel = {
let nameLabel = UILabel()
nameLabel.font = UIFont.preferredFont(forTextStyle: .body)
@@ -27,35 +27,35 @@ class TunnelListCell: UITableViewCell {
nameLabel.numberOfLines = 0
return nameLabel
}()
-
+
let busyIndicator: UIActivityIndicatorView = {
let busyIndicator = UIActivityIndicatorView(style: .gray)
busyIndicator.hidesWhenStopped = true
return busyIndicator
}()
-
+
let statusSwitch = UISwitch()
-
+
private var statusObservationToken: AnyObject?
private var nameObservationToken: AnyObject?
-
+
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
-
+
contentView.addSubview(statusSwitch)
statusSwitch.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
statusSwitch.centerYAnchor.constraint(equalTo: contentView.centerYAnchor),
contentView.rightAnchor.constraint(equalTo: statusSwitch.rightAnchor)
])
-
+
contentView.addSubview(busyIndicator)
busyIndicator.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
busyIndicator.centerYAnchor.constraint(equalTo: contentView.centerYAnchor),
statusSwitch.leftAnchor.constraint(equalToSystemSpacingAfter: busyIndicator.rightAnchor, multiplier: 1)
])
-
+
contentView.addSubview(nameLabel)
nameLabel.translatesAutoresizingMaskIntoConstraints = false
nameLabel.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
@@ -67,16 +67,16 @@ class TunnelListCell: UITableViewCell {
busyIndicator.leftAnchor.constraint(equalToSystemSpacingAfter: nameLabel.rightAnchor, multiplier: 1),
bottomAnchorConstraint
])
-
+
accessoryType = .disclosureIndicator
-
+
statusSwitch.addTarget(self, action: #selector(switchToggled), for: .valueChanged)
}
-
+
@objc func switchToggled() {
onSwitchToggled?(statusSwitch.isOn)
}
-
+
private func update(from status: TunnelStatus?) {
guard let status = status else {
reset()
@@ -93,17 +93,17 @@ class TunnelListCell: UITableViewCell {
}
}
}
-
+
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
-
+
private func reset() {
statusSwitch.isOn = false
statusSwitch.isUserInteractionEnabled = false
busyIndicator.stopAnimating()
}
-
+
override func prepareForReuse() {
super.prepareForReuse()
reset()