Files
comaps/iphone/Maps/UI/PlacePage/Components/WikiDescriptionViewController.swift
Konstantin Pastbin e3e4a1985a Organic Maps sources as of 02.04.2025 (fad26bbf22ac3da75e01e62aa01e5c8e11861005)
To expand with full Organic Maps and Maps.ME commits history run:
  git remote add om-historic [om-historic.git repo url]
  git fetch --tags om-historic
  git replace squashed-history historic-commits
2025-05-08 21:10:51 +07:00

71 lines
2.4 KiB
Swift

protocol WikiDescriptionViewControllerDelegate: AnyObject {
func didPressMore()
}
class WikiDescriptionViewController: UIViewController {
@IBOutlet var descriptionTextView: UITextView!
@IBOutlet var moreButton: UIButton!
var descriptionHtml: String? {
didSet{
updateDescription()
}
}
weak var delegate: WikiDescriptionViewControllerDelegate?
override func viewDidLoad() {
super.viewDidLoad()
descriptionTextView.textContainerInset = .zero
updateDescription()
}
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
guard traitCollection.userInterfaceStyle != previousTraitCollection?.userInterfaceStyle else { return }
updateDescription()
}
private func updateDescription() {
guard let descriptionHtml = descriptionHtml else { return }
DispatchQueue.global().async {
let font = UIFont.regular14()
let color = UIColor.blackPrimaryText()
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.lineSpacing = 4
let attributedString: NSAttributedString
if let str = NSMutableAttributedString(htmlString: descriptionHtml, baseFont: font, paragraphStyle: paragraphStyle) {
str.addAttribute(NSAttributedString.Key.foregroundColor,
value: color,
range: NSRange(location: 0, length: str.length))
attributedString = str;
} else {
attributedString = NSAttributedString(string: descriptionHtml,
attributes: [NSAttributedString.Key.font : font,
NSAttributedString.Key.foregroundColor: color,
NSAttributedString.Key.paragraphStyle: paragraphStyle])
}
DispatchQueue.main.async {
if attributedString.length > 500 {
self.descriptionTextView.attributedText = attributedString.attributedSubstring(from: NSRange(location: 0,
length: 500))
} else {
self.descriptionTextView.attributedText = attributedString
}
}
}
}
@IBAction func onMore(_ sender: UIButton) {
delegate?.didPressMore()
}
override func applyTheme() {
super.applyTheme()
updateDescription()
}
}