Skip to content

pykaso/SwiftUI_ContactPicker

Repository files navigation

SwiftUI ContactPicker

Native SwiftUI CNContactViewController replacement

License SwiftPM compatible Twitter

CNContactViewController VS. SwiftUI_ContactPicker

Usage

Default list, without custom row layout

import SwiftUIContactPicker

@State var selectedContact: PhoneContact?
@State var viewModel: ContactPickerViewModel = ContactPickerViewModel(store: 
@State var showSheet: Bool = false
private var cpConfig = ContactPickerConfiguration.default

var body: some View {
    Text("Choose a contact")
        .onTapGesture {
            showSheet.toggle()
        }
        .sheet(isPresented: $showSheet, content: {
            ContactPickerView(viewModel: viewModel,
                            config: cpConfig,
                            selectedContact: $selectedContact,
                            onCancel: {
                                showSheet = false
                            })
        })
        .onChange(of: selectedContact) { selected in
            guard let selectedContact = selected else { return }
            print("selected=\(selectedContact.name ?? "")")

        }
}

TODO

  • The "Groups" button not implemented. It's possible that will be removed/hidden because I don't need it for now.
  • Missing "index bar" (letters on the right side)