[DetectorType] add .mention, .hashtag and .custon() to detect your own pattern

[DetectorType] Put mention and hashtag as var

[CHANGELOG] Update

[DetectorType] Update to have at least 4 characters and more

[CHANGELOG] Update

[DetectorType]

[MessageLabel] run NSDataDetector once

[MessageLabel] Run NSDataDetector once

[Testing] Add testing and pass rangesOfDetectors as internal

[Refactoring]

[Filter] only .custom

[Examples]
This commit is contained in:
Julien K
2018-10-26 12:15:27 +02:00
parent 095abe0223
commit 77e9ccda46
8 changed files with 284 additions and 20 deletions
@@ -46,7 +46,7 @@ final internal class SampleData {
let messageImages: [UIImage] = [#imageLiteral(resourceName: "img1"), #imageLiteral(resourceName: "img2")]
let messageTypes = ["Text", "Text", "Text", "AttributedText", "Location", "Photo", "Emoji", "Video", "URL", "Phone", "Custom"]
let messageTypes = ["Text", "Text", "Text", "AttributedText", "Location", "Photo", "Emoji", "Video", "URL", "Phone", "Mention", "Hashtag", "Custom"]
let emojis = [
"👍",
@@ -150,6 +150,10 @@ final internal class SampleData {
return MockMessage(text: "https://github.com/MessageKit", sender: sender, messageId: uniqueID, date: date)
case "Phone":
return MockMessage(text: "123-456-7890", sender: sender, messageId: uniqueID, date: date)
case "Mention":
return MockMessage(text: "@messagekit", sender: sender, messageId: uniqueID, date: date)
case "Hashtag":
return MockMessage(text: "#messagekit", sender: sender, messageId: uniqueID, date: date)
case "Custom":
return MockMessage(custom: "Someone left the conversation", sender: system, messageId: uniqueID, date: date)
default:
@@ -258,11 +258,14 @@ extension AdvancedExampleViewController: MessagesDisplayDelegate {
}
func detectorAttributes(for detector: DetectorType, and message: MessageType, at indexPath: IndexPath) -> [NSAttributedString.Key: Any] {
return MessageLabel.defaultAttributes
switch detector {
case .hashtag, .mention: return [.foregroundColor: UIColor.blue]
default: return MessageLabel.defaultAttributes
}
}
func enabledDetectors(for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> [DetectorType] {
return [.url, .address, .phoneNumber, .date, .transitInformation]
return [.url, .address, .phoneNumber, .date, .transitInformation, .mention, .hashtag]
}
// MARK: - All Messages
@@ -49,11 +49,14 @@ extension BasicExampleViewController: MessagesDisplayDelegate {
}
func detectorAttributes(for detector: DetectorType, and message: MessageType, at indexPath: IndexPath) -> [NSAttributedString.Key: Any] {
return MessageLabel.defaultAttributes
switch detector {
case .hashtag, .mention: return [.foregroundColor: UIColor.blue]
default: return MessageLabel.defaultAttributes
}
}
func enabledDetectors(for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> [DetectorType] {
return [.url, .address, .phoneNumber, .date, .transitInformation]
return [.url, .address, .phoneNumber, .date, .transitInformation, .mention, .hashtag]
}
// MARK: - All Messages