From 4ee5f6dd007806501e475783b0f63718b31a54ba Mon Sep 17 00:00:00 2001 From: Aleksey Belousov Date: Thu, 9 Jul 2020 11:06:25 +0300 Subject: [PATCH] [iOS] fix a bug in which "more" button below bookmark description in PP not available https://jira.mail.ru/browse/MAPSME-14299 --- .../PlacePageBookmarkViewController.swift | 14 +++----------- .../Maps/UI/PlacePage/Views/ExpandableLabel.swift | 10 ++++++++-- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/iphone/Maps/UI/PlacePage/Components/PlacePageBookmarkViewController.swift b/iphone/Maps/UI/PlacePage/Components/PlacePageBookmarkViewController.swift index 6bcf068343..84b91114bf 100644 --- a/iphone/Maps/UI/PlacePage/Components/PlacePageBookmarkViewController.swift +++ b/iphone/Maps/UI/PlacePage/Components/PlacePageBookmarkViewController.swift @@ -29,20 +29,12 @@ class PlacePageBookmarkViewController: UIViewController { updateViews() } - override func viewDidLayoutSubviews() { - super.viewDidLayoutSubviews() - guard let bookmarkData = bookmarkData, - bookmarkData.isHtmlDescription, - expandableLabel.width > 0, - let description = bookmarkData.bookmarkDescription else { return } - setHtmlDescription(description, maxWidth: expandableLabel.width) - } - func updateViews() { guard let bookmarkData = bookmarkData else { return } editButton.isEnabled = bookmarkData.isEditable if let description = bookmarkData.bookmarkDescription { if bookmarkData.isHtmlDescription { + setHtmlDescription(description) topConstraint.constant = 16 } else { expandableLabel.text = description @@ -53,7 +45,7 @@ class PlacePageBookmarkViewController: UIViewController { } } - private func setHtmlDescription(_ htmlDescription: String, maxWidth: CGFloat) { + private func setHtmlDescription(_ htmlDescription: String) { DispatchQueue.global().async { let font = UIFont.regular14() let color = UIColor.blackPrimaryText() @@ -61,7 +53,7 @@ class PlacePageBookmarkViewController: UIViewController { paragraphStyle.lineSpacing = 4 let attributedString: NSAttributedString - if let str = NSMutableAttributedString(htmlString: htmlDescription, baseFont: font, paragraphStyle: paragraphStyle, estimatedWidth: maxWidth) { + if let str = NSMutableAttributedString(htmlString: htmlDescription, baseFont: font, paragraphStyle: paragraphStyle) { str.addAttribute(NSAttributedString.Key.foregroundColor, value: color, range: NSRange(location: 0, length: str.length)) diff --git a/iphone/Maps/UI/PlacePage/Views/ExpandableLabel.swift b/iphone/Maps/UI/PlacePage/Views/ExpandableLabel.swift index 983f1e8749..620d3652c2 100644 --- a/iphone/Maps/UI/PlacePage/Views/ExpandableLabel.swift +++ b/iphone/Maps/UI/PlacePage/Views/ExpandableLabel.swift @@ -30,7 +30,6 @@ final class ExpandableLabel: UIView { didSet { containerText = text textView.text = text - expandLabel.isHidden = true if let text = text { isHidden = text.isEmpty } else { @@ -43,7 +42,6 @@ final class ExpandableLabel: UIView { didSet { containerText = attributedText?.string textView.attributedText = attributedText - expandLabel.isHidden = true if let attributedText = attributedText { isHidden = attributedText.length == 0 } else { @@ -72,6 +70,8 @@ final class ExpandableLabel: UIView { } } + private var oldWidth: CGFloat = 0 + override func setContentHuggingPriority(_ priority: UILayoutPriority, for axis: NSLayoutConstraint.Axis) { super.setContentHuggingPriority(priority, for: axis) textView.setContentHuggingPriority(priority, for: axis) @@ -137,6 +137,12 @@ final class ExpandableLabel: UIView { override func layoutSubviews() { super.layoutSubviews() + if oldWidth != bounds.width, let attributedText = attributedText?.mutableCopy() as? NSMutableAttributedString { + attributedText.enumerateAttachments(estimatedWidth: bounds.width) + self.attributedText = attributedText + oldWidth = bounds.width + } + guard containerMaximumNumberOfLines > 0, containerMaximumNumberOfLines != numberOfLines, let s = containerText,