Skip to content

Commit e7bc2e8

Browse files
committed
Show email as name when contact has no name
// FREEBIE
1 parent 76d0186 commit e7bc2e8

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

Signal/src/views/ContactCell.swift

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,20 +99,25 @@ fileprivate extension CNContact {
9999
func formattedFullName(font: UIFont) -> NSAttributedString? {
100100
let keyToHighlight = ContactSortOrder == .familyName ? CNContactFamilyNameKey : CNContactGivenNameKey
101101

102+
let boldDescriptor = font.fontDescriptor.withSymbolicTraits(.traitBold)
103+
let boldAttributes = [
104+
NSFontAttributeName: UIFont(descriptor:boldDescriptor!, size: 0)
105+
]
106+
102107
if let attributedName = CNContactFormatter.attributedString(from: self, style: .fullName, defaultAttributes: nil) {
103108
let highlightedName = attributedName.mutableCopy() as! NSMutableAttributedString
104109
highlightedName.enumerateAttributes(in: NSMakeRange(0, highlightedName.length), options: [], using: { (attrs, range, stop) in
105110
if let property = attrs[CNContactPropertyAttribute] as? String, property == keyToHighlight {
106-
let boldDescriptor = font.fontDescriptor.withSymbolicTraits(.traitBold)
107-
let boldAttributes = [
108-
NSFontAttributeName: UIFont(descriptor:boldDescriptor!, size: 0)
109-
]
110-
111111
highlightedName.addAttributes(boldAttributes, range: range)
112112
}
113113
})
114114
return highlightedName
115115
}
116+
117+
if let emailAddress = (self.emailAddresses.first?.value as String?) {
118+
return NSAttributedString(string: emailAddress, attributes: boldAttributes)
119+
}
120+
116121
return nil
117122
}
118123
}

0 commit comments

Comments
 (0)