Render country flags with Emojis (#787)

Revert FlagKit just introduced in #786
This commit is contained in:
Davide 2024-10-31 01:15:07 +01:00 committed by GitHub
parent dcdb03a735
commit 80dd6dc779
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 36 additions and 49 deletions

View File

@ -9,15 +9,6 @@
"version" : "1.7.18" "version" : "1.7.18"
} }
}, },
{
"identity" : "flagkit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/madebybowtie/FlagKit",
"state" : {
"revision" : "f12111d91902d23fd1d9cc7ad9198030b049795d",
"version" : "2.4.0"
}
},
{ {
"identity" : "generic-json-swift", "identity" : "generic-json-swift",
"kind" : "remoteSourceControl", "kind" : "remoteSourceControl",

View File

@ -44,8 +44,7 @@ let package = Package(
.package(url: "git@github.com:passepartoutvpn/passepartoutkit-source-wireguard-go", from: "0.9.1"), .package(url: "git@github.com:passepartoutvpn/passepartoutkit-source-wireguard-go", from: "0.9.1"),
// .package(url: "git@github.com:passepartoutvpn/passepartoutkit-source-wireguard-go", revision: "ea39fa396e98cfd2b9a235f0a801aaf03a37e30a"), // .package(url: "git@github.com:passepartoutvpn/passepartoutkit-source-wireguard-go", revision: "ea39fa396e98cfd2b9a235f0a801aaf03a37e30a"),
// .package(path: "../../../passepartoutkit-source-wireguard-go"), // .package(path: "../../../passepartoutkit-source-wireguard-go"),
.package(url: "https://github.com/Cocoanetics/Kvitto", from: "1.0.0"), .package(url: "https://github.com/Cocoanetics/Kvitto", from: "1.0.0")
.package(url: "https://github.com/madebybowtie/FlagKit", from: "2.3.0")
], ],
targets: [ targets: [
// Targets are the basic building blocks of a package, defining a module or a test suite. // Targets are the basic building blocks of a package, defining a module or a test suite.
@ -86,7 +85,6 @@ let package = Package(
"AppDataProfiles", "AppDataProfiles",
"AppDataProviders", "AppDataProviders",
"AppLibrary", "AppLibrary",
"FlagKit",
"Kvitto", "Kvitto",
"UtilsLibrary" "UtilsLibrary"
], ],

View File

@ -24,7 +24,6 @@
// //
import CommonLibrary import CommonLibrary
import FlagKit
#if canImport(LocalAuthentication) #if canImport(LocalAuthentication)
import LocalAuthentication import LocalAuthentication
#endif #endif
@ -454,35 +453,28 @@ public struct ThemeCountryFlag: View {
private let countryTip: ((String) -> String?)? private let countryTip: ((String) -> String?)?
public init(code: String?, placeholderTip: String? = nil, countryTip: ((String) -> String?)? = nil) { public init(_ code: String?, placeholderTip: String? = nil, countryTip: ((String) -> String?)? = nil) {
self.code = code self.code = code
self.placeholderTip = placeholderTip self.placeholderTip = placeholderTip
self.countryTip = countryTip self.countryTip = countryTip
} }
public var body: some View { public var body: some View {
Group { if let code {
if let code { text(withString: code.asCountryCodeEmoji, tip: countryTip?(code))
let image = Image(code, bundle: FlagKit.assetBundle) } else {
.resizable() text(withString: "🌐", tip: placeholderTip)
}
if let tip = countryTip?(code) { }
image
.help(tip) @ViewBuilder
} else { private func text(withString string: String, tip: String?) -> some View {
image if let tip {
} Text(verbatim: string)
} else { .help(tip)
let image = Image(systemName: "globe") } else {
if let placeholderTip { Text(verbatim: string)
image
.help(placeholderTip)
} else {
image
}
}
} }
.frame(width: 20, height: 15)
} }
} }

View File

@ -2,10 +2,6 @@
"author": "Davide De Rosa", "author": "Davide De Rosa",
"licenses": [ "licenses": [
{ {
"name": "FlagKit",
"licenseName": "MIT",
"licenseURL": "https://raw.githubusercontent.com/madebybowtie/FlagKit/master/LICENSE"
}, {
"name": "GenericJSON", "name": "GenericJSON",
"licenseName": "MIT", "licenseName": "MIT",
"licenseURL": "https://raw.githubusercontent.com/iwill/generic-json-swift/master/LICENSE" "licenseURL": "https://raw.githubusercontent.com/iwill/generic-json-swift/master/LICENSE"

View File

@ -158,7 +158,7 @@ private struct ProviderCountryFlag: View {
var body: some View { var body: some View {
ThemeCountryFlag( ThemeCountryFlag(
code: provider.entity?.header.countryCode, provider.entity?.header.countryCode,
placeholderTip: Strings.Errors.App.Passepartout.missingProviderEntity, placeholderTip: Strings.Errors.App.Passepartout.missingProviderEntity,
countryTip: { countryTip: {
$0.localizedAsRegionCode $0.localizedAsRegionCode

View File

@ -81,7 +81,7 @@ private extension VPNFiltersView {
Text(Strings.Global.any) Text(Strings.Global.any)
.tag(nil as String?) .tag(nil as String?)
ForEach(model.countries, id: \.code) { ForEach(model.countries, id: \.code) {
Text($0.description) Text("\($0.code.asCountryCodeEmoji) \($0.description)")
.tag($0.code as String?) .tag($0.code as String?)
} }
} }

View File

@ -164,10 +164,7 @@ private extension VPNProviderServerView.ServersSubview {
DisclosureGroup { DisclosureGroup {
ForEach(servers, id: \.id, content: serverView) ForEach(servers, id: \.id, content: serverView)
} label: { } label: {
HStack { Text("\(code.asCountryCodeEmoji) \(code.localizedAsRegionCode ?? code)")
ThemeCountryFlag(code: code)
Text(code.localizedAsRegionCode ?? code)
}
} }
} }
} }

View File

@ -71,11 +71,8 @@ extension VPNProviderServerView {
.width(10.0) .width(10.0)
TableColumn(Strings.Global.region) { server in TableColumn(Strings.Global.region) { server in
HStack { Text("\(server.provider.countryCode.asCountryCodeEmoji) \(server.region)")
ThemeCountryFlag(code: server.provider.countryCode)
Text(server.region)
.help(server.region) .help(server.region)
}
} }
TableColumn(Strings.Global.address, value: \.address) TableColumn(Strings.Global.address, value: \.address)

View File

@ -46,3 +46,19 @@ extension String {
.capitalized .capitalized
} }
} }
extension String {
public var asCountryCodeEmoji: String {
Self.emoji(forCountryCode: self)
}
public static func emoji(forCountryCode countryCode: String) -> String {
let points = countryCode
.unicodeScalars
.compactMap {
UnicodeScalar(127397 + $0.value)
}
return String(String.UnicodeScalarView(points))
}
}