Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Fix for a11y crash on iOS #12990

Merged
merged 5 commits into from
Oct 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class AccessibilityBridge;
/**
* A node in the iOS semantics tree.
*/
@interface SemanticsObject : NSObject
@interface SemanticsObject : UIAccessibilityElement

/**
* The globally unique identifier for this node.
Expand Down Expand Up @@ -126,7 +126,7 @@ class AccessibilityBridge;
* * `SemanticsObject` for the other type of semantics objects.
* * `FlutterSemanticsObject` for default implementation of `SemanticsObject`.
*/
@interface FlutterPlatformViewSemanticsContainer : NSObject
@interface FlutterPlatformViewSemanticsContainer : UIAccessibilityElement

/**
* The position inside an accessibility container.
Expand Down
20 changes: 16 additions & 4 deletions shell/platform/darwin/ios/framework/Source/accessibility_bridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ @implementation FlutterCustomAccessibilityAction {
* there for structure and they don't provide any semantic information to VoiceOver (they return
* NO for isAccessibilityElement).
*/
@interface SemanticsObjectContainer : NSObject
@interface SemanticsObjectContainer : UIAccessibilityElement
- (instancetype)init __attribute__((unavailable("Use initWithSemanticsObject instead")));
- (instancetype)initWithSemanticsObject:(SemanticsObject*)semanticsObject
bridge:(fml::WeakPtr<flutter::AccessibilityBridge>)bridge
Expand Down Expand Up @@ -109,7 +109,11 @@ - (instancetype)init {
- (instancetype)initWithBridge:(fml::WeakPtr<flutter::AccessibilityBridge>)bridge uid:(int32_t)uid {
FML_DCHECK(bridge) << "bridge must be set";
FML_DCHECK(uid >= kRootNodeId);
self = [super init];
// Initialize with the UIView as the container.
// The UIView will not necessarily be accessibility parent for this object.
// The bridge informs the OS of the actual structure via
// `accessibilityContainer` and `accessibilityElementAtIndex`.
self = [super initWithAccessibilityContainer:bridge->view()];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and everywhere else this is called: I believe not all SemanticsObjects have the view as an accessibility container. There are some intermediate a11y containers that we create. Shouldn't the SemanticsObjects be attached to their container, not the root?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is we don't know the containers at this point - but it seems to work because we later assign it to the right container when we actually create the container.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should probably at least be a comment here then. And I am wondering how we can assure that it is going to be assigned the right container....


if (self) {
_bridge = bridge;
Expand Down Expand Up @@ -429,7 +433,11 @@ - (instancetype)init {

- (instancetype)initWithSemanticsObject:(SemanticsObject*)object {
FML_CHECK(object);
if (self = [super init]) {
// Initialize with the UIView as the container.
// The UIView will not necessarily be accessibility parent for this object.
// The bridge informs the OS of the actual structure via
// `accessibilityContainer` and `accessibilityElementAtIndex`.
if (self = [super initWithAccessibilityContainer:object.bridge->view()]) {
_semanticsObject = object;
flutter::FlutterPlatformViewsController* controller =
object.bridge->GetPlatformViewsController();
Expand Down Expand Up @@ -476,7 +484,11 @@ - (instancetype)init {
- (instancetype)initWithSemanticsObject:(SemanticsObject*)semanticsObject
bridge:(fml::WeakPtr<flutter::AccessibilityBridge>)bridge {
FML_DCHECK(semanticsObject) << "semanticsObject must be set";
self = [super init];
// Initialize with the UIView as the container.
// The UIView will not necessarily be accessibility parent for this object.
// The bridge informs the OS of the actual structure via
// `accessibilityContainer` and `accessibilityElementAtIndex`.
self = [super initWithAccessibilityContainer:bridge->view()];

if (self) {
_semanticsObject = semanticsObject;
Expand Down