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"
}
},
{
"identity" : "flagkit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/madebybowtie/FlagKit",
"state" : {
"revision" : "f12111d91902d23fd1d9cc7ad9198030b049795d",
"version" : "2.4.0"
}
},
{
"identity" : "generic-json-swift",
"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", revision: "ea39fa396e98cfd2b9a235f0a801aaf03a37e30a"),
// .package(path: "../../../passepartoutkit-source-wireguard-go"),
.package(url: "https://github.com/Cocoanetics/Kvitto", from: "1.0.0"),
.package(url: "https://github.com/madebybowtie/FlagKit", from: "2.3.0")
.package(url: "https://github.com/Cocoanetics/Kvitto", from: "1.0.0")
],
targets: [
// Targets are the basic building blocks of a package, defining a module or a test suite.
@ -86,7 +85,6 @@ let package = Package(
"AppDataProfiles",
"AppDataProviders",
"AppLibrary",
"FlagKit",
"Kvitto",
"UtilsLibrary"
],

View File

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

View File

@ -2,10 +2,6 @@
"author": "Davide De Rosa",
"licenses": [
{
"name": "FlagKit",
"licenseName": "MIT",
"licenseURL": "https://raw.githubusercontent.com/madebybowtie/FlagKit/master/LICENSE"
}, {
"name": "GenericJSON",
"licenseName": "MIT",
"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 {
ThemeCountryFlag(
code: provider.entity?.header.countryCode,
provider.entity?.header.countryCode,
placeholderTip: Strings.Errors.App.Passepartout.missingProviderEntity,
countryTip: {
$0.localizedAsRegionCode

View File

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

View File

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

View File

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

View File

@ -46,3 +46,19 @@ extension String {
.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))
}
}