Skip to content

Commit 58f13dd

Browse files
committed
Fix connection view background in iOS15
1 parent 0072998 commit 58f13dd

File tree

4 files changed

+21
-59
lines changed

4 files changed

+21
-59
lines changed

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

+17-30
Original file line numberDiff line numberDiff line change
@@ -15,49 +15,36 @@ struct ConnectionView: View {
1515
@State private(set) var isExpanded = false
1616

1717
var action: ButtonPanel.Action?
18-
var onContentUpdate: (() -> Void)?
1918

2019
var body: some View {
2120
Spacer()
2221
.accessibilityIdentifier(AccessibilityIdentifier.connectionView.asString)
2322

24-
VStack(spacing: 22) {
25-
ZStack {
26-
BlurView(style: .dark)
23+
VStack(alignment: .leading, spacing: 0) {
24+
HeaderView(viewModel: connectionViewModel, isExpanded: $isExpanded)
25+
.padding(.bottom, headerViewBottomPadding)
2726

28-
VStack(alignment: .leading, spacing: 0) {
29-
HeaderView(viewModel: connectionViewModel, isExpanded: $isExpanded)
30-
.padding(.bottom, headerViewBottomPadding)
27+
DetailsContainer(
28+
connectionViewModel: connectionViewModel,
29+
indicatorsViewModel: indicatorsViewModel,
30+
isExpanded: $isExpanded
31+
)
32+
.showIf(connectionViewModel.showConnectionDetails)
3133

32-
DetailsContainer(
33-
connectionViewModel: connectionViewModel,
34-
indicatorsViewModel: indicatorsViewModel,
35-
isExpanded: $isExpanded
36-
)
37-
.showIf(connectionViewModel.showConnectionDetails)
38-
39-
ButtonPanel(viewModel: connectionViewModel, action: action)
40-
.padding(.top, 16)
41-
}
42-
.padding(16)
43-
}
44-
.cornerRadius(12)
45-
.padding(16)
34+
ButtonPanel(viewModel: connectionViewModel, action: action)
35+
.padding(.top, 16)
4636
}
47-
.padding(.bottom, 8) // Some spacing to avoid overlap with the map legal link.
48-
.onChange(of: isExpanded) { _ in
49-
onContentUpdate?()
50-
}
51-
.onReceive(connectionViewModel.combinedState) { _, _ in
37+
.padding(16)
38+
.background(BlurView(style: .dark))
39+
.cornerRadius(12)
40+
.padding(EdgeInsets(top: 16, leading: 16, bottom: 24, trailing: 16))
41+
.onReceive(connectionViewModel.$tunnelStatus) { _ in
5242
// Only update expanded state when connections details should be hidden.
5343
// This will contract the view on eg. disconnect, but leave it as-is on
5444
// eg. connect.
5545
if !connectionViewModel.showConnectionDetails {
5646
isExpanded = false
57-
return
5847
}
59-
60-
onContentUpdate?()
6148
}
6249
}
6350
}
@@ -68,7 +55,7 @@ extension ConnectionView {
6855
let showConnectionDetails = connectionViewModel.showConnectionDetails
6956

7057
return isExpanded
71-
? 16
58+
? showConnectionDetails ? 16 : 0
7259
: hasIndicators && showConnectionDetails ? 16 : 0
7360
}
7461
}

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

-8
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,6 @@ class ConnectionViewViewModel: ObservableObject {
2626

2727
@Published private(set) var tunnelStatus: TunnelStatus
2828
@Published var outgoingConnectionInfo: OutgoingConnectionInfo?
29-
@Published var showsActivityIndicator = false
30-
31-
var combinedState: Publishers.CombineLatest<
32-
Published<TunnelStatus>.Publisher,
33-
Published<Bool>.Publisher
34-
> {
35-
$tunnelStatus.combineLatest($showsActivityIndicator)
36-
}
3729

3830
var tunnelIsConnected: Bool {
3931
if case .connected = tunnelStatus.state {

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

+2-16
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,11 @@ class TunnelViewController: UIViewController, RootContainment {
6767
)
6868

6969
connectionView = ConnectionView(
70-
connectionViewModel: self.connectionViewViewModel,
71-
indicatorsViewModel: self.indicatorsViewViewModel
70+
connectionViewModel: connectionViewViewModel,
71+
indicatorsViewModel: indicatorsViewViewModel
7272
)
7373

7474
super.init(nibName: nil, bundle: nil)
75-
76-
// When content size is updated in SwiftUI we need to explicitly tell UIKit to
77-
// update its view size. This is not necessary on iOS 16 where we can set
78-
// hostingController.sizingOptions instead.
79-
connectionView.onContentUpdate = { [weak self] in
80-
self?.connectionController?.view.setNeedsUpdateConstraints()
81-
}
8275
}
8376

8477
required init?(coder: NSCoder) {
@@ -168,20 +161,16 @@ class TunnelViewController: UIViewController, RootContainment {
168161
case let .connecting(tunnelRelays, _, _):
169162
mapViewController.removeLocationMarker()
170163
mapViewController.setCenter(tunnelRelays?.exit.location.geoCoordinate, animated: animated)
171-
connectionViewViewModel.showsActivityIndicator = true
172164
activityIndicator.startAnimating()
173165

174166
case let .reconnecting(tunnelRelays, _, _), let .negotiatingEphemeralPeer(tunnelRelays, _, _, _):
175167
activityIndicator.startAnimating()
176168
mapViewController.removeLocationMarker()
177169
mapViewController.setCenter(tunnelRelays.exit.location.geoCoordinate, animated: animated)
178-
connectionViewViewModel.showsActivityIndicator = true
179170

180171
case let .connected(tunnelRelays, _, _):
181172
let center = tunnelRelays.exit.location.geoCoordinate
182173
mapViewController.setCenter(center, animated: animated) {
183-
self.connectionViewViewModel.showsActivityIndicator = false
184-
185174
// Connection can change during animation, so make sure we're still connected before adding marker.
186175
if case .connected = self.tunnelState {
187176
self.mapViewController.addLocationMarker(coordinate: center)
@@ -192,18 +181,15 @@ class TunnelViewController: UIViewController, RootContainment {
192181
case .pendingReconnect:
193182
activityIndicator.startAnimating()
194183
mapViewController.removeLocationMarker()
195-
connectionViewViewModel.showsActivityIndicator = true
196184

197185
case .waitingForConnectivity, .error:
198186
activityIndicator.stopAnimating()
199187
mapViewController.removeLocationMarker()
200-
connectionViewViewModel.showsActivityIndicator = false
201188

202189
case .disconnected, .disconnecting:
203190
activityIndicator.stopAnimating()
204191
mapViewController.removeLocationMarker()
205192
mapViewController.setCenter(nil, animated: animated)
206-
connectionViewViewModel.showsActivityIndicator = false
207193
}
208194
}
209195

ios/MullvadVPN/Views/BlurView.swift

+2-5
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ struct BlurView: View {
1313
var style: UIBlurEffect.Style
1414

1515
var body: some View {
16-
Spacer()
17-
.overlay {
18-
VisualEffectView(effect: UIBlurEffect(style: style))
19-
.opacity(0.8)
20-
}
16+
VisualEffectView(effect: UIBlurEffect(style: style))
17+
.opacity(0.8)
2118
}
2219
}

0 commit comments

Comments
 (0)