Merge pull request #925 from j-f1/double-line-large-content

IOS-93: Fix large content viewer for DoubleTitleLabelNavigationBarTitleView
This commit is contained in:
Marcus Kida 2023-02-08 11:03:20 +01:00 committed by GitHub
commit 2f2b5475f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 1 deletions

View File

@ -53,18 +53,22 @@ extension DoubleTitleLabelNavigationBarTitleView {
containerView.addArrangedSubview(subtitleLabel)
isAccessibilityElement = true
showsLargeContentViewer = true
addInteraction(UILargeContentViewerInteraction())
}
func update(title: String, subtitle: String?) {
titleLabel.configure(content: PlaintextMetaContent(string: title))
update(subtitle: subtitle)
accessibilityLabel = subtitle.map { "\(title), \($0)" } ?? title
largeContentTitle = accessibilityLabel
}
func update(titleMetaContent: MetaContent, subtitle: String?) {
titleLabel.configure(content: titleMetaContent)
update(subtitle: subtitle)
accessibilityLabel = subtitle.map { "\(titleMetaContent.string), \($0)" } ?? titleMetaContent.string
accessibilityLabel = subtitle.map { "\(titleLabel.backedString), \($0)" } ?? titleLabel.backedString
largeContentTitle = accessibilityLabel
}
func update(subtitle: String?) {

View File

@ -152,4 +152,18 @@ extension MetaLabel {
]
}
public var backedString: String {
let string = textStorage.string
let nsString = NSMutableString(string: string)
textStorage.enumerateAttribute(
.attachment,
in: NSRange(location: 0, length: textStorage.length),
options: [.reverse])
{ value, range, _ in
guard let attachment = value as? MetaAttachment else { return }
nsString.replaceCharacters(in: range, with: attachment.string)
}
return nsString as String
}
}