[iOS] fix a bug in which "more" button below bookmark description in PP not available

https://jira.mail.ru/browse/MAPSME-14299
This commit is contained in:
Aleksey Belousov 2020-07-09 11:06:25 +03:00 committed by Aleksey Belousov
parent 4875728969
commit 4ee5f6dd00
2 changed files with 11 additions and 13 deletions

View file

@ -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))

View file

@ -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,