Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
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 @@ -93,7 +93,7 @@ constexpr int32_t kRootNodeId = 0;
- (BOOL)nodeWillCauseScroll:(const flutter::SemanticsNode*)node;
- (BOOL)nodeShouldTriggerAnnouncement:(const flutter::SemanticsNode*)node;
- (void)collectRoutes:(NSMutableArray<SemanticsObject*>*)edges;
- (SemanticsObject*)routeFocusObject;
- (NSString*)routeName;
- (BOOL)onCustomAccessibilityAction:(FlutterCustomAccessibilityAction*)action;

@end
Expand Down
15 changes: 7 additions & 8 deletions shell/platform/darwin/ios/framework/Source/SemanticsObject.mm
Original file line number Diff line number Diff line change
Expand Up @@ -282,21 +282,20 @@ - (BOOL)onCustomAccessibilityAction:(FlutterCustomAccessibilityAction*)action {
return YES;
}

- (SemanticsObject*)routeFocusObject {
// Returns the first SemanticObject in this branch that has
// the NamesRoute flag with a non-nil semantic label. Otherwise
// returns nil.
- (NSString*)routeName {
// Returns the first non-null and non-empty semantic label of a child
// with an NamesRoute flag. Otherwise returns nil.
if ([self node].HasFlag(flutter::SemanticsFlags::kNamesRoute)) {
NSString* newName = [self accessibilityLabel];
if (newName != nil && [newName length] > 0) {
return self;
return newName;
}
}
if ([self hasChildren]) {
for (SemanticsObject* child in self.children) {
SemanticsObject* focusObject = [child routeFocusObject];
if (focusObject != nil) {
return focusObject;
NSString* newName = [child routeName];
if (newName != nil && [newName length] > 0) {
return newName;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,9 @@ void PostAccessibilityNotification(UIAccessibilityNotifications notification,
// We should send out only one notification per semantics update.
if (routeChanged) {
if (!ios_delegate_->IsFlutterViewControllerPresentingModalViewController(view_controller_)) {
SemanticsObject* nextToFocus = [lastAdded routeFocusObject];
if (!nextToFocus && root) {
nextToFocus = FindFirstFocusable(root);
}
NSString* routeName = [lastAdded routeName];
ios_delegate_->PostAccessibilityNotification(UIAccessibilityScreenChangedNotification,
nextToFocus);
routeName);
}
} else if (layoutChanged) {
SemanticsObject* nextToFocus = nil;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,7 @@ - (void)testAnnouncesRouteChanges {
bridge->UpdateSemantics(/*nodes=*/nodes, /*actions=*/actions);

XCTAssertEqual([accessibility_notifications count], 1ul);
SemanticsObject* focusObject = accessibility_notifications[0][@"argument"];
XCTAssertEqual([focusObject uid], 3);
XCTAssertEqualObjects([focusObject accessibilityLabel], @"node3");
XCTAssertEqualObjects(accessibility_notifications[0][@"argument"], @"node3");
Copy link
Member Author

Choose a reason for hiding this comment

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

This was just a bad revert I think.

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, this looks good

XCTAssertEqual([accessibility_notifications[0][@"notification"] unsignedIntValue],
UIAccessibilityScreenChangedNotification);
}
Expand Down Expand Up @@ -373,7 +371,8 @@ - (void)testAnnouncesRouteChangesWhenNoNamesRoute {
flutter::SemanticsNode node1;
node1.id = 1;
node1.label = "node1";
node1.flags = static_cast<int32_t>(flutter::SemanticsFlags::kScopesRoute);
node1.flags = static_cast<int32_t>(flutter::SemanticsFlags::kScopesRoute) |
static_cast<int32_t>(flutter::SemanticsFlags::kNamesRoute);
node1.childrenInTraversalOrder = {2, 3};
node1.childrenInHitTestOrder = {2, 3};
nodes[node1.id] = node1;
Expand All @@ -394,9 +393,9 @@ - (void)testAnnouncesRouteChangesWhenNoNamesRoute {

// Notification should focus first focusable node, which is node1.
XCTAssertEqual([accessibility_notifications count], 1ul);
SemanticsObject* focusObject = accessibility_notifications[0][@"argument"];
XCTAssertEqual([focusObject uid], 2);
XCTAssertEqualObjects([focusObject accessibilityLabel], @"node2");
id focusObject = accessibility_notifications[0][@"argument"];
XCTAssertTrue([focusObject isKindOfClass:[NSString class]]);
XCTAssertEqualObjects(focusObject, @"node1");
XCTAssertEqual([accessibility_notifications[0][@"notification"] unsignedIntValue],
UIAccessibilityScreenChangedNotification);
}
Expand Down