From 2b32ebc36720c22fdbd7558b2f1f77a635669c91 Mon Sep 17 00:00:00 2001 From: Peter <> Date: Tue, 26 Feb 2019 18:24:16 +0300 Subject: [PATCH] Expose more elements to accessibility --- .../ChatInterfaceStateNavigationButtons.swift | 4 +++- TelegramUI/ChatListController.swift | 13 ++++++++++++- TelegramUI/ChatListControllerNode.swift | 2 ++ TelegramUI/ContactsPeerItem.swift | 5 +++++ TelegramUI/ItemListActionItem.swift | 12 ++++++++++++ TelegramUI/ItemListAvatarAndNameItem.swift | 4 ++++ TelegramUI/ItemListDisclosureItem.swift | 6 ++++++ TelegramUI/ItemListPeerActionItem.swift | 4 ++++ TelegramUI/ItemListPeerItem.swift | 13 +++++++++++++ TelegramUI/ItemListTextWithLabelItem.swift | 5 +++++ TelegramUI/NavigationBarSearchContentNode.swift | 5 +++++ 11 files changed, 71 insertions(+), 2 deletions(-) diff --git a/TelegramUI/ChatInterfaceStateNavigationButtons.swift b/TelegramUI/ChatInterfaceStateNavigationButtons.swift index a54f8d679f..fb7da36e23 100644 --- a/TelegramUI/ChatInterfaceStateNavigationButtons.swift +++ b/TelegramUI/ChatInterfaceStateNavigationButtons.swift @@ -52,7 +52,9 @@ func rightNavigationButtonForChatInterfaceState(_ presentationInterfaceState: Ch if case .standard(true) = presentationInterfaceState.mode { } else if let peer = presentationInterfaceState.renderedPeer?.peer { if presentationInterfaceState.accountPeerId == peer.id { - return ChatNavigationButton(action: .search, buttonItem: UIBarButtonItem(image: PresentationResourcesRootController.navigationCompactSearchIcon(presentationInterfaceState.theme), style: .plain, target: target, action: selector)) + let buttonItem = UIBarButtonItem(image: PresentationResourcesRootController.navigationCompactSearchIcon(presentationInterfaceState.theme), style: .plain, target: target, action: selector) + buttonItem.accessibilityLabel = "Info" + return ChatNavigationButton(action: .search, buttonItem: buttonItem) } } diff --git a/TelegramUI/ChatListController.swift b/TelegramUI/ChatListController.swift index 279d407043..dd15d8c161 100644 --- a/TelegramUI/ChatListController.swift +++ b/TelegramUI/ChatListController.swift @@ -593,7 +593,11 @@ public class ChatListController: TelegramController, KeyShortcutResponder, UIVie } self.chatListDisplayNode.chatListNode.contentOffsetChanged = { [weak self] offset in - if let strongSelf = self, let searchContentNode = strongSelf.searchContentNode { + if let strongSelf = self, let searchContentNode = strongSelf.searchContentNode, let validLayout = strongSelf.validLayout { + var offset = offset + if validLayout.inVoiceOver { + offset = .known(0.0) + } searchContentNode.updateListVisibleContentOffset(offset) } } @@ -789,8 +793,15 @@ public class ChatListController: TelegramController, KeyShortcutResponder, UIVie override public func containerLayoutUpdated(_ layout: ContainerViewLayout, transition: ContainedViewLayoutTransition) { super.containerLayoutUpdated(layout, transition: transition) + let wasInVoiceOver = self.validLayout?.inVoiceOver ?? false + self.validLayout = layout + if let searchContentNode = self.searchContentNode, layout.inVoiceOver != wasInVoiceOver { + searchContentNode.updateListVisibleContentOffset(.known(0.0)) + self.chatListDisplayNode.chatListNode.scrollToPosition(.top) + } + self.chatListDisplayNode.containerLayoutUpdated(layout, navigationBarHeight: self.navigationInsetHeight, transition: transition) } diff --git a/TelegramUI/ChatListControllerNode.swift b/TelegramUI/ChatListControllerNode.swift index 903c630e0d..875eff30d1 100644 --- a/TelegramUI/ChatListControllerNode.swift +++ b/TelegramUI/ChatListControllerNode.swift @@ -198,6 +198,7 @@ final class ChatListControllerNode: ASDisplayNode { requestDeactivateSearch() } }) + self.chatListNode.accessibilityElementsHidden = true self.searchDisplayController?.containerLayoutUpdated(containerLayout, navigationBarHeight: navigationBarHeight, transition: .immediate) self.searchDisplayController?.activate(insertSubnode: { [weak self, weak placeholderNode] subnode, isSearchBar in @@ -215,6 +216,7 @@ final class ChatListControllerNode: ASDisplayNode { if let searchDisplayController = self.searchDisplayController { searchDisplayController.deactivate(placeholder: placeholderNode, animated: animated) self.searchDisplayController = nil + self.chatListNode.accessibilityElementsHidden = false } } diff --git a/TelegramUI/ContactsPeerItem.swift b/TelegramUI/ContactsPeerItem.swift index 951c6117ff..22d95f77cb 100644 --- a/TelegramUI/ContactsPeerItem.swift +++ b/TelegramUI/ContactsPeerItem.swift @@ -335,6 +335,8 @@ class ContactsPeerItemNode: ItemListRevealOptionsItemNode { super.init(layerBacked: false, dynamicBounce: false, rotated: false, seeThrough: false) + self.isAccessibilityElement = true + self.addSubnode(self.backgroundNode) self.addSubnode(self.separatorNode) self.addSubnode(self.avatarNode) @@ -620,6 +622,9 @@ class ContactsPeerItemNode: ItemListRevealOptionsItemNode { if let strongSelf = strongSelf { strongSelf.layoutParams = (item, params, first, last, firstWithHeader) + strongSelf.accessibilityLabel = titleAttributedString?.string + strongSelf.accessibilityValue = statusAttributedString?.string + switch item.peer { case let .peer(peer, _): if let peer = peer { diff --git a/TelegramUI/ItemListActionItem.swift b/TelegramUI/ItemListActionItem.swift index 68c325e81c..bc6bd01c4d 100644 --- a/TelegramUI/ItemListActionItem.swift +++ b/TelegramUI/ItemListActionItem.swift @@ -116,6 +116,8 @@ class ItemListActionItemNode: ListViewItemNode { super.init(layerBacked: false, dynamicBounce: false) + self.isAccessibilityElement = true + self.addSubnode(self.titleNode) } @@ -170,6 +172,16 @@ class ItemListActionItemNode: ListViewItemNode { if let strongSelf = self { strongSelf.item = item + strongSelf.accessibilityLabel = item.title + var accessibilityTraits: UIAccessibilityTraits = UIAccessibilityTraitButton + switch item.kind { + case .disabled: + accessibilityTraits |= UIAccessibilityTraitNotEnabled + default: + break + } + strongSelf.accessibilityTraits = accessibilityTraits + if let _ = updatedTheme { strongSelf.topStripeNode.backgroundColor = itemSeparatorColor strongSelf.bottomStripeNode.backgroundColor = itemSeparatorColor diff --git a/TelegramUI/ItemListAvatarAndNameItem.swift b/TelegramUI/ItemListAvatarAndNameItem.swift index 40aee8b8ab..61eba3f9c7 100644 --- a/TelegramUI/ItemListAvatarAndNameItem.swift +++ b/TelegramUI/ItemListAvatarAndNameItem.swift @@ -327,6 +327,8 @@ class ItemListAvatarAndNameInfoItemNode: ListViewItemNode, ItemListItemNode, Ite super.init(layerBacked: false, dynamicBounce: false) + self.isAccessibilityElement = true + self.addSubnode(self.avatarNode) self.addSubnode(self.activityIndicator) @@ -524,6 +526,8 @@ class ItemListAvatarAndNameInfoItemNode: ListViewItemNode, ItemListItemNode, Ite if let strongSelf = self { strongSelf.item = item + strongSelf.accessibilityLabel = displayTitle.composedTitle + strongSelf.layoutWidthAndNeighbors = (params, neighbors) var updatedArrowImage: UIImage? diff --git a/TelegramUI/ItemListDisclosureItem.swift b/TelegramUI/ItemListDisclosureItem.swift index e55996c203..032169cf9f 100644 --- a/TelegramUI/ItemListDisclosureItem.swift +++ b/TelegramUI/ItemListDisclosureItem.swift @@ -155,6 +155,8 @@ class ItemListDisclosureItemNode: ListViewItemNode { super.init(layerBacked: false, dynamicBounce: false) + self.isAccessibilityElement = true + self.addSubnode(self.titleNode) self.addSubnode(self.labelNode) self.addSubnode(self.arrowNode) @@ -286,6 +288,10 @@ class ItemListDisclosureItemNode: ListViewItemNode { if let strongSelf = self { strongSelf.item = item + strongSelf.accessibilityLabel = item.title + strongSelf.accessibilityValue = item.label + strongSelf.accessibilityTraits = UIAccessibilityTraitButton + if let icon = item.icon { if strongSelf.iconNode.supernode == nil { strongSelf.addSubnode(strongSelf.iconNode) diff --git a/TelegramUI/ItemListPeerActionItem.swift b/TelegramUI/ItemListPeerActionItem.swift index 0516d054cc..2a47a34b29 100644 --- a/TelegramUI/ItemListPeerActionItem.swift +++ b/TelegramUI/ItemListPeerActionItem.swift @@ -114,6 +114,8 @@ class ItemListPeerActionItemNode: ListViewItemNode { super.init(layerBacked: false, dynamicBounce: false) + self.isAccessibilityElement = true + self.addSubnode(self.iconNode) self.addSubnode(self.titleNode) } @@ -147,6 +149,8 @@ class ItemListPeerActionItemNode: ListViewItemNode { if let strongSelf = self { strongSelf.item = item + strongSelf.accessibilityLabel = item.title + if let _ = updatedTheme { strongSelf.topStripeNode.backgroundColor = item.theme.list.itemBlocksSeparatorColor strongSelf.bottomStripeNode.backgroundColor = item.theme.list.itemBlocksSeparatorColor diff --git a/TelegramUI/ItemListPeerItem.swift b/TelegramUI/ItemListPeerItem.swift index 151027a01b..234eac2033 100644 --- a/TelegramUI/ItemListPeerItem.swift +++ b/TelegramUI/ItemListPeerItem.swift @@ -246,6 +246,8 @@ class ItemListPeerItemNode: ItemListRevealOptionsItemNode, ItemListItemNode { super.init(layerBacked: false, dynamicBounce: false, rotated: false, seeThrough: false) + self.isAccessibilityElement = true + self.addSubnode(self.avatarNode) self.addSubnode(self.titleNode) self.addSubnode(self.statusNode) @@ -497,6 +499,17 @@ class ItemListPeerItemNode: ItemListRevealOptionsItemNode, ItemListItemNode { if let strongSelf = self { strongSelf.layoutParams = (item, params, neighbors) + strongSelf.accessibilityLabel = titleAttributedString?.string + var combinedValueString = "" + if let statusString = statusAttributedString?.string, !statusString.isEmpty { + combinedValueString.append(statusString) + } + if let labelString = labelAttributedString?.string, !labelString.isEmpty { + combinedValueString.append(labelString) + } + + strongSelf.accessibilityValue = combinedValueString + if let updateArrowImage = updateArrowImage { strongSelf.labelArrowNode?.image = updateArrowImage } diff --git a/TelegramUI/ItemListTextWithLabelItem.swift b/TelegramUI/ItemListTextWithLabelItem.swift index 00c150c667..5033ee6757 100644 --- a/TelegramUI/ItemListTextWithLabelItem.swift +++ b/TelegramUI/ItemListTextWithLabelItem.swift @@ -132,6 +132,8 @@ class ItemListTextWithLabelItemNode: ListViewItemNode { super.init(layerBacked: false, dynamicBounce: false) + self.isAccessibilityElement = true + self.addSubnode(self.labelNode) self.addSubnode(self.textNode) } @@ -218,6 +220,9 @@ class ItemListTextWithLabelItemNode: ListViewItemNode { strongSelf.item = item + strongSelf.accessibilityLabel = item.label + strongSelf.accessibilityValue = item.text + if let _ = updatedTheme { strongSelf.topStripeNode.backgroundColor = item.theme.list.itemPlainSeparatorColor strongSelf.bottomStripeNode.backgroundColor = item.theme.list.itemPlainSeparatorColor diff --git a/TelegramUI/NavigationBarSearchContentNode.swift b/TelegramUI/NavigationBarSearchContentNode.swift index 10df92837b..394126a17a 100644 --- a/TelegramUI/NavigationBarSearchContentNode.swift +++ b/TelegramUI/NavigationBarSearchContentNode.swift @@ -24,6 +24,10 @@ class NavigationBarSearchContentNode: NavigationBarContentNode { super.init() + self.placeholderNode.isAccessibilityElement = true + self.placeholderNode.accessibilityLabel = placeholder + self.placeholderNode.accessibilityTraits = UIAccessibilityTraitSearchField + self.addSubnode(self.placeholderNode) self.placeholderNode.activate = activate } @@ -31,6 +35,7 @@ class NavigationBarSearchContentNode: NavigationBarContentNode { func updateThemeAndPlaceholder(theme: PresentationTheme, placeholder: String) { self.theme = theme self.placeholder = placeholder + self.placeholderNode.accessibilityLabel = placeholder if let disabledOverlay = self.disabledOverlay { disabledOverlay.backgroundColor = theme.rootController.navigationBar.backgroundColor.withAlphaComponent(0.5) }