aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard/UI/iOS/SharedViews
diff options
context:
space:
mode:
authorEric Kuck <eric@bluelinelabs.com>2018-12-14 17:12:59 -0600
committerEric Kuck <eric@bluelinelabs.com>2018-12-14 17:15:22 -0600
commit7a24f18eb753180800f9b44a767b0d59e4e702b7 (patch)
tree0e02b3ff59a672b0b25eb7bcc195e23730abec40 /WireGuard/WireGuard/UI/iOS/SharedViews
parentPrettier log time format (diff)
downloadwireguard-apple-7a24f18eb753180800f9b44a767b0d59e4e702b7.tar.xz
wireguard-apple-7a24f18eb753180800f9b44a767b0d59e4e702b7.zip
Most similar views now shared between ViewControllers
Signed-off-by: Eric Kuck <eric@bluelinelabs.com>
Diffstat (limited to '')
-rw-r--r--WireGuard/WireGuard/UI/iOS/SharedViews/BorderedTextButton.swift (renamed from WireGuard/WireGuard/UI/iOS/TunnelList/BorderedTextButton.swift)6
-rw-r--r--WireGuard/WireGuard/UI/iOS/SharedViews/ButtonCell.swift (renamed from WireGuard/WireGuard/UI/iOS/EditTunnel/TunnelEditButtonCell.swift)6
-rw-r--r--WireGuard/WireGuard/UI/iOS/SharedViews/CheckmarkCell.swift (renamed from WireGuard/WireGuard/UI/iOS/EditTunnel/TunnelEditSectionListCell.swift)3
-rw-r--r--WireGuard/WireGuard/UI/iOS/SharedViews/CopyableLabelTableViewCell.swift (renamed from WireGuard/WireGuard/UI/iOS/CopyableLabelTableViewCell.swift)10
-rw-r--r--WireGuard/WireGuard/UI/iOS/SharedViews/EditableKeyValueCell.swift (renamed from WireGuard/WireGuard/UI/iOS/EditTunnel/TunnelEditKeyValueCell.swift)12
-rw-r--r--WireGuard/WireGuard/UI/iOS/SharedViews/KeyValueCell.swift (renamed from WireGuard/WireGuard/UI/iOS/TunnelDetail/TunnelDetailKeyValueCell.swift)14
-rw-r--r--WireGuard/WireGuard/UI/iOS/SharedViews/ScrollableLabel.swift (renamed from WireGuard/WireGuard/UI/iOS/ScrollableLabel.swift)0
-rw-r--r--WireGuard/WireGuard/UI/iOS/SharedViews/SwitchCell.swift (renamed from WireGuard/WireGuard/UI/iOS/EditTunnel/TunnelEditSwitchCell.swift)19
8 files changed, 36 insertions, 34 deletions
diff --git a/WireGuard/WireGuard/UI/iOS/TunnelList/BorderedTextButton.swift b/WireGuard/WireGuard/UI/iOS/SharedViews/BorderedTextButton.swift
index 5114c09..94b76d6 100644
--- a/WireGuard/WireGuard/UI/iOS/TunnelList/BorderedTextButton.swift
+++ b/WireGuard/WireGuard/UI/iOS/SharedViews/BorderedTextButton.swift
@@ -33,9 +33,9 @@ class BorderedTextButton: UIView {
addSubview(button)
button.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
- button.centerXAnchor.constraint(equalTo: self.centerXAnchor),
- button.centerYAnchor.constraint(equalTo: self.centerYAnchor)
- ])
+ button.centerXAnchor.constraint(equalTo: centerXAnchor),
+ button.centerYAnchor.constraint(equalTo: centerYAnchor)
+ ])
button.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)
}
diff --git a/WireGuard/WireGuard/UI/iOS/EditTunnel/TunnelEditButtonCell.swift b/WireGuard/WireGuard/UI/iOS/SharedViews/ButtonCell.swift
index af70183..4702993 100644
--- a/WireGuard/WireGuard/UI/iOS/EditTunnel/TunnelEditButtonCell.swift
+++ b/WireGuard/WireGuard/UI/iOS/SharedViews/ButtonCell.swift
@@ -3,14 +3,14 @@
import UIKit
-class TunnelEditButtonCell: UITableViewCell {
+class ButtonCell: UITableViewCell {
var buttonText: String {
get { return button.title(for: .normal) ?? "" }
set(value) { button.setTitle(value, for: .normal) }
}
var hasDestructiveAction: Bool {
- get { return button.tintColor == UIColor.red }
- set(value) { button.tintColor = value ? UIColor.red : buttonStandardTintColor }
+ get { return button.tintColor == .red }
+ set(value) { button.tintColor = value ? .red : buttonStandardTintColor }
}
var onTapped: (() -> Void)?
diff --git a/WireGuard/WireGuard/UI/iOS/EditTunnel/TunnelEditSectionListCell.swift b/WireGuard/WireGuard/UI/iOS/SharedViews/CheckmarkCell.swift
index ca0352e..db4b6c9 100644
--- a/WireGuard/WireGuard/UI/iOS/EditTunnel/TunnelEditSectionListCell.swift
+++ b/WireGuard/WireGuard/UI/iOS/SharedViews/CheckmarkCell.swift
@@ -3,7 +3,7 @@
import UIKit
-class TunnelEditSelectionListCell: UITableViewCell {
+class CheckmarkCell: UITableViewCell {
var message: String {
get { return textLabel?.text ?? "" }
set(value) { textLabel!.text = value }
@@ -13,6 +13,7 @@ class TunnelEditSelectionListCell: UITableViewCell {
accessoryType = isChecked ? .checkmark : .none
}
}
+
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
isChecked = false
super.init(style: .default, reuseIdentifier: reuseIdentifier)
diff --git a/WireGuard/WireGuard/UI/iOS/CopyableLabelTableViewCell.swift b/WireGuard/WireGuard/UI/iOS/SharedViews/CopyableLabelTableViewCell.swift
index daddf0a..93a9ef7 100644
--- a/WireGuard/WireGuard/UI/iOS/CopyableLabelTableViewCell.swift
+++ b/WireGuard/WireGuard/UI/iOS/SharedViews/CopyableLabelTableViewCell.swift
@@ -17,13 +17,13 @@ class CopyableLabelTableViewCell: UITableViewCell {
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
let gestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(handleTapGesture(_:)))
- self.addGestureRecognizer(gestureRecognizer)
- self.isUserInteractionEnabled = true
+ addGestureRecognizer(gestureRecognizer)
+ isUserInteractionEnabled = true
}
// MARK: - UIGestureRecognizer
@objc func handleTapGesture(_ recognizer: UIGestureRecognizer) {
- if !self.copyableGesture {
+ if !copyableGesture {
return
}
guard recognizer.state == .recognized else { return }
@@ -31,7 +31,7 @@ class CopyableLabelTableViewCell: UITableViewCell {
if let recognizerView = recognizer.view,
let recognizerSuperView = recognizerView.superview, recognizerView.becomeFirstResponder() {
let menuController = UIMenuController.shared
- menuController.setTargetRect(self.detailTextLabel?.frame ?? recognizerView.frame, in: self.detailTextLabel?.superview ?? recognizerSuperView)
+ menuController.setTargetRect(detailTextLabel?.frame ?? recognizerView.frame, in: detailTextLabel?.superview ?? recognizerSuperView)
menuController.setMenuVisible(true, animated: true)
}
}
@@ -50,6 +50,6 @@ class CopyableLabelTableViewCell: UITableViewCell {
override func prepareForReuse() {
super.prepareForReuse()
- self.copyableGesture = true
+ copyableGesture = true
}
}
diff --git a/WireGuard/WireGuard/UI/iOS/EditTunnel/TunnelEditKeyValueCell.swift b/WireGuard/WireGuard/UI/iOS/SharedViews/EditableKeyValueCell.swift
index 432d75b..48956eb 100644
--- a/WireGuard/WireGuard/UI/iOS/EditTunnel/TunnelEditKeyValueCell.swift
+++ b/WireGuard/WireGuard/UI/iOS/SharedViews/EditableKeyValueCell.swift
@@ -3,10 +3,10 @@
import UIKit
-class TunnelEditKeyValueCell: UITableViewCell {
+class EditableKeyValueCell: UITableViewCell {
var key: String {
get { return keyLabel.text ?? "" }
- set(value) {keyLabel.text = value }
+ set(value) { keyLabel.text = value }
}
var value: String {
get { return valueTextField.text ?? "" }
@@ -89,7 +89,7 @@ class TunnelEditKeyValueCell: UITableViewCell {
func configureForContentSize() {
var constraints = [NSLayoutConstraint]()
- if self.traitCollection.preferredContentSizeCategory.isAccessibilityCategory {
+ if traitCollection.preferredContentSizeCategory.isAccessibilityCategory {
// Stack vertically
if !isStackedVertically {
constraints = [
@@ -113,9 +113,9 @@ class TunnelEditKeyValueCell: UITableViewCell {
}
}
if !constraints.isEmpty {
- NSLayoutConstraint.deactivate(self.contentSizeBasedConstraints)
+ NSLayoutConstraint.deactivate(contentSizeBasedConstraints)
NSLayoutConstraint.activate(constraints)
- self.contentSizeBasedConstraints = constraints
+ contentSizeBasedConstraints = constraints
}
}
@@ -136,7 +136,7 @@ class TunnelEditKeyValueCell: UITableViewCell {
}
}
-extension TunnelEditKeyValueCell: UITextFieldDelegate {
+extension EditableKeyValueCell: UITextFieldDelegate {
func textFieldDidBeginEditing(_ textField: UITextField) {
textFieldValueOnBeginEditing = textField.text ?? ""
isValueValid = true
diff --git a/WireGuard/WireGuard/UI/iOS/TunnelDetail/TunnelDetailKeyValueCell.swift b/WireGuard/WireGuard/UI/iOS/SharedViews/KeyValueCell.swift
index cbe1c14..78026ea 100644
--- a/WireGuard/WireGuard/UI/iOS/TunnelDetail/TunnelDetailKeyValueCell.swift
+++ b/WireGuard/WireGuard/UI/iOS/SharedViews/KeyValueCell.swift
@@ -3,7 +3,7 @@
import UIKit
-class TunnelDetailKeyValueCell: CopyableLabelTableViewCell {
+class KeyValueCell: CopyableLabelTableViewCell {
var key: String {
get { return keyLabel.text ?? "" }
set(value) { keyLabel.text = value }
@@ -14,7 +14,7 @@ class TunnelDetailKeyValueCell: CopyableLabelTableViewCell {
}
override var textToCopy: String? {
- return self.valueLabel.text
+ return valueLabel.text
}
let keyLabel: UILabel = {
@@ -46,14 +46,14 @@ class TunnelDetailKeyValueCell: CopyableLabelTableViewCell {
NSLayoutConstraint.activate([
keyLabel.leftAnchor.constraint(equalTo: contentView.layoutMarginsGuide.leftAnchor),
keyLabel.topAnchor.constraint(equalToSystemSpacingBelow: contentView.layoutMarginsGuide.topAnchor, multiplier: 0.5)
- ])
+ ])
contentView.addSubview(valueLabel)
valueLabel.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
valueLabel.rightAnchor.constraint(equalTo: contentView.layoutMarginsGuide.rightAnchor),
contentView.layoutMarginsGuide.bottomAnchor.constraint(equalToSystemSpacingBelow: valueLabel.bottomAnchor, multiplier: 0.5)
- ])
+ ])
keyLabel.setContentCompressionResistancePriority(.defaultHigh + 1, for: .horizontal)
keyLabel.setContentHuggingPriority(.defaultHigh, for: .horizontal)
@@ -64,7 +64,7 @@ class TunnelDetailKeyValueCell: CopyableLabelTableViewCell {
func configureForContentSize() {
var constraints = [NSLayoutConstraint]()
- if self.traitCollection.preferredContentSizeCategory.isAccessibilityCategory {
+ if traitCollection.preferredContentSizeCategory.isAccessibilityCategory {
// Stack vertically
if !isStackedVertically {
constraints = [
@@ -88,9 +88,9 @@ class TunnelDetailKeyValueCell: CopyableLabelTableViewCell {
}
}
if !constraints.isEmpty {
- NSLayoutConstraint.deactivate(self.contentSizeBasedConstraints)
+ NSLayoutConstraint.deactivate(contentSizeBasedConstraints)
NSLayoutConstraint.activate(constraints)
- self.contentSizeBasedConstraints = constraints
+ contentSizeBasedConstraints = constraints
}
}
diff --git a/WireGuard/WireGuard/UI/iOS/ScrollableLabel.swift b/WireGuard/WireGuard/UI/iOS/SharedViews/ScrollableLabel.swift
index bd6f547..bd6f547 100644
--- a/WireGuard/WireGuard/UI/iOS/ScrollableLabel.swift
+++ b/WireGuard/WireGuard/UI/iOS/SharedViews/ScrollableLabel.swift
diff --git a/WireGuard/WireGuard/UI/iOS/EditTunnel/TunnelEditSwitchCell.swift b/WireGuard/WireGuard/UI/iOS/SharedViews/SwitchCell.swift
index 658fb95..d0c29aa 100644
--- a/WireGuard/WireGuard/UI/iOS/EditTunnel/TunnelEditSwitchCell.swift
+++ b/WireGuard/WireGuard/UI/iOS/SharedViews/SwitchCell.swift
@@ -3,10 +3,10 @@
import UIKit
-class TunnelEditSwitchCell: UITableViewCell {
+class SwitchCell: UITableViewCell {
var message: String {
get { return textLabel?.text ?? "" }
- set(value) { textLabel!.text = value }
+ set(value) { textLabel?.text = value }
}
var isOn: Bool {
get { return switchView.isOn }
@@ -16,31 +16,32 @@ class TunnelEditSwitchCell: UITableViewCell {
get { return switchView.isEnabled }
set(value) {
switchView.isEnabled = value
- textLabel?.textColor = value ? UIColor.black : UIColor.gray
+ textLabel?.textColor = value ? .black : .gray
}
}
var onSwitchToggled: ((Bool) -> Void)?
- let switchView: UISwitch
+ let switchView = UISwitch()
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
- switchView = UISwitch()
super.init(style: .default, reuseIdentifier: reuseIdentifier)
+
accessoryView = switchView
switchView.addTarget(self, action: #selector(switchToggled), for: .valueChanged)
}
+
+ required init?(coder aDecoder: NSCoder) {
+ fatalError("init(coder:) has not been implemented")
+ }
@objc func switchToggled() {
onSwitchToggled?(switchView.isOn)
}
- required init?(coder aDecoder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
-
override func prepareForReuse() {
super.prepareForReuse()
+ isEnabled = true
message = ""
isOn = false
}