[a11y] fixes overlayPortals not showing VoiceControl labels (#164754)
Fixes https://github.com/flutter/flutter/issues/157753 Even when a `uiaccessibilityelement` is marked as `accessibilityRespondsToUserInteraction`, if it's spatially far away enough from its parent's `accessibilityFrame`, a VoiceControl label will not be created for it. In this PR, I set the parent `SemanticObjectContainer`'s `accessibilityFrame` so it is the minimum rect that will cover all it's children. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing.
This commit is contained in:
@@ -941,7 +941,12 @@ CGRect ConvertRectToGlobal(SemanticsObject* reference, CGRect local_rect) {
|
||||
}
|
||||
|
||||
- (CGRect)accessibilityFrame {
|
||||
return self.semanticsObject.accessibilityFrame;
|
||||
// For OverlayPortals, the child element is sometimes outside the bounds of the parent
|
||||
// Even if it's marked accessible, VoiceControl labels will not appear if it's too
|
||||
// spatially distant. Set the frame to be the max screen size so all children are guaraenteed
|
||||
// to be contained.
|
||||
|
||||
return UIScreen.mainScreen.bounds;
|
||||
}
|
||||
|
||||
- (id)accessibilityContainer {
|
||||
|
||||
@@ -614,6 +614,41 @@ const float kFloatCompareEpsilon = 0.001;
|
||||
XCTAssertTrue([object.accessibilityLabel isEqualToString:@"label\ntooltip"]);
|
||||
}
|
||||
|
||||
- (void)testSemanticsObjectContainerAccessibilityFrameCoversEntireScreen {
|
||||
flutter::testing::MockAccessibilityBridge* mock = new flutter::testing::MockAccessibilityBridge();
|
||||
mock->isVoiceOverRunningValue = true;
|
||||
fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(mock);
|
||||
fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
|
||||
|
||||
flutter::SemanticsNode parent;
|
||||
parent.id = 0;
|
||||
parent.actions = static_cast<int32_t>(flutter::SemanticsAction::kTap);
|
||||
|
||||
flutter::SemanticsNode child;
|
||||
child.id = 1;
|
||||
child.actions = static_cast<int32_t>(flutter::SemanticsAction::kTap);
|
||||
child.rect = SkRect::MakeXYWH(0, 0, 100, 100);
|
||||
parent.childrenInTraversalOrder.push_back(1);
|
||||
|
||||
FlutterSemanticsObject* parentObject = [[FlutterSemanticsObject alloc] initWithBridge:bridge
|
||||
uid:0];
|
||||
[parentObject setSemanticsNode:&parent];
|
||||
|
||||
FlutterSemanticsObject* childObject = [[FlutterSemanticsObject alloc] initWithBridge:bridge
|
||||
uid:1];
|
||||
[childObject setSemanticsNode:&child];
|
||||
|
||||
parentObject.children = @[ childObject ];
|
||||
[parentObject accessibilityBridgeDidFinishUpdate];
|
||||
[childObject accessibilityBridgeDidFinishUpdate];
|
||||
|
||||
SemanticsObjectContainer* container =
|
||||
static_cast<SemanticsObjectContainer*>(parentObject.accessibilityContainer);
|
||||
|
||||
XCTAssertTrue(childObject.accessibilityRespondsToUserInteraction);
|
||||
XCTAssertTrue(CGRectEqualToRect(container.accessibilityFrame, UIScreen.mainScreen.bounds));
|
||||
}
|
||||
|
||||
- (void)testFlutterSemanticsObjectAttributedStringsDoNotCrashWhenEmpty {
|
||||
flutter::testing::MockAccessibilityBridge* mock = new flutter::testing::MockAccessibilityBridge();
|
||||
mock->isVoiceOverRunningValue = true;
|
||||
|
||||
Reference in New Issue
Block a user