2021-01-29 09:47:32 +01:00
|
|
|
//
|
|
|
|
// ActiveLabel.swift
|
|
|
|
// Mastodon
|
|
|
|
//
|
|
|
|
// Created by sxiaojian on 2021/1/29.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
import Foundation
|
|
|
|
import ActiveLabel
|
2021-02-01 11:06:29 +01:00
|
|
|
import os.log
|
2021-01-29 09:47:32 +01:00
|
|
|
|
|
|
|
extension ActiveLabel {
|
|
|
|
|
|
|
|
enum Style {
|
|
|
|
case `default`
|
|
|
|
case timelineHeaderView
|
|
|
|
}
|
|
|
|
|
|
|
|
convenience init(style: Style) {
|
|
|
|
self.init()
|
|
|
|
|
|
|
|
switch style {
|
|
|
|
case .default:
|
|
|
|
font = .preferredFont(forTextStyle: .body)
|
2021-02-23 08:16:55 +01:00
|
|
|
textColor = Asset.Colors.Label.primary.color
|
2021-01-29 09:47:32 +01:00
|
|
|
case .timelineHeaderView:
|
|
|
|
font = .preferredFont(forTextStyle: .footnote)
|
|
|
|
textColor = .secondaryLabel
|
|
|
|
}
|
|
|
|
|
|
|
|
numberOfLines = 0
|
2021-02-23 08:16:55 +01:00
|
|
|
lineSpacing = 5
|
|
|
|
mentionColor = Asset.Colors.Label.highlight.color
|
|
|
|
hashtagColor = Asset.Colors.Label.highlight.color
|
|
|
|
URLColor = Asset.Colors.Label.highlight.color
|
2021-01-29 09:47:32 +01:00
|
|
|
text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
extension ActiveLabel {
|
2021-02-01 11:06:29 +01:00
|
|
|
func config(content: String) {
|
2021-02-23 12:18:34 +01:00
|
|
|
activeEntities.removeAll()
|
2021-02-01 11:06:29 +01:00
|
|
|
if let parseResult = try? TootContent.parse(toot: content) {
|
|
|
|
text = parseResult.trimmed
|
|
|
|
activeEntities = parseResult.activeEntities
|
2021-02-23 12:18:34 +01:00
|
|
|
} else {
|
|
|
|
text = ""
|
2021-02-01 11:06:29 +01:00
|
|
|
}
|
2021-01-29 09:47:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|