From 117f6e94ebf3e7152c1c5fe16d7fc933206ff299 Mon Sep 17 00:00:00 2001 From: Dan Field Date: Tue, 8 Oct 2019 16:37:09 -0700 Subject: [PATCH] Fix for a11y crash on iOS (flutter/engine#12990) --- .../framework/Source/accessibility_bridge.h | 4 ++-- .../framework/Source/accessibility_bridge.mm | 20 +++++++++++++++---- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/accessibility_bridge.h b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/accessibility_bridge.h index f563b73ce2..aaba31842c 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/accessibility_bridge.h +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/accessibility_bridge.h @@ -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. @@ -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. diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/accessibility_bridge.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/accessibility_bridge.mm index 938cec276a..36f320d938 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/accessibility_bridge.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/accessibility_bridge.mm @@ -81,7 +81,7 @@ flutter::SemanticsAction GetSemanticsActionForScrollDirection( * 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)bridge @@ -109,7 +109,11 @@ flutter::SemanticsAction GetSemanticsActionForScrollDirection( - (instancetype)initWithBridge:(fml::WeakPtr)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()]; if (self) { _bridge = bridge; @@ -429,7 +433,11 @@ flutter::SemanticsAction GetSemanticsActionForScrollDirection( - (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(); @@ -476,7 +484,11 @@ flutter::SemanticsAction GetSemanticsActionForScrollDirection( - (instancetype)initWithSemanticsObject:(SemanticsObject*)semanticsObject bridge:(fml::WeakPtr)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;