-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhoneNumberKitSwiftUIDemoView.swift
More file actions
67 lines (59 loc) · 2.36 KB
/
Copy pathPhoneNumberKitSwiftUIDemoView.swift
File metadata and controls
67 lines (59 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import SwiftUI
import PhoneNumberKitSwiftUI
public struct PhoneNumberKitSwiftUIDemoView: View {
@State private var store = PhoneNumberStore(
withPrefix: true,
withPrefixPrefill: true,
withFlag: true,
withExamplePlaceholder: true
)
private var isClearDisabled: Bool {
store.text.isEmpty && store.rawDigits.isEmpty
}
public init() {}
public var body: some View {
NavigationStack {
Form {
Section {
PhoneNumberField(store: store, title: "Phone number")
} header: {
Text("Phone Number")
} footer: {
Text(store.isValidNumber ? "Valid phone number" : "Enter a valid phone number")
.font(.footnote)
.foregroundStyle(store.isValidNumber ? .green : .secondary)
}
Section("Controls") {
Toggle("Show country picker flag", isOn: $store.withFlag)
Toggle("Use international prefix", isOn: $store.withPrefix)
Toggle("Prefill prefix on focus", isOn: $store.withPrefixPrefill)
Toggle("Show example placeholder", isOn: $store.withExamplePlaceholder)
}
Section("Current value") {
LabeledContent("Region", value: store.currentRegion)
LabeledContent("Formatted", value: store.text.isEmpty ? "Empty" : store.text)
LabeledContent("Raw digits", value: store.rawDigits.isEmpty ? "Empty" : store.rawDigits)
LabeledContent("National", value: store.nationalNumber.isEmpty ? "Empty" : store.nationalNumber)
}
}
.navigationTitle("PhoneNumberKitSwiftUI")
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .topBarLeading) {
Button("Demo") {
store.setExampleNumber()
}
}
ToolbarItem(placement: .topBarTrailing) {
Button("Clear") {
store.setProgrammaticRawDigits("")
}
.disabled(isClearDisabled)
}
}
}
}
}
#Preview {
PhoneNumberKitSwiftUIDemoView()
}