|
@@ -119,7 +119,7 @@ open class MessageLabel: UILabel {
|
|
|
size.height += textInsets.vertical
|
|
|
return size
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
internal var messageLabelFont: UIFont?
|
|
|
|
|
|
private var attributesNeedUpdate = false
|
|
@@ -139,11 +139,11 @@ open class MessageLabel: UILabel {
|
|
|
open internal(set) var phoneNumberAttributes: [NSAttributedString.Key: Any] = defaultAttributes
|
|
|
|
|
|
open internal(set) var urlAttributes: [NSAttributedString.Key: Any] = defaultAttributes
|
|
|
-
|
|
|
+
|
|
|
open internal(set) var transitInformationAttributes: [NSAttributedString.Key: Any] = defaultAttributes
|
|
|
-
|
|
|
+
|
|
|
open internal(set) var hashtagAttributes: [NSAttributedString.Key: Any] = defaultAttributes
|
|
|
-
|
|
|
+
|
|
|
open internal(set) var mentionAttributes: [NSAttributedString.Key: Any] = defaultAttributes
|
|
|
|
|
|
open internal(set) var customAttributes: [NSRegularExpression: [NSAttributedString.Key: Any]] = [:]
|
|
@@ -201,7 +201,7 @@ open class MessageLabel: UILabel {
|
|
|
}
|
|
|
|
|
|
// MARK: - Public Methods
|
|
|
-
|
|
|
+
|
|
|
public func configure(block: () -> Void) {
|
|
|
isConfiguring = true
|
|
|
block()
|
|
@@ -222,19 +222,19 @@ open class MessageLabel: UILabel {
|
|
|
setNeedsDisplay()
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
let style = paragraphStyle(for: newText)
|
|
|
let range = NSRange(location: 0, length: newText.length)
|
|
|
-
|
|
|
+
|
|
|
let mutableText = NSMutableAttributedString(attributedString: newText)
|
|
|
mutableText.addAttribute(.paragraphStyle, value: style, range: range)
|
|
|
-
|
|
|
+
|
|
|
if shouldParse {
|
|
|
rangesForDetectors.removeAll()
|
|
|
let results = parse(text: mutableText)
|
|
|
setRangesForDetectors(in: results)
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
for (detector, rangeTuples) in rangesForDetectors {
|
|
|
if enabledDetectors.contains(detector) {
|
|
|
let attributes = detectorAttributes(for: detector)
|
|
@@ -250,17 +250,17 @@ open class MessageLabel: UILabel {
|
|
|
if !isConfiguring { setNeedsDisplay() }
|
|
|
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
private func paragraphStyle(for text: NSAttributedString) -> NSParagraphStyle {
|
|
|
guard text.length > 0 else { return NSParagraphStyle() }
|
|
|
-
|
|
|
+
|
|
|
var range = NSRange(location: 0, length: text.length)
|
|
|
let existingStyle = text.attribute(.paragraphStyle, at: 0, effectiveRange: &range) as? NSMutableParagraphStyle
|
|
|
let style = existingStyle ?? NSMutableParagraphStyle()
|
|
|
-
|
|
|
+
|
|
|
style.lineBreakMode = lineBreakMode
|
|
|
style.alignment = textAlignment
|
|
|
-
|
|
|
+
|
|
|
return style
|
|
|
}
|
|
|
|
|
@@ -321,7 +321,7 @@ open class MessageLabel: UILabel {
|
|
|
fatalError(MessageKitError.unrecognizedCheckingResult)
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
private func setupView() {
|
|
|
numberOfLines = 0
|
|
|
lineBreakMode = .byWordWrapping
|
|
@@ -378,7 +378,7 @@ open class MessageLabel: UILabel {
|
|
|
private func setRangesForDetectors(in checkingResults: [NSTextCheckingResult]) {
|
|
|
|
|
|
guard checkingResults.isEmpty == false else { return }
|
|
|
-
|
|
|
+
|
|
|
for result in checkingResults {
|
|
|
|
|
|
switch result.resultType {
|
|
@@ -435,13 +435,13 @@ open class MessageLabel: UILabel {
|
|
|
let index = layoutManager.glyphIndex(for: location, in: textContainer)
|
|
|
|
|
|
let lineRect = layoutManager.lineFragmentUsedRect(forGlyphAt: index, effectiveRange: nil)
|
|
|
-
|
|
|
+
|
|
|
var characterIndex: Int?
|
|
|
-
|
|
|
+
|
|
|
if lineRect.contains(location) {
|
|
|
characterIndex = layoutManager.characterIndexForGlyph(at: index)
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
return characterIndex
|
|
|
|
|
|
}
|
|
@@ -463,7 +463,6 @@ open class MessageLabel: UILabel {
|
|
|
|
|
|
// swiftlint:disable cyclomatic_complexity
|
|
|
private func handleGesture(for detectorType: DetectorType, value: MessageTextCheckingType) {
|
|
|
-
|
|
|
switch value {
|
|
|
case let .addressComponents(addressComponents):
|
|
|
var transformedAddressComponents = [String: String]()
|
|
@@ -501,23 +500,23 @@ open class MessageLabel: UILabel {
|
|
|
}
|
|
|
}
|
|
|
// swiftlint:enable cyclomatic_complexity
|
|
|
-
|
|
|
+
|
|
|
private func handleAddress(_ addressComponents: [String: String]) {
|
|
|
delegate?.didSelectAddress(addressComponents)
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
private func handleDate(_ date: Date) {
|
|
|
delegate?.didSelectDate(date)
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
private func handleURL(_ url: URL) {
|
|
|
delegate?.didSelectURL(url)
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
private func handlePhoneNumber(_ phoneNumber: String) {
|
|
|
delegate?.didSelectPhoneNumber(phoneNumber)
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
private func handleTransitInformation(_ components: [String: String]) {
|
|
|
delegate?.didSelectTransitInformation(components)
|
|
|
}
|