Skip to content

Commit e8bef98

Browse files
authored
Adds a11y section locale support for iOS (#175005)
<!-- Thanks for filing a pull request! Reviewers are typically assigned within a week of filing a request. To learn more about code review, see our documentation on Tree Hygiene: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md --> part of flutter/flutter#99600 ## Pre-launch Checklist - [ ] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [ ] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [ ] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [ ] I signed the [CLA]. - [ ] I listed at least one issue that this PR fixes in the description above. - [ ] I updated/added relevant documentation (doc comments with `///`). - [ ] I added new tests to check the change I am making, or this PR is [test-exempt]. - [ ] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [ ] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
1 parent 2cda3fb commit e8bef98

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

engine/src/flutter/shell/platform/darwin/ios/framework/Source/SemanticsObject.mm

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,17 @@ - (BOOL)isAccessibilityElement {
454454
return [self isFocusable];
455455
}
456456

457+
- (NSString*)accessibilityLanguage {
458+
if (![self isAccessibilityBridgeAlive]) {
459+
return nil;
460+
}
461+
462+
if (self.node.locale.empty()) {
463+
return nil;
464+
}
465+
return @(self.node.locale.data());
466+
}
467+
457468
- (bool)isFocusable {
458469
// If the node is scrollable AND hidden OR
459470
// The node has a label, value, or hint OR

engine/src/flutter/shell/platform/darwin/ios/framework/Source/SemanticsObjectTest.mm

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,33 @@ - (void)testFlutterSemanticsObjectHasIdentifier {
571571
XCTAssertTrue([object.accessibilityIdentifier isEqualToString:@"identifier"]);
572572
}
573573

574+
- (void)testFlutterSemanticsObjectHasLocale {
575+
flutter::testing::MockAccessibilityBridge* mock = new flutter::testing::MockAccessibilityBridge();
576+
mock->isVoiceOverRunningValue = true;
577+
fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(mock);
578+
fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
579+
580+
flutter::SemanticsNode node;
581+
node.locale = "es-MX";
582+
583+
FlutterSemanticsObject* object = [[FlutterSemanticsObject alloc] initWithBridge:bridge uid:0];
584+
[object setSemanticsNode:&node];
585+
XCTAssertTrue([object.accessibilityLanguage isEqualToString:@"es-MX"]);
586+
}
587+
588+
- (void)testFlutterSemanticsObjectLocaleNil {
589+
flutter::testing::MockAccessibilityBridge* mock = new flutter::testing::MockAccessibilityBridge();
590+
mock->isVoiceOverRunningValue = true;
591+
fml::WeakPtrFactory<flutter::AccessibilityBridgeIos> factory(mock);
592+
fml::WeakPtr<flutter::AccessibilityBridgeIos> bridge = factory.GetWeakPtr();
593+
594+
flutter::SemanticsNode node;
595+
596+
FlutterSemanticsObject* object = [[FlutterSemanticsObject alloc] initWithBridge:bridge uid:0];
597+
[object setSemanticsNode:&node];
598+
XCTAssertTrue(object.accessibilityLanguage == nil);
599+
}
600+
574601
- (void)testFlutterScrollableSemanticsObjectWithLabelValueHintIsNotHiddenWhenVoiceOverIsRunning {
575602
flutter::testing::MockAccessibilityBridge* mock = new flutter::testing::MockAccessibilityBridge();
576603
mock->isVoiceOverRunningValue = true;

0 commit comments

Comments
 (0)