CNContactView controller's cancel button disappears while typing and then reappears

I'm working with SwiftUI, I'm using a NavigationView, then a NavigationLink which takes to a UIViewControllerRepresentable of a CNContactViewController.

UIViewControllerRepresentable:

import SwiftUI
import ContactsUI

struct ContactView: UIViewControllerRepresentable {
    let contact: CNContact
    
    class Coordinator: NSObject, CNContactViewControllerDelegate {
        
        let contacts: Contacts
        
        init(contacts: Contacts) {
            self.contacts = contacts
        }
        
        func contactViewController(_ viewController: CNContactViewController, didCompleteWith contact: CNContact?) {
        }
    }
    
    init (_ contact: CNContact) {
        self.contact = contact
    }

    func makeUIViewController(context: Context) -> CNContactViewController {
        let controller = CNContactViewController(for: contact)
        controller.allowsEditing = true
        controller.contactStore = contacts.contactStore
        controller.message = ""
        controller.delegate = context.coordinator
        
        return controller
    }
    
    func makeCoordinator() -> Coordinator {
        return Coordinator(contacts: contacts)
    }

    
    func updateUIViewController(_ uiViewController: CNContactViewController, context: Context) {
        
    }
} 

Navigation Link:

NavigationView {
   List {
      let contact = ... // get an existing contact from the contact store

      NavigationLink(destination: ContactView(contact)) {
         Text("Show Contact")
      }
   }
}

Button disappears and reappears:

Button disappears and reappears

Here is a demo project on GitHub if you want to run it easily

Upvotes: 2

Views: 188

Answers (0)

Related Questions