I have an app I've been working on for a while that is all SwiftUI and runs on macOS, iOS, and iPadOS. One feature is a simple address lookup that allows the user to either enter an address or do a search in their Contacts app. The problem is, while a search works fine, and if you have a keyboard, you can hit tab and enter a first name, etc. going between fields in the SwiftUI view, you cannot use any pointer to select any fields on in the view. The following code is the Swift View.
var body: some View {
NavigationView {
GeometryReader { geomtry in
VStack {
TextField("Address Line 1", text: $addressLine1)
.customTextField()
Spacer()
}
ContactPicker(showPicker: $showPicker, onSelectContact: {contact in
firstName = contact.givenName
lastName = contact.familyName
if contact.postalAddresses.count > 0 {
if let addressString = (
((contact.postalAddresses[0] as AnyObject).value(forKey: "labelValuePair")
as AnyObject).value(forKey: "value"))
as? CNPostalAddress {
// swiftlint:disable:next line_length
let mailAddress = CNPostalAddressFormatter.string(from: addressString, style: .mailingAddress)
addressLine1 = "\(addressString.street)"
}
}
self.showPicker.toggle()
}, onCancel: nil)
}
.padding([.leading, .trailing], 10 )
.navigationTitle("Recipient")
.navigationBarItems(trailing:
HStack {
Button(action: {
self.showPicker.toggle()
}, label: {
Image(systemName: "magnifyingglass")
})
}
)
}
}
` I have confirmed that if I disable the ContactPicker function the screen allows me to select fields.. so it must be caused by the ShowPicker capabilities.