From c54b1c9a374db0d9545c9290a5689b6d4865607e Mon Sep 17 00:00:00 2001 From: "Roodyn, Yishai (UK - London)" Date: Wed, 14 Feb 2018 16:34:58 +0000 Subject: [PATCH 1/5] TransitInfoDetection - Added transitInfoDetection to message Label --- Sources/Models/DetectorType.swift | 2 ++ Sources/Protocols/MessageLabelDelegate.swift | 5 ++++ Sources/Views/MessageLabel.swift | 29 +++++++++++++++++++- 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/Sources/Models/DetectorType.swift b/Sources/Models/DetectorType.swift index 55c48efc..20ea43f7 100644 --- a/Sources/Models/DetectorType.swift +++ b/Sources/Models/DetectorType.swift @@ -30,6 +30,7 @@ public enum DetectorType { case date case phoneNumber case url + case transitInformation // MARK: - Not supported yet @@ -43,6 +44,7 @@ public enum DetectorType { case .date: return .date case .phoneNumber: return .phoneNumber case .url: return .link + case .transitInformation: return .transitInformation } } diff --git a/Sources/Protocols/MessageLabelDelegate.swift b/Sources/Protocols/MessageLabelDelegate.swift index 1b749d7c..38e7194b 100644 --- a/Sources/Protocols/MessageLabelDelegate.swift +++ b/Sources/Protocols/MessageLabelDelegate.swift @@ -33,6 +33,8 @@ public protocol MessageLabelDelegate: AnyObject { func didSelectPhoneNumber(_ phoneNumber: String) func didSelectURL(_ url: URL) + + func didSelectTransitInformation(_ transitInformation: [String: String]) } @@ -45,5 +47,8 @@ public extension MessageLabelDelegate { func didSelectPhoneNumber(_ phoneNumber: String) {} func didSelectURL(_ url: URL) {} + + func didSelectTransitInformation(_ transitInformation: [String: String]) {} + } diff --git a/Sources/Views/MessageLabel.swift b/Sources/Views/MessageLabel.swift index c33a20be..561e136f 100644 --- a/Sources/Views/MessageLabel.swift +++ b/Sources/Views/MessageLabel.swift @@ -130,6 +130,9 @@ open class MessageLabel: UILabel { open internal(set) var phoneNumberAttributes: [NSAttributedStringKey: Any] = defaultAttributes open internal(set) var urlAttributes: [NSAttributedStringKey: Any] = defaultAttributes + + open internal(set) var transitInformationAttributes: [NSAttributedStringKey: Any] = defaultAttributes + public func setAttributes(_ attributes: [NSAttributedStringKey: Any], detector: DetectorType) { switch detector { @@ -141,6 +144,8 @@ open class MessageLabel: UILabel { dateAttributes = attributes case .url: urlAttributes = attributes + case .transitInformation: + transitInformationAttributes = attributes } if isConfiguring { attributesNeedUpdate = true @@ -268,6 +273,8 @@ open class MessageLabel: UILabel { return phoneNumberAttributes case .url: return urlAttributes + case .transitInformation: + return transitInformationAttributes } } @@ -282,6 +289,8 @@ open class MessageLabel: UILabel { return phoneNumberAttributes case .link: return urlAttributes + case .transitInformation: + return transitInformationAttributes default: fatalError(MessageKitError.unrecognizedCheckingResult) } @@ -306,7 +315,7 @@ open class MessageLabel: UILabel { switch result.resultType { case .address: var ranges = rangesForDetectors[.address] ?? [] - let tuple: (NSRange, MessageTextCheckingType) = (result.range, .addressComponents(result.addressComponents)) + let tuple: (NSRange, MessageTextCheckingType) = (result.range, .addressComponents(result.components)) ranges.append(tuple) rangesForDetectors.updateValue(ranges, forKey: .address) case .date: @@ -324,6 +333,12 @@ open class MessageLabel: UILabel { let tuple: (NSRange, MessageTextCheckingType) = (result.range, .link(result.url)) ranges.append(tuple) rangesForDetectors.updateValue(ranges, forKey: .url) + case .transitInformation: + var ranges = rangesForDetectors[.transitInformation] ?? [] + let tuple: (NSRange, MessageTextCheckingType) = (result.range, .transitInformationComponents(result.components)) + ranges.append(tuple) + rangesForDetectors.updateValue(ranges, forKey: .transitInformation) + default: fatalError("Received an unrecognized NSTextCheckingResult.CheckingType") } @@ -391,6 +406,13 @@ open class MessageLabel: UILabel { case let .link(url): guard let url = url else { return } handleURL(url) + case let .transitInformationComponents(transitInformation): + var transformedTransitInformation = [String: String]() + guard let transitInformation = transitInformation else { return } + transitInformation.forEach { (key, value) in + transformedTransitInformation[key.rawValue] = value + } + handleTransitInformation(transformedTransitInformation) } } @@ -410,6 +432,10 @@ open class MessageLabel: UILabel { delegate?.didSelectPhoneNumber(phoneNumber) } + private func handleTransitInformation(_ transitInformationComponents: [String: String]) { + delegate?.didSelectTransitInformation(transitInformationComponents) + } + } private enum MessageTextCheckingType { @@ -417,4 +443,5 @@ private enum MessageTextCheckingType { case date(Date?) case phoneNumber(String?) case link(URL?) + case transitInformationComponents([NSTextCheckingKey: String]?) } From c5c4bd4c8680af8faa0d9b6ecacefb97f6c39e59 Mon Sep 17 00:00:00 2001 From: Yishai Date: Thu, 15 Feb 2018 09:53:43 +0000 Subject: [PATCH 2/5] TransitInformation - Updated tests and example project --- Example/Sources/ConversationViewController.swift | 6 +++++- Tests/DetectorTypeSpec.swift | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Example/Sources/ConversationViewController.swift b/Example/Sources/ConversationViewController.swift index e7b7910b..97275ade 100644 --- a/Example/Sources/ConversationViewController.swift +++ b/Example/Sources/ConversationViewController.swift @@ -305,7 +305,7 @@ extension ConversationViewController: MessagesDisplayDelegate { } func enabledDetectors(for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> [DetectorType] { - return [.url, .address, .phoneNumber, .date] + return [.url, .address, .phoneNumber, .date, .transitInformation] } // MARK: - All Messages @@ -439,6 +439,10 @@ extension ConversationViewController: MessageLabelDelegate { func didSelectURL(_ url: URL) { print("URL Selected: \(url)") } + + func didSelectTransitInformation(_ transitInformation: [String : String]) { + print("TransitInformation Selected: \(transitInformation)") + } } diff --git a/Tests/DetectorTypeSpec.swift b/Tests/DetectorTypeSpec.swift index b77aa119..60426131 100644 --- a/Tests/DetectorTypeSpec.swift +++ b/Tests/DetectorTypeSpec.swift @@ -54,6 +54,12 @@ final class DetectorTypeSpec: QuickSpec { expect(phoneNumber).to(equal(NSTextCheckingResult.CheckingType.phoneNumber)) } } + context("case .transitInformation") { + it("should equal .transitInformation") { + let transitInformation = DetectorType.transitInformation.textCheckingType + expect(transitInformation).to(equal(NSTextCheckingResult.CheckingType.transitInformation)) + } + } } } } From 516f8e41524f0ec9aec9e49e1df5a35d6208ee8d Mon Sep 17 00:00:00 2001 From: Yishai Date: Thu, 15 Feb 2018 13:16:15 +0000 Subject: [PATCH 3/5] TransitInformation - Updated handleTransitInfo method name and updated change log --- CHANGELOG.md | 3 +++ Sources/Views/MessageLabel.swift | 10 +++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d95b5b9..685698dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,9 @@ The changelog for `MessageKit`. Also see the [releases](https://github.com/Messa - `layoutBottomLabel(with attributes: MessagesCollectionViewLayoutAttributes)` [#491](https://github.com/MessageKit/MessageKit/pull/491) by [@SD10](https://github.com/SD10). +- **Breaking Change** Adds new `DetectorType` called `TransitInformation` to message label. +[#520](https://github.com/MessageKit/MessageKit/pull/520) by [@nosarj](https://github.com/nosarj). + ### [[Prerelease] 0.13.1](https://github.com/MessageKit/MessageKit/releases/tag/0.13.1) ### Fixed diff --git a/Sources/Views/MessageLabel.swift b/Sources/Views/MessageLabel.swift index 561e136f..0f12f719 100644 --- a/Sources/Views/MessageLabel.swift +++ b/Sources/Views/MessageLabel.swift @@ -335,7 +335,7 @@ open class MessageLabel: UILabel { rangesForDetectors.updateValue(ranges, forKey: .url) case .transitInformation: var ranges = rangesForDetectors[.transitInformation] ?? [] - let tuple: (NSRange, MessageTextCheckingType) = (result.range, .transitInformationComponents(result.components)) + let tuple: (NSRange, MessageTextCheckingType) = (result.range, .transitInfoComponents(result.components)) ranges.append(tuple) rangesForDetectors.updateValue(ranges, forKey: .transitInformation) @@ -406,7 +406,7 @@ open class MessageLabel: UILabel { case let .link(url): guard let url = url else { return } handleURL(url) - case let .transitInformationComponents(transitInformation): + case let .transitInfoComponents(transitInformation): var transformedTransitInformation = [String: String]() guard let transitInformation = transitInformation else { return } transitInformation.forEach { (key, value) in @@ -432,8 +432,8 @@ open class MessageLabel: UILabel { delegate?.didSelectPhoneNumber(phoneNumber) } - private func handleTransitInformation(_ transitInformationComponents: [String: String]) { - delegate?.didSelectTransitInformation(transitInformationComponents) + private func handleTransitInformation(_ components: [String: String]) { + delegate?.didSelectTransitInformation(components) } } @@ -443,5 +443,5 @@ private enum MessageTextCheckingType { case date(Date?) case phoneNumber(String?) case link(URL?) - case transitInformationComponents([NSTextCheckingKey: String]?) + case transitInfoComponents([NSTextCheckingKey: String]?) } From f426a4356d07e9e07067835ec7a06e53e971d2bc Mon Sep 17 00:00:00 2001 From: Steven Deutsch Date: Thu, 15 Feb 2018 16:53:05 -0600 Subject: [PATCH 4/5] Move CHANGELOG entry --- CHANGELOG.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 685698dd..224ae4d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ The changelog for `MessageKit`. Also see the [releases](https://github.com/Messa ### Added +- **Breaking Change** Adds new `DetectorType` called `.transitInformation` to message label. +[#520](https://github.com/MessageKit/MessageKit/pull/520) by [@nosarj](https://github.com/nosarj). + - **Breaking Change** Adds `.custom(Any?)` case to `MessageData`. [#498](https://github.com/MessageKit/MessageKit/pull/498) by [@SD10](https://github.com/SD10). @@ -34,9 +37,6 @@ The changelog for `MessageKit`. Also see the [releases](https://github.com/Messa - `layoutBottomLabel(with attributes: MessagesCollectionViewLayoutAttributes)` [#491](https://github.com/MessageKit/MessageKit/pull/491) by [@SD10](https://github.com/SD10). -- **Breaking Change** Adds new `DetectorType` called `TransitInformation` to message label. -[#520](https://github.com/MessageKit/MessageKit/pull/520) by [@nosarj](https://github.com/nosarj). - ### [[Prerelease] 0.13.1](https://github.com/MessageKit/MessageKit/releases/tag/0.13.1) ### Fixed From 49a1904bf5e166124f2b8b9bbb1dc03807450128 Mon Sep 17 00:00:00 2001 From: Yishai Date: Sun, 4 Mar 2018 11:09:59 +0000 Subject: [PATCH 5/5] TransifInformation - Changed address back to addressComponents --- Sources/Views/MessageLabel.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Views/MessageLabel.swift b/Sources/Views/MessageLabel.swift index 0f12f719..f572be22 100644 --- a/Sources/Views/MessageLabel.swift +++ b/Sources/Views/MessageLabel.swift @@ -315,7 +315,7 @@ open class MessageLabel: UILabel { switch result.resultType { case .address: var ranges = rangesForDetectors[.address] ?? [] - let tuple: (NSRange, MessageTextCheckingType) = (result.range, .addressComponents(result.components)) + let tuple: (NSRange, MessageTextCheckingType) = (result.range, .addressComponents(result.addressComponents)) ranges.append(tuple) rangesForDetectors.updateValue(ranges, forKey: .address) case .date: