tvOS SwiftUI buttons with a custom style are not properly accessible with VoiceOver

Originator:defagos
Number:rdar://FB9786531 Date Originated:Nov 29, 2021
Status:Open Resolved:
Product:SwiftUI, tvOS Product Version:tvOS 14, tvOS 15
Classification:Incorrect behavior Reproducible:Always
 
Description of the problem
---------------------------

When assigning a custom button style to a SwiftUI button on tvOS, accessibility via VoiceOver does not work correctly anymore (VoiceOver does not read anything). There is no such issue with custom styles applied to iOS SwiftUI buttons.

This issue was observed at least with tvOS 15 and tvOS 14 (including tvOS 15.2 beta 3). It is therefore not a recent regression but more likely a problem which existed since a long time.


Step-by-step set of instructions to reproduce the problem
----------------------------------------------------------

I attached a simple sample project to this issue. This project is a SwiftUI universal app which can be run on iOS and tvOS 15. It simply displays 4 simple `Text` buttons to which 4 different styles are applied:

- 2 built-in styles (`.plain` and `.automatic`).
- 2 custom styles:
    - A style called `SimplestButtonStyle` which returns the wrapped label as is, without any style adjustments.
    - A more realistic style called `FocusableButtonStyle` which applies a different style when the button is focused.

Instructions:

1. Extract the attached project, open it with Xcode 13 and setup code signing.
2. Run the demo on a real iOS device (respectively tvOS device).
2. Enable VoiceOver and navigate through the 4 buttons (note that the "Simplest" button can receive the focus on tvOS, though of course no style adjustment is visible for this style).

On iOS you can observe that all four button labels are properly read by VoiceOver, while on tvOS only the ones displayed within buttons having a built-in style are read. Buttons with a custom style on tvOS (even the simplest possible style which does nothing) are not read by VoiceOver.


What results you expected
---------------------------

SwiftUI buttons to which a custom style has been applied can be properly read by VoiceOver on tvOS.


What results you actually saw
------------------------------

SwiftUI buttons to which a custom style has been applied are not read by VoiceOver on tvOS.

Comments

Sample code

Available on GitHub: https://github.com/defagos/radars/tree/master/button-style-tvos-accessibility-issues


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!