Question: Top View Controller (CardVC
) not focusable with Full Keyboard Access
Issues:
- When
CardVC
is displayed, and if theFull Keyboard Access
is enabled, the navigation by pressingTab
orArrow
buttons on external keyboard doesn’t cycle back to theCardVC
. - Initially,
CardVC
is highlighted (blue border to represent the focus), but pressingspace
key on external keyboard doesn’t result in tap event. Expected: Pressingspace
key should navigate to accounts settings.
Video Recording: dropbox link
View Hierarchy:
Base View Controller (Background view controller)
Card View Controller (Extended from UIViewController – custom height/width and has a gesture to dismiss upon tap on background BaseViewController)
Table view
Single cell with a button
Switch Accounts
.
Looked into:
- Tried combination of these properties on the
CardVC
:isAccessibilityElement = true
,accessibilityViewIsModal = true
,accessibilityTraits = [.keyboardKey, .allowsDirectInteraction, ...]
- Focus Groups and setting up priority
.prioritized
, etc. This doesn’t work. - CardVC has a custom gesture to detect background tap — Tried commenting it out just in case it’s interfering, it didn’t work.
- AccessibilityGroups and suggestions here: https://Appt.org
- Guide: https://developer.apple.com/documentation/uikit/uikeycommand/navigating_an_app_s_user_interface_using_a_keyboard
Would welcome suggestions on how to approach Accessibility and full keyboard access related debugging.
Related:
- How to receive space/tab keyDown event when (new) Full Keyboard Access setting is enabled?
- SwiftUI Full Keyboard Access
- Apple Developer Forum: Alternative to navigate (not working as the suggestion given here) https://developer.apple.com/forums/thread/656821
2
Answers
TableViews with complicated cells are known to break the
Full Keyboard Access
as per the updated links in the question.Root cause of this issue: Cell has a button and few other views that conflicts with the focus.
In order to resolve it, I had to simplify the cell to not contain the button
Switch Accounts
- this was added a few years back and caused the focus issue with Full Keyboard Access.Now the updated hierarchy is:
For fixing this issue I would recommend initially setting
isAccessibilityElement = false
for all components within the view. This approach ensures that none of the elements are accessible by default. Subsequently, I would methodically enable accessibility for each element by settingisAccessibilityElement = true
individually. This step-by-step process will help identify the specific element responsible for the issue.It’s important to note that not every element requires the
isAccessibilityElement = true
setting. Certain elements, such as buttons, are inherently accessible and have this property enabled by default. Additionally, utilizing the accessibility inspector on your computer is crucial. It provides a clearer perspective on how the inspector interprets the accessibility of each element.