-
Notifications
You must be signed in to change notification settings - Fork 339
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the multihop page to the root of the settings page
- Loading branch information
Showing
46 changed files
with
423 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// | ||
// ViewGeometry.swift | ||
// MullvadVPN | ||
// | ||
// Created by Jon Petersson on 2024-11-13. | ||
// Copyright © 2024 Mullvad VPN AB. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
|
||
/// Struct for measuring view size. Typically used in a `.background()`, | ||
/// eg. `.background(ViewGeometry { actualViewSize in [...] }). | ||
struct ViewGeometry: View { | ||
let onSizeChange: (CGSize) -> Void | ||
|
||
var body: some View { | ||
GeometryReader { geometry in | ||
Color.clear | ||
.preference(key: ViewSizeKey.self, value: geometry.size) | ||
.onPreferenceChange(ViewSizeKey.self) { | ||
onSizeChange($0) | ||
} | ||
} | ||
} | ||
} | ||
|
||
private struct ViewSizeKey: PreferenceKey { | ||
static var defaultValue: CGSize = .zero | ||
|
||
static func reduce(value: inout CGSize, nextValue: () -> CGSize) { | ||
value = nextValue() | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
ios/MullvadVPN/Coordinators/Settings/Multihop/SettingsMultihopView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// | ||
// SettingsMultihopView.swift | ||
// MullvadVPN | ||
// | ||
// Created by Andrew Bulhak on 2024-09-23. | ||
// Copyright © 2024 Mullvad VPN AB. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct SettingsMultihopView: View { | ||
@State private var enabled = true | ||
|
||
var didToggleEnabled: ((Bool) -> Void)? | ||
|
||
var body: some View { | ||
ZStack { | ||
VStack(spacing: 24) { | ||
SettingsInfoView( | ||
viewModel: SettingsInfoViewModel( | ||
body: NSLocalizedString( | ||
"SETTINGS_INFO_MULTIHOP", | ||
tableName: "Settings", | ||
value: """ | ||
Multihop routes your traffic into one WireGuard server and out another, making it \ | ||
harder to trace. This results in increased latency but increases anonymity online. | ||
""", | ||
comment: "" | ||
), | ||
image: .multihopIllustration | ||
) | ||
) | ||
|
||
SwitchRowView( | ||
enabled: enabled, | ||
text: NSLocalizedString( | ||
"SETTINGS_SWITCH_MULTIHOP", | ||
tableName: "Settings", | ||
value: "Enable", | ||
comment: "" | ||
), | ||
didToggle: { didToggleEnabled?($0) } | ||
) | ||
|
||
Spacer() | ||
} | ||
.padding(UIMetrics.contentInsets.toEdgeInsets) | ||
} | ||
.background(Color(.secondaryColor)) | ||
.foregroundColor(Color(.primaryTextColor)) | ||
} | ||
} | ||
|
||
#Preview { | ||
SettingsMultihopView { enabled in | ||
print("\(enabled)") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
ios/MullvadVPN/Coordinators/Settings/Views/SettingsInfoView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// | ||
// SettingsInfoView.swift | ||
// MullvadVPN | ||
// | ||
// Created by Jon Petersson on 2024-11-13. | ||
// Copyright © 2024 Mullvad VPN AB. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct SettingsInfoViewModel { | ||
let body: String | ||
let image: ImageResource | ||
} | ||
|
||
struct SettingsInfoView: View { | ||
let viewModel: SettingsInfoViewModel | ||
|
||
var body: some View { | ||
VStack(alignment: .leading, spacing: 16) { | ||
Image(viewModel.image) | ||
.resizable() | ||
.aspectRatio(contentMode: .fit) | ||
Text(viewModel.body) | ||
.font(.subheadline) | ||
.opacity(0.6) | ||
} | ||
} | ||
} | ||
|
||
#Preview { | ||
SettingsInfoView(viewModel: SettingsInfoViewModel( | ||
body: """ | ||
Multihop routes your traffic into one WireGuard server and out another, making it \ | ||
harder to trace. This results in increased latency but increases anonymity online. | ||
""", | ||
image: .multihopIllustration | ||
)) | ||
} |
57 changes: 57 additions & 0 deletions
57
ios/MullvadVPN/Coordinators/Settings/Views/SwitchRowView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// | ||
// SwitchRowView.swift | ||
// MullvadVPN | ||
// | ||
// Created by Jon Petersson on 2024-11-13. | ||
// Copyright © 2024 Mullvad VPN AB. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct SwitchRowView: View { | ||
@State private var enabled: Bool | ||
private let text: String | ||
|
||
let didToggle: (Bool) -> Void | ||
var didTap: (() -> Void)? | ||
|
||
init( | ||
enabled: Bool, | ||
text: String, | ||
didToggle: @escaping ((Bool) -> Void), | ||
didTap: (() -> Void)? = nil | ||
) { | ||
self.enabled = enabled | ||
self.text = text | ||
self.didToggle = didToggle | ||
self.didTap = didTap | ||
} | ||
|
||
var body: some View { | ||
Toggle(isOn: $enabled, label: { | ||
Text(text) | ||
}).onChange(of: enabled, perform: { enabled in | ||
didToggle(enabled) | ||
}) | ||
.toggleStyle(CustomToggleStyle(infoButtonAction: didTap)) | ||
.font(.headline) | ||
.frame(height: UIMetrics.SettingsViewCell.height) | ||
.padding(UIMetrics.SettingsViewCell.layoutMargins) | ||
.background(Color(.primaryColor)) | ||
.foregroundColor(Color(.primaryTextColor)) | ||
.cornerRadius(UIMetrics.SettingsViewCell.cornerRadius) | ||
.accessibilityIdentifier(AccessibilityIdentifier.multihopSwitch.rawValue) | ||
} | ||
} | ||
|
||
#Preview { | ||
SwitchRowView( | ||
enabled: true, | ||
text: "Enable", | ||
didToggle: { enabled in | ||
print("\(enabled)") | ||
}, didTap: { | ||
print("Tapped") | ||
} | ||
) | ||
} |
Oops, something went wrong.