SwiftUIContactPicker

main

Native SwiftUI contact picker
pykaso/SwiftUI_ContactPicker

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)

Description

  • Swift Tools 5.3.0
View More Packages from this Author

Dependencies

  • None
Last updated: Sun Oct 20 2024 07:51:37 GMT-0900 (Hawaii-Aleutian Daylight Time)