Skip to content

Commit 3aaafb0

Browse files
mojganiipinkisemils
authored andcommitted
Hide connection details view based on tunnel status
1 parent b402c79 commit 3aaafb0

File tree

3 files changed

+10
-16
lines changed

3 files changed

+10
-16
lines changed

ios/MullvadVPN/View controllers/Tunnel/ConnectionView/ConnectionView.swift

+2-10
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ struct ConnectionView: View {
2929
indicatorsViewModel: indicatorsViewModel,
3030
isExpanded: $isExpanded
3131
)
32-
.showIf(connectionViewModel.showConnectionDetails)
32+
.showIf(connectionViewModel.showsConnectionDetails)
3333

3434
ButtonPanel(viewModel: connectionViewModel, action: action)
3535
.padding(.top, 16)
@@ -38,21 +38,13 @@ struct ConnectionView: View {
3838
.background(BlurView(style: .dark))
3939
.cornerRadius(12)
4040
.padding(EdgeInsets(top: 16, leading: 16, bottom: 24, trailing: 16))
41-
.onReceive(connectionViewModel.$tunnelStatus) { _ in
42-
// Only update expanded state when connections details should be hidden.
43-
// This will contract the view on eg. disconnect, but leave it as-is on
44-
// eg. connect.
45-
if !connectionViewModel.showConnectionDetails {
46-
isExpanded = false
47-
}
48-
}
4941
}
5042
}
5143

5244
extension ConnectionView {
5345
var headerViewBottomPadding: CGFloat {
5446
let hasIndicators = !indicatorsViewModel.chips.isEmpty
55-
let showConnectionDetails = connectionViewModel.showConnectionDetails
47+
let showConnectionDetails = connectionViewModel.showsConnectionDetails
5648

5749
return isExpanded
5850
? showConnectionDetails ? 16 : 0

ios/MullvadVPN/View controllers/Tunnel/ConnectionView/ConnectionViewViewModel.swift

+7-5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class ConnectionViewViewModel: ObservableObject {
3030
@Published private(set) var tunnelStatus: TunnelStatus
3131
@Published var outgoingConnectionInfo: OutgoingConnectionInfo?
3232
@Published var showsActivityIndicator = false
33+
@Published var showsConnectionDetails = false
3334

3435
@Published var relayConstraints: RelayConstraints
3536
let destinationDescriber: DestinationDescribing
@@ -72,24 +73,25 @@ class ConnectionViewViewModel: ObservableObject {
7273

7374
func update(tunnelStatus: TunnelStatus) {
7475
self.tunnelStatus = tunnelStatus
76+
self.showsConnectionDetails = shouldShowConnectionDetails(tunnelStatus)
7577

7678
if !tunnelIsConnected {
7779
outgoingConnectionInfo = nil
7880
}
7981
}
80-
}
8182

82-
extension ConnectionViewViewModel {
83-
var showConnectionDetails: Bool {
83+
private func shouldShowConnectionDetails(_ tunnelStatus: TunnelStatus) -> Bool {
8484
switch tunnelStatus.state {
85-
case .connecting, .reconnecting, .waitingForConnectivity(.noConnection), .negotiatingEphemeralPeer,
85+
case .connecting, .reconnecting, .negotiatingEphemeralPeer,
8686
.connected, .pendingReconnect:
8787
true
88-
case .disconnecting, .disconnected, .waitingForConnectivity(.noNetwork), .error:
88+
case .disconnecting, .disconnected, .waitingForConnectivity, .error:
8989
false
9090
}
9191
}
92+
}
9293

94+
extension ConnectionViewViewModel {
9395
var textColorForSecureLabel: UIColor {
9496
switch tunnelStatus.state {
9597
case .connecting, .reconnecting, .waitingForConnectivity(.noConnection), .negotiatingEphemeralPeer,

ios/MullvadVPN/View controllers/Tunnel/ConnectionView/HeaderView.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ extension ConnectionView {
4747
.foregroundStyle(.white)
4848
.accessibilityIdentifier(AccessibilityIdentifier.relayStatusCollapseButton.asString)
4949
}
50-
.showIf(viewModel.showConnectionDetails)
50+
.showIf(viewModel.showsConnectionDetails)
5151
}
5252
.contentShape(Rectangle())
5353
.onTapGesture {

0 commit comments

Comments
 (0)