-
Notifications
You must be signed in to change notification settings - Fork 356
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
379 additions
and
1 deletion.
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
88 changes: 88 additions & 0 deletions
88
ios/MullvadVPN/View controllers/Tunnel/FeatureIndicators/ChipFeatures.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,88 @@ | ||
// | ||
// ChipFeatures.swift | ||
// MullvadVPN | ||
// | ||
// Created by Mojgan on 2024-12-06. | ||
// Copyright © 2024 Mullvad VPN AB. All rights reserved. | ||
// | ||
import Foundation | ||
import MullvadSettings | ||
import SwiftUI | ||
|
||
protocol ChipFeature { | ||
var isEnabled: Bool { get } | ||
var name: LocalizedStringKey { get } | ||
} | ||
|
||
struct DaitaFeature: ChipFeature { | ||
let settings: LatestTunnelSettings | ||
|
||
var isEnabled: Bool { | ||
settings.daita.daitaState.isEnabled | ||
} | ||
|
||
var name: LocalizedStringKey { | ||
LocalizedStringKey("DAITA") | ||
} | ||
} | ||
|
||
struct QuantumResistanceFeature: ChipFeature { | ||
let settings: LatestTunnelSettings | ||
var isEnabled: Bool { | ||
settings.tunnelQuantumResistance.isEnabled | ||
} | ||
|
||
var name: LocalizedStringKey { | ||
LocalizedStringKey("Quantum resistance") | ||
} | ||
} | ||
|
||
struct MultihopFeature: ChipFeature { | ||
let settings: LatestTunnelSettings | ||
var isEnabled: Bool { | ||
settings.tunnelMultihopState.isEnabled | ||
} | ||
|
||
var name: LocalizedStringKey { | ||
LocalizedStringKey("Multihop") | ||
} | ||
} | ||
|
||
struct ObfuscationFeature: ChipFeature { | ||
let settings: LatestTunnelSettings | ||
|
||
var isEnabled: Bool { | ||
settings.wireGuardObfuscation.state.isEnabled | ||
} | ||
|
||
var name: LocalizedStringKey { | ||
LocalizedStringKey("Obfuscation") | ||
} | ||
} | ||
|
||
struct DNSFeature: ChipFeature { | ||
let settings: LatestTunnelSettings | ||
|
||
var isEnabled: Bool { | ||
settings.dnsSettings.enableCustomDNS || !settings.dnsSettings.blockingOptions.isEmpty | ||
} | ||
|
||
var name: LocalizedStringKey { | ||
if !settings.dnsSettings.blockingOptions.isEmpty { | ||
return LocalizedStringKey("DNS content blockers") | ||
} | ||
return LocalizedStringKey("Custom DNS") | ||
} | ||
} | ||
|
||
struct IPOverrideFeature: ChipFeature { | ||
let repository: IPOverrideRepositoryProtocol | ||
|
||
var isEnabled: Bool { | ||
!repository.fetchAll().isEmpty | ||
} | ||
|
||
var name: LocalizedStringKey { | ||
LocalizedStringKey("Server IP override") | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
ios/MullvadVPN/View controllers/Tunnel/FeatureIndicators/ChipsView/ChipContainerView.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,75 @@ | ||
// | ||
// ChipContainerView.swift | ||
// MullvadVPN | ||
// | ||
// Created by Mojgan on 2024-12-05. | ||
// Copyright © 2024 Mullvad VPN AB. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import SwiftUI | ||
struct ChipContainerView<ViewModel>: View where ViewModel: ChipViewModelProtocol { | ||
@ObservedObject var viewModel: ViewModel | ||
|
||
var body: some View { | ||
GeometryReader { geo in | ||
let containerWidth = geo.size.width | ||
let chipsPerLine = 2 | ||
if viewModel.isExpanded { | ||
ZStack(alignment: .topLeading) { | ||
createChipViews(chips: viewModel.chips, containerWidth: containerWidth) | ||
} | ||
} else { | ||
HStack { | ||
createChipViews(chips: Array(viewModel.chips.prefix(chipsPerLine)), containerWidth: containerWidth) | ||
if viewModel.chips.count > chipsPerLine { | ||
Text(LocalizedStringKey("\(viewModel.chips.count - chipsPerLine) more...")) | ||
.font(.subheadline) | ||
.lineLimit(1) | ||
.foregroundStyle(UIColor.primaryTextColor.color) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
private func createChipViews(chips: [ChipModel], containerWidth: CGFloat) -> some View { | ||
var width = CGFloat.zero | ||
var height = CGFloat.zero | ||
|
||
return ForEach(chips) { data in | ||
ChipView(item: data) | ||
.padding(EdgeInsets(top: 6, leading: 0, bottom: 6, trailing: 8)) | ||
.alignmentGuide(.leading) { dimension in | ||
if abs(width - dimension.width) > containerWidth { | ||
width = 0 | ||
height -= dimension.height | ||
} | ||
let result = width | ||
if data.id == viewModel.chips.last!.id { | ||
width = 0 | ||
} else { | ||
width -= dimension.width | ||
} | ||
return result | ||
} | ||
.alignmentGuide(.top) { _ in | ||
let result = height | ||
if data.id == viewModel.chips.last!.id { | ||
height = 0 | ||
} | ||
return result | ||
} | ||
} | ||
} | ||
} | ||
|
||
#Preview("Normal") { | ||
ChipContainerView(viewModel: FeaturesIndicatoresMockViewModel()) | ||
.background(UIColor.secondaryColor.color) | ||
} | ||
|
||
#Preview("Expanded") { | ||
ChipContainerView(viewModel: FeaturesIndicatoresMockViewModel(isExpanded: true)) | ||
.background(UIColor.secondaryColor.color) | ||
} |
15 changes: 15 additions & 0 deletions
15
ios/MullvadVPN/View controllers/Tunnel/FeatureIndicators/ChipsView/ChipModel.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,15 @@ | ||
// | ||
// FeatureChipModel.swift | ||
// MullvadVPN | ||
// | ||
// Created by Mojgan on 2024-12-05. | ||
// Copyright © 2024 Mullvad VPN AB. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import SwiftUI | ||
|
||
struct ChipModel: Identifiable { | ||
let id = UUID() | ||
let name: LocalizedStringKey | ||
} |
40 changes: 40 additions & 0 deletions
40
ios/MullvadVPN/View controllers/Tunnel/FeatureIndicators/ChipsView/ChipView.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,40 @@ | ||
// | ||
// FeatureChipView.swift | ||
// MullvadVPN | ||
// | ||
// Created by Mojgan on 2024-12-05. | ||
// Copyright © 2024 Mullvad VPN AB. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct ChipView: View { | ||
let item: ChipModel | ||
var body: some View { | ||
Text(item.name) | ||
.font(.subheadline) | ||
.lineLimit(1) | ||
.foregroundStyle(UIColor.primaryTextColor.color) | ||
.padding(.horizontal, 8) | ||
.padding(.vertical, 4) | ||
.background( | ||
RoundedRectangle(cornerRadius: 8.0) | ||
.stroke( | ||
UIColor.primaryColor.color, | ||
lineWidth: 1 | ||
) | ||
.background( | ||
RoundedRectangle(cornerRadius: 8.0) | ||
.fill(UIColor.secondaryColor.color) | ||
) | ||
) | ||
} | ||
} | ||
|
||
#Preview { | ||
ZStack { | ||
ChipView(item: ChipModel(name: LocalizedStringKey("Example"))) | ||
} | ||
.frame(maxWidth: .infinity, maxHeight: .infinity) | ||
.background(UIColor.secondaryColor.color) | ||
} |
31 changes: 31 additions & 0 deletions
31
...ullvadVPN/View controllers/Tunnel/FeatureIndicators/ChipsView/ChipViewModelProtocol.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,31 @@ | ||
// | ||
// ChipViewModelProtocol.swift | ||
// MullvadVPN | ||
// | ||
// Created by Mojgan on 2024-12-05. | ||
// Copyright © 2024 Mullvad VPN AB. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
protocol ChipViewModelProtocol: ObservableObject { | ||
var chips: [ChipModel] { get } | ||
var isExpanded: Bool { get set } | ||
} | ||
|
||
class FeaturesIndicatoresMockViewModel: ChipViewModelProtocol { | ||
@Published var chips: [ChipModel] = [ | ||
ChipModel(name: LocalizedStringKey("DAITA")), | ||
ChipModel(name: LocalizedStringKey("Obfuscation")), | ||
ChipModel(name: LocalizedStringKey("Quantum resistance")), | ||
ChipModel(name: LocalizedStringKey("Multihop")), | ||
ChipModel(name: LocalizedStringKey("DNS content blockers")), | ||
ChipModel(name: LocalizedStringKey("Custom DNS")), | ||
ChipModel(name: LocalizedStringKey("Server IP override")), | ||
] | ||
|
||
@Published var isExpanded: Bool | ||
|
||
init(isExpanded: Bool = false) { | ||
self.isExpanded = isExpanded | ||
} | ||
} |
Oops, something went wrong.