Skip to content

Commit 662b0a5

Browse files
authored
feat: Enabling dialling code picker. (#21)
1 parent b5970c2 commit 662b0a5

File tree

2 files changed

+7
-35
lines changed

2 files changed

+7
-35
lines changed

Sources/Authenticator/Utilities/RegionUtils.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ struct Region: Equatable, Hashable {
1717
self.name = name
1818
self.code = code
1919
self.callingCode = callingCode
20-
let base: UInt32 = 127397
20+
let base = UnicodeScalar("🇦").value - UnicodeScalar("A").value
2121
let scalarView = String.UnicodeScalarView(code.unicodeScalars.compactMap {
2222
Unicode.Scalar(base + $0.value)
2323
})

Sources/Authenticator/Views/Primitives/PhoneNumberField.swift

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -159,39 +159,6 @@ struct CallingCodeField: View {
159159
private let maxCallingCodeLength = 4
160160

161161
var body: some View {
162-
SwiftUI.TextField(
163-
"authenticator.field.diallingCode.placeholder".localized(),
164-
text: $callingCode
165-
)
166-
.focused($isFocused)
167-
.onChange(of: callingCode) { text in
168-
if text.isEmpty {
169-
callingCode = "+"
170-
} else if !text.hasPrefix("+") {
171-
var updated = text
172-
updated.removeAll(where: { $0 == "+" })
173-
callingCode = "+\(updated)"
174-
} else if text.count > maxCallingCodeLength {
175-
callingCode = String(text.prefix(maxCallingCodeLength))
176-
}
177-
}
178-
.onChange(of: isFocused) { isFocused in
179-
if !isFocused, callingCode == "+" {
180-
callingCode = defaultCallingCode
181-
}
182-
}
183-
.multilineTextAlignment(.center)
184-
.accessibilityLabel(Text(
185-
"authenticator.field.diallingCode.label".localized()
186-
))
187-
.textFieldStyle(.plain)
188-
.frame(width: 55)
189-
#if os(iOS)
190-
.keyboardType(.numberPad)
191-
#endif
192-
}
193-
194-
private var callingCodePicker: some View {
195162
SwiftUI.Button(
196163
action: {
197164
isShowingList = true
@@ -211,6 +178,10 @@ struct CallingCodeField: View {
211178
allRegionsContent
212179
}
213180
}
181+
.accessibilityLabel(Text(
182+
"authenticator.field.diallingCode.label".localized()
183+
))
184+
.frame(width: 55)
214185
}
215186

216187
private var allRegionsContent: some View {
@@ -253,7 +224,8 @@ struct CallingCodeField: View {
253224
}
254225
)
255226
.buttonStyle(.borderless)
256-
.accessibilityLabel(Text(region.name))
227+
.accessibilityLabel(Text("\(region.name), \(region.callingCode)"))
228+
.accessibilityRemoveTraits(.isButton)
257229
}
258230
}
259231
.foregroundColor(theme.colors.foreground.primary)

0 commit comments

Comments
 (0)