Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Sources/KNContactsPicker/KNContactCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ class KNContactCell: UITableViewCell {
override func prepareForReuse() {
super.prepareForReuse()
self.disabled = false
self.isSelected = false
}

override func setSelected(_ selected: Bool, animated: Bool) {
if (!disabled) {
super.setSelected(selected, animated: animated)
self.setAppropriateStyle()
}
}

Expand Down Expand Up @@ -176,6 +176,8 @@ class KNContactCell: UITableViewCell {
}

public func set(contactModel: KNContactCellModel) {
let isSelected = contactModel.getIsSelected()
self.setSelected(isSelected, animated: false)
self.nameLabel.text = contactModel.getName()
self.subtitleLabel.text = contactModel.getSubtitle()

Expand Down
8 changes: 7 additions & 1 deletion Sources/KNContactsPicker/KNContactCellModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,17 @@ struct KNContactCellModel {
private var contact: CNContact
private var settings: KNPickerSettings
private var formatter: CNContactFormatter
private var isSelected: Bool

init(contact: CNContact, settings: KNPickerSettings, formatter: CNContactFormatter) {
init(contact: CNContact, settings: KNPickerSettings, formatter: CNContactFormatter, isSelected: Bool) {
self.contact = contact
self.settings = settings
self.formatter = formatter
self.isSelected = isSelected
}

func getIsSelected() -> Bool {
return isSelected
}

func getName() -> String {
Expand Down
10 changes: 4 additions & 6 deletions Sources/KNContactsPicker/KNContactsPickerController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,13 @@ class KNContactsPickerController: UITableViewController {
override open func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: CELL_ID, for: indexPath) as! KNContactCell
let contact = self.getContact(at: indexPath)
let contactModel = KNContactCellModel(contact: contact, settings: settings, formatter: formatter)

let disabled = ( shouldDisableSelection && !selectedContacts.contains(contact) ) || settings.conditionToDisableContact(contact)

let selected = selectedContacts.contains(contact)
let disabled = ( shouldDisableSelection && !selectedContacts.contains(contact) ) || settings.conditionToDisableContact(contact)
let contactModel = KNContactCellModel(contact: contact, settings: settings, formatter: formatter, isSelected: selected)

cell.set(contactModel: contactModel)

cell.setDisabled(disabled: disabled)
cell.setSelected(selected, animated: false)
cell.setAppropriateStyle()
return cell
}

Expand Down