Expose metas in fields as accessibility actions
This commit is contained in:
parent
5a3afef978
commit
952ae0f621
|
@ -129,6 +129,40 @@ extension ProfileFieldCollectionViewCell {
|
||||||
UIMenuController.shared.showMenu(from: checkmark, rect: checkmark.bounds)
|
UIMenuController.shared.showMenu(from: checkmark, rect: checkmark.bounds)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var valueMetas: [(title: String, Meta)] {
|
||||||
|
var result: [(title: String, Meta)] = []
|
||||||
|
valueMetaLabel.textStorage.enumerateAttribute(NSAttributedString.Key("MetaAttributeKey.meta"), in: NSMakeRange(0, valueMetaLabel.textStorage.length)) { value, range, _ in
|
||||||
|
if let value = value as? Meta {
|
||||||
|
result.append((valueMetaLabel.textStorage.string.substring(with: range), value))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
override func accessibilityActivate() -> Bool {
|
||||||
|
if let (_, meta) = valueMetas.first {
|
||||||
|
delegate?.profileFieldCollectionViewCell(self, metaLabel: valueMetaLabel, didSelectMeta: meta)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override var accessibilityCustomActions: [UIAccessibilityCustomAction]? {
|
||||||
|
get {
|
||||||
|
let valueMetas = valueMetas
|
||||||
|
if valueMetas.count < 2 { return nil }
|
||||||
|
return valueMetas.compactMap { title, meta in
|
||||||
|
guard let name = meta.accessibilityLabel else { return nil }
|
||||||
|
return UIAccessibilityCustomAction(name: name) { [weak self] _ in
|
||||||
|
guard let self, let delegate = self.delegate else { return false }
|
||||||
|
delegate.profileFieldCollectionViewCell(self, metaLabel: self.valueMetaLabel, didSelectMeta: meta)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
set {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// UIMenuController boilerplate
|
// UIMenuController boilerplate
|
||||||
|
|
|
@ -8,9 +8,9 @@
|
||||||
import Meta
|
import Meta
|
||||||
import MastodonLocalization
|
import MastodonLocalization
|
||||||
|
|
||||||
extension Meta.Entity {
|
extension Meta {
|
||||||
var accessibilityCustomActionLabel: String? {
|
public var accessibilityLabel: String? {
|
||||||
switch meta {
|
switch self {
|
||||||
case .url(_, trimmed: _, url: let url, userInfo: _):
|
case .url(_, trimmed: _, url: let url, userInfo: _):
|
||||||
return L10n.Common.Controls.Status.MetaEntity.url(url)
|
return L10n.Common.Controls.Status.MetaEntity.url(url)
|
||||||
case .hashtag(_, hashtag: let hashtag, userInfo: _):
|
case .hashtag(_, hashtag: let hashtag, userInfo: _):
|
|
@ -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
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -889,7 +889,7 @@ extension StatusView.ViewModel {
|
||||||
.map { content, isRevealed in
|
.map { content, isRevealed in
|
||||||
guard isRevealed, let entities = content?.entities else { return [] }
|
guard isRevealed, let entities = content?.entities else { return [] }
|
||||||
return entities.compactMap { entity in
|
return entities.compactMap { entity in
|
||||||
guard let name = entity.accessibilityCustomActionLabel else { return nil }
|
guard let name = entity.meta.accessibilityLabel else { return nil }
|
||||||
return UIAccessibilityCustomAction(name: name) { action in
|
return UIAccessibilityCustomAction(name: name) { action in
|
||||||
statusView.delegate?.statusView(statusView, metaText: statusView.contentMetaText, didSelectMeta: entity.meta)
|
statusView.delegate?.statusView(statusView, metaText: statusView.contentMetaText, didSelectMeta: entity.meta)
|
||||||
return true
|
return true
|
||||||
|
|
Loading…
Reference in New Issue