From eef98ea70bb733838e4f97a51c94c33c91238503 Mon Sep 17 00:00:00 2001 From: Jed Fox Date: Tue, 7 Feb 2023 21:20:39 -0500 Subject: [PATCH] Fix large content viewer for DoubleTitleLabelNavigationBarTitleView --- .../DoubleTitleLabelNavigationBarTitleView.swift | 6 +++++- .../Sources/MastodonUI/Extension/MetaLabel.swift | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Mastodon/Scene/Share/View/Content/DoubleTitleLabelNavigationBarTitleView.swift b/Mastodon/Scene/Share/View/Content/DoubleTitleLabelNavigationBarTitleView.swift index 52d9c9f1a..953d6faa7 100644 --- a/Mastodon/Scene/Share/View/Content/DoubleTitleLabelNavigationBarTitleView.swift +++ b/Mastodon/Scene/Share/View/Content/DoubleTitleLabelNavigationBarTitleView.swift @@ -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?) { diff --git a/MastodonSDK/Sources/MastodonUI/Extension/MetaLabel.swift b/MastodonSDK/Sources/MastodonUI/Extension/MetaLabel.swift index 3e2c6853c..c59f89895 100644 --- a/MastodonSDK/Sources/MastodonUI/Extension/MetaLabel.swift +++ b/MastodonSDK/Sources/MastodonUI/Extension/MetaLabel.swift @@ -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 + } + }