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

Commit 48a6fde

Browse files
authored
fix On iOS, dialog titles are announced twice (#19826)
1 parent 8825f91 commit 48a6fde

File tree

4 files changed

+13
-11
lines changed

4 files changed

+13
-11
lines changed

shell/platform/darwin/ios/framework/Source/SemanticsObject.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ constexpr int32_t kRootNodeId = 0;
9393
- (BOOL)nodeWillCauseScroll:(const flutter::SemanticsNode*)node;
9494
- (BOOL)nodeShouldTriggerAnnouncement:(const flutter::SemanticsNode*)node;
9595
- (void)collectRoutes:(NSMutableArray<SemanticsObject*>*)edges;
96-
- (NSString*)routeName;
96+
- (SemanticsObject*)routeFocusObject;
9797
- (BOOL)onCustomAccessibilityAction:(FlutterCustomAccessibilityAction*)action;
9898

9999
@end

shell/platform/darwin/ios/framework/Source/SemanticsObject.mm

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -282,20 +282,21 @@ - (BOOL)onCustomAccessibilityAction:(FlutterCustomAccessibilityAction*)action {
282282
return YES;
283283
}
284284

285-
- (NSString*)routeName {
286-
// Returns the first non-null and non-empty semantic label of a child
287-
// with an NamesRoute flag. Otherwise returns nil.
285+
- (SemanticsObject*)routeFocusObject {
286+
// Returns the first SemanticObject in this branch that has
287+
// the NamesRoute flag with a non-nil semantic label. Otherwise
288+
// returns nil.
288289
if ([self node].HasFlag(flutter::SemanticsFlags::kNamesRoute)) {
289290
NSString* newName = [self accessibilityLabel];
290291
if (newName != nil && [newName length] > 0) {
291-
return newName;
292+
return self;
292293
}
293294
}
294295
if ([self hasChildren]) {
295296
for (SemanticsObject* child in self.children) {
296-
NSString* newName = [child routeName];
297-
if (newName != nil && [newName length] > 0) {
298-
return newName;
297+
SemanticsObject* focusObject = [child routeFocusObject];
298+
if (focusObject != nil) {
299+
return focusObject;
299300
}
300301
}
301302
}

shell/platform/darwin/ios/framework/Source/accessibility_bridge.mm

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,8 @@ void PostAccessibilityNotification(UIAccessibilityNotifications notification,
199199
layoutChanged = layoutChanged || [doomed_uids count] > 0;
200200
if (routeChanged) {
201201
if (!ios_delegate_->IsFlutterViewControllerPresentingModalViewController(view_)) {
202-
NSString* routeName = [lastAdded routeName];
203202
ios_delegate_->PostAccessibilityNotification(UIAccessibilityScreenChangedNotification,
204-
routeName);
203+
[lastAdded routeFocusObject]);
205204
}
206205
} else if (layoutChanged) {
207206
// TODO(goderbauer): figure out which node to focus next.

shell/platform/darwin/ios/framework/Source/accessibility_bridge_test.mm

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,9 @@ - (void)testAnnouncesRouteChanges {
311311
bridge->UpdateSemantics(/*nodes=*/nodes, /*actions=*/actions);
312312

313313
XCTAssertEqual([accessibility_notifications count], 1ul);
314-
XCTAssertEqualObjects(accessibility_notifications[0][@"argument"], @"route");
314+
SemanticsObject* focusObject = accessibility_notifications[0][@"argument"];
315+
XCTAssertEqual([focusObject uid], 1);
316+
XCTAssertEqualObjects([focusObject accessibilityLabel], @"route");
315317
XCTAssertEqual([accessibility_notifications[0][@"notification"] unsignedIntValue],
316318
UIAccessibilityScreenChangedNotification);
317319
}

0 commit comments

Comments
 (0)