aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard/UI/iOS/View
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2019-02-27 13:30:57 +0530
committerJason A. Donenfeld <Jason@zx2c4.com>2019-03-18 06:46:55 +0100
commit5941bf181cc37368cfff5e1d92398bce6c7b8a5e (patch)
tree8375b2e35e3544512c25accedf2adb63ceea7346 /WireGuard/WireGuard/UI/iOS/View
parenton-demand: Introducing ActivateOnDemandViewModel (diff)
downloadwireguard-apple-5941bf181cc37368cfff5e1d92398bce6c7b8a5e.tar.xz
wireguard-apple-5941bf181cc37368cfff5e1d92398bce6c7b8a5e.zip
on-demand: iOS: Support for SSIDs
Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to 'WireGuard/WireGuard/UI/iOS/View')
-rw-r--r--WireGuard/WireGuard/UI/iOS/View/ChevronCell.swift25
-rw-r--r--WireGuard/WireGuard/UI/iOS/View/EditableTextCell.swift64
-rw-r--r--WireGuard/WireGuard/UI/iOS/View/TextCell.swift24
3 files changed, 113 insertions, 0 deletions
diff --git a/WireGuard/WireGuard/UI/iOS/View/ChevronCell.swift b/WireGuard/WireGuard/UI/iOS/View/ChevronCell.swift
new file mode 100644
index 0000000..94e4e05
--- /dev/null
+++ b/WireGuard/WireGuard/UI/iOS/View/ChevronCell.swift
@@ -0,0 +1,25 @@
+// SPDX-License-Identifier: MIT
+// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
+
+import UIKit
+
+class ChevronCell: UITableViewCell {
+ var message: String {
+ get { return textLabel?.text ?? "" }
+ set(value) { textLabel?.text = value }
+ }
+
+ override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
+ super.init(style: .default, reuseIdentifier: reuseIdentifier)
+ accessoryType = .disclosureIndicator
+ }
+
+ 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/EditableTextCell.swift b/WireGuard/WireGuard/UI/iOS/View/EditableTextCell.swift
new file mode 100644
index 0000000..178b200
--- /dev/null
+++ b/WireGuard/WireGuard/UI/iOS/View/EditableTextCell.swift
@@ -0,0 +1,64 @@
+// SPDX-License-Identifier: MIT
+// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
+
+import UIKit
+
+class EditableTextCell: UITableViewCell {
+ var message: String {
+ get { return valueTextField.text ?? "" }
+ set(value) { valueTextField.text = value }
+ }
+
+ let valueTextField: UITextField = {
+ let valueTextField = UITextField()
+ valueTextField.textAlignment = .left
+ valueTextField.isEnabled = true
+ valueTextField.font = UIFont.preferredFont(forTextStyle: .body)
+ valueTextField.adjustsFontForContentSizeCategory = true
+ valueTextField.autocapitalizationType = .none
+ valueTextField.autocorrectionType = .no
+ valueTextField.spellCheckingType = .no
+ return valueTextField
+ }()
+
+ var onValueBeingEdited: ((String) -> Void)?
+
+ override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
+ super.init(style: style, reuseIdentifier: reuseIdentifier)
+
+ valueTextField.delegate = self
+ contentView.addSubview(valueTextField)
+ valueTextField.translatesAutoresizingMaskIntoConstraints = false
+ let bottomAnchorConstraint = contentView.layoutMarginsGuide.bottomAnchor.constraint(equalToSystemSpacingBelow: valueTextField.bottomAnchor, multiplier: 1)
+ bottomAnchorConstraint.priority = .defaultLow
+ NSLayoutConstraint.activate([
+ valueTextField.leadingAnchor.constraint(equalToSystemSpacingAfter: contentView.layoutMarginsGuide.leadingAnchor, multiplier: 1),
+ contentView.layoutMarginsGuide.trailingAnchor.constraint(equalToSystemSpacingAfter: valueTextField.trailingAnchor, multiplier: 1),
+ valueTextField.topAnchor.constraint(equalToSystemSpacingBelow: contentView.layoutMarginsGuide.topAnchor, multiplier: 1),
+ bottomAnchorConstraint
+ ])
+ }
+
+ required init?(coder aDecoder: NSCoder) {
+ fatalError("init(coder:) has not been implemented")
+ }
+
+ func beginEditing() {
+ valueTextField.becomeFirstResponder()
+ }
+
+ override func prepareForReuse() {
+ super.prepareForReuse()
+ message = ""
+ }
+}
+
+extension EditableTextCell: UITextFieldDelegate {
+ 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)
+ onValueBeingEdited(modifiedText)
+ }
+ return true
+ }
+}
diff --git a/WireGuard/WireGuard/UI/iOS/View/TextCell.swift b/WireGuard/WireGuard/UI/iOS/View/TextCell.swift
new file mode 100644
index 0000000..303f9c7
--- /dev/null
+++ b/WireGuard/WireGuard/UI/iOS/View/TextCell.swift
@@ -0,0 +1,24 @@
+// SPDX-License-Identifier: MIT
+// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
+
+import UIKit
+
+class TextCell: UITableViewCell {
+ var message: String {
+ get { return textLabel?.text ?? "" }
+ set(value) { textLabel!.text = value }
+ }
+
+ override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
+ super.init(style: .default, reuseIdentifier: reuseIdentifier)
+ }
+
+ required init?(coder aDecoder: NSCoder) {
+ fatalError("init(coder:) has not been implemented")
+ }
+
+ override func prepareForReuse() {
+ super.prepareForReuse()
+ message = ""
+ }
+}