-
Notifications
You must be signed in to change notification settings - Fork 392
/
Copy pathConnectionView.swift
70 lines (58 loc) · 2.29 KB
/
ConnectionView.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
//
// ConnectionView.swift
// MullvadVPN
//
// Created by Jon Petersson on 2024-12-03.
// Copyright © 2025 Mullvad VPN AB. All rights reserved.
//
import SwiftUI
struct ConnectionView: View {
@ObservedObject var connectionViewModel: ConnectionViewViewModel
@ObservedObject var indicatorsViewModel: FeatureIndicatorsViewModel
@State private(set) var isExpanded = false
var action: ButtonPanel.Action?
var body: some View {
Spacer()
.accessibilityIdentifier(AccessibilityIdentifier.connectionView.asString)
VStack(alignment: .leading, spacing: 0) {
HeaderView(viewModel: connectionViewModel, isExpanded: $isExpanded)
.padding(.bottom, headerViewBottomPadding)
DetailsContainer(
connectionViewModel: connectionViewModel,
indicatorsViewModel: indicatorsViewModel,
isExpanded: $isExpanded
)
.showIf(connectionViewModel.showsConnectionDetails)
ButtonPanel(viewModel: connectionViewModel, action: action)
.padding(.top, 16)
}
.padding(16)
.background(BlurView(style: .dark))
.cornerRadius(12)
.padding(EdgeInsets(top: 16, leading: 16, bottom: 24, trailing: 16))
.onReceive(connectionViewModel.combinedState) { _ in
if !connectionViewModel.showsConnectionDetails {
isExpanded = false
}
}
}
}
extension ConnectionView {
var headerViewBottomPadding: CGFloat {
let hasIndicators = !indicatorsViewModel.chips.isEmpty
let showConnectionDetails = connectionViewModel.showsConnectionDetails
return isExpanded
? showConnectionDetails ? 16 : 0
: hasIndicators && showConnectionDetails ? 16 : 0
}
}
#Preview("ConnectionView (Indicators)") {
ConnectionViewComponentPreview(showIndicators: true, isExpanded: true) { indicatorModel, viewModel, _ in
ConnectionView(connectionViewModel: viewModel, indicatorsViewModel: indicatorModel)
}
}
#Preview("ConnectionView (No indicators)") {
ConnectionViewComponentPreview(showIndicators: false, isExpanded: true) { indicatorModel, viewModel, _ in
ConnectionView(connectionViewModel: viewModel, indicatorsViewModel: indicatorModel)
}
}