summaryrefslogtreecommitdiffhomepage
path: root/ios/MullvadVPN/View controllers/Settings/SelectableSettingsDetailsCell.swift
blob: bd5fe94804806835a02856e3e0c73d97080ca404 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//
//  SelectableSettingsDetailsCell.swift
//  MullvadVPN
//
//  Created by Jon Petersson on 2024-10-14.
//  Copyright © 2025 Mullvad VPN AB. All rights reserved.
//

import UIKit

class SelectableSettingsDetailsCell: SelectableSettingsCell {
    let viewContainer = UIView()

    var buttonAction: (() -> Void)?

    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: .subtitle, reuseIdentifier: reuseIdentifier)

        let actionButton = IncreasedHitButton(type: .system)
        var actionButtonConfiguration = actionButton.configuration ?? .plain()
        actionButtonConfiguration.image = UIImage(systemName: "ellipsis")?
            .withRenderingMode(.alwaysOriginal)
            .withTintColor(.white)
        actionButton.configuration = actionButtonConfiguration
        actionButton.setAccessibilityIdentifier(.openPortSelectorMenuButton)

        actionButton.addTarget(
            self,
            action: #selector(didPressActionButton),
            for: .touchUpInside
        )

        let separatorView = UIView()
        separatorView.backgroundColor = .secondaryColor

        viewContainer.addConstrainedSubviews([separatorView, actionButton]) {
            separatorView.leadingAnchor.constraint(equalTo: viewContainer.leadingAnchor, constant: 16)
            separatorView.centerYAnchor.constraint(equalTo: viewContainer.centerYAnchor)
            separatorView.heightAnchor.constraint(equalToConstant: UIMetrics.SettingsCell.verticalDividerHeight)
            separatorView.widthAnchor.constraint(equalToConstant: 1)

            actionButton.pinEdgesToSuperview(.all().excluding(.leading))
            actionButton.leadingAnchor.constraint(equalTo: separatorView.trailingAnchor)
            actionButton.widthAnchor.constraint(equalToConstant: UIMetrics.SettingsCell.detailsButtonSize)
        }

        setViewContainer()
    }

    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    override func prepareForReuse() {
        super.prepareForReuse()
        setViewContainer()
    }

    private func setViewContainer() {
        setTrailingView { superview in
            superview.addConstrainedSubviews([viewContainer]) {
                viewContainer.pinEdgesToSuperview()
            }
        }
    }

    // MARK: - Actions

    @objc private func didPressActionButton() {
        buttonAction?()
    }
}