aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard/UI
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2018-11-02 13:24:10 +0530
committerRoopesh Chander <roop@roopc.net>2018-11-02 13:24:10 +0530
commit90af773fef10f50683eb49c382f00133aedb7387 (patch)
treeea0edde3234b815f5d50a54522131d9a8e6bc6fd /WireGuard/WireGuard/UI
parentTable edit: Show/hide 'Exclude Private IPs' instead of enable/disable (diff)
downloadwireguard-apple-90af773fef10f50683eb49c382f00133aedb7387.tar.xz
wireguard-apple-90af773fef10f50683eb49c382f00133aedb7387.zip
Handle cell reuse in showing delete buttons in red
Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to 'WireGuard/WireGuard/UI')
-rw-r--r--WireGuard/WireGuard/UI/iOS/TunnelDetailTableViewController.swift9
-rw-r--r--WireGuard/WireGuard/UI/iOS/TunnelEditTableViewController.swift9
2 files changed, 16 insertions, 2 deletions
diff --git a/WireGuard/WireGuard/UI/iOS/TunnelDetailTableViewController.swift b/WireGuard/WireGuard/UI/iOS/TunnelDetailTableViewController.swift
index 2921ca5..71bdeca 100644
--- a/WireGuard/WireGuard/UI/iOS/TunnelDetailTableViewController.swift
+++ b/WireGuard/WireGuard/UI/iOS/TunnelDetailTableViewController.swift
@@ -198,7 +198,7 @@ extension TunnelDetailTableViewController {
// Delete configuration
let cell = tableView.dequeueReusableCell(withIdentifier: TunnelDetailTableViewButtonCell.id, for: indexPath) as! TunnelDetailTableViewButtonCell
cell.buttonText = "Delete tunnel"
- cell.button.tintColor = UIColor.red
+ cell.hasDestructiveAction = true
cell.onTapped = { [weak self] in
guard let s = self else { return }
s.showConfirmationAlert(message: "Delete this tunnel?", buttonTitle: "Delete", from: cell) { [weak s] in
@@ -336,12 +336,18 @@ class TunnelDetailTableViewButtonCell: UITableViewCell {
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 }
+ }
var onTapped: (() -> Void)? = nil
let button: UIButton
+ var buttonStandardTintColor: UIColor
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
button = UIButton(type: .system)
+ buttonStandardTintColor = button.tintColor
super.init(style: style, reuseIdentifier: reuseIdentifier)
contentView.addSubview(button)
button.translatesAutoresizingMaskIntoConstraints = false
@@ -364,5 +370,6 @@ class TunnelDetailTableViewButtonCell: UITableViewCell {
super.prepareForReuse()
buttonText = ""
onTapped = nil
+ hasDestructiveAction = false
}
}
diff --git a/WireGuard/WireGuard/UI/iOS/TunnelEditTableViewController.swift b/WireGuard/WireGuard/UI/iOS/TunnelEditTableViewController.swift
index c7794e3..17615ab 100644
--- a/WireGuard/WireGuard/UI/iOS/TunnelEditTableViewController.swift
+++ b/WireGuard/WireGuard/UI/iOS/TunnelEditTableViewController.swift
@@ -240,7 +240,7 @@ extension TunnelEditTableViewController {
if (field == .deletePeer) {
let cell = tableView.dequeueReusableCell(withIdentifier: TunnelEditTableViewButtonCell.id, for: indexPath) as! TunnelEditTableViewButtonCell
cell.buttonText = field.rawValue
- cell.button.tintColor = UIColor.red
+ cell.hasDestructiveAction = true
cell.onTapped = { [weak self, weak peerData] in
guard let peerData = peerData else { return }
guard let s = self else { return }
@@ -512,12 +512,18 @@ class TunnelEditTableViewButtonCell: UITableViewCell {
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 }
+ }
var onTapped: (() -> Void)? = nil
let button: UIButton
+ var buttonStandardTintColor: UIColor
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
button = UIButton(type: .system)
+ buttonStandardTintColor = button.tintColor
super.init(style: style, reuseIdentifier: reuseIdentifier)
contentView.addSubview(button)
button.translatesAutoresizingMaskIntoConstraints = false
@@ -540,6 +546,7 @@ class TunnelEditTableViewButtonCell: UITableViewCell {
super.prepareForReuse()
buttonText = ""
onTapped = nil
+ hasDestructiveAction = false
}
}