-
Notifications
You must be signed in to change notification settings - Fork 387
/
Copy pathDetailsView.swift
80 lines (74 loc) · 3 KB
/
DetailsView.swift
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
73
74
75
76
77
78
79
80
//
// DetailsView.swift
// MullvadVPN
//
// Created by Andrew Bulhak on 2025-01-03.
// Copyright © 2025 Mullvad VPN AB. All rights reserved.
//
import SwiftUI
extension ConnectionView {
internal struct DetailsView: View {
@ObservedObject var viewModel: ConnectionViewViewModel
@State private var columnWidth: CGFloat = 0
var body: some View {
VStack(alignment: .leading, spacing: 8) {
HStack {
Text(LocalizedStringKey("Connection details"))
.font(.footnote.weight(.semibold))
.foregroundStyle(UIColor.primaryTextColor.color.opacity(0.6))
Spacer()
}
VStack(alignment: .leading, spacing: 0) {
if let inAddress = viewModel.inAddress {
connectionDetailRow(
title: LocalizedStringKey("In"),
value: inAddress,
accessibilityId: .connectionPanelInAddressRow
)
}
if viewModel.tunnelIsConnected {
if let outAddressIpv4 = viewModel.outAddressIpv4 {
connectionDetailRow(
title: LocalizedStringKey("Out IPv4"),
value: outAddressIpv4,
accessibilityId: .connectionPanelOutAddressRow
)
}
if let outAddressIpv6 = viewModel.outAddressIpv6 {
connectionDetailRow(
title: LocalizedStringKey("Out IPv6"),
value: outAddressIpv6,
accessibilityId: .connectionPanelOutIpv6AddressRow
)
}
}
}
}
.animation(.default, value: viewModel.inAddress)
.animation(.default, value: viewModel.tunnelIsConnected)
}
@ViewBuilder
private func connectionDetailRow(
title: LocalizedStringKey,
value: String,
accessibilityId: AccessibilityIdentifier
) -> some View {
HStack(alignment: .top, spacing: 8) {
Text(title)
.font(.subheadline)
.foregroundStyle(UIColor.primaryTextColor.color.opacity(0.6))
.frame(minWidth: columnWidth, alignment: .leading)
.sizeOfView { columnWidth = max(columnWidth, $0.width) }
Text(value)
.font(.subheadline)
.foregroundStyle(UIColor.primaryTextColor.color)
.accessibilityIdentifier(accessibilityId.asString)
}
}
}
}
#Preview {
ConnectionViewComponentPreview(showIndicators: true) { _, vm, _ in
ConnectionView.DetailsView(viewModel: vm)
}
}